Merge branch 'master' into nextversion
This commit is contained in:
@@ -1043,9 +1043,14 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Standard panic funcion just prints an error message. The test
|
||||||
|
** with 'lua_type' avoids possible memory errors in 'lua_tostring'.
|
||||||
|
*/
|
||||||
static int panic (lua_State *L) {
|
static int panic (lua_State *L) {
|
||||||
const char *msg = lua_tostring(L, -1);
|
const char *msg = (lua_type(L, -1) == LUA_TSTRING)
|
||||||
if (msg == NULL) msg = "error object is not a string";
|
? lua_tostring(L, -1)
|
||||||
|
: "error object is not a string";
|
||||||
lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
|
lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
|
||||||
msg);
|
msg);
|
||||||
return 0; /* return to Lua to abort */
|
return 0; /* return to Lua to abort */
|
||||||
|
|||||||
5
ldebug.c
5
ldebug.c
@@ -927,12 +927,12 @@ int luaG_traceexec (lua_State *L, const Instruction *pc) {
|
|||||||
}
|
}
|
||||||
pc++; /* reference is always next instruction */
|
pc++; /* reference is always next instruction */
|
||||||
ci->u.l.savedpc = pc; /* save 'pc' */
|
ci->u.l.savedpc = pc; /* save 'pc' */
|
||||||
counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));
|
counthook = (mask & LUA_MASKCOUNT) && (--L->hookcount == 0);
|
||||||
if (counthook)
|
if (counthook)
|
||||||
resethookcount(L); /* reset count */
|
resethookcount(L); /* reset count */
|
||||||
else if (!(mask & LUA_MASKLINE))
|
else if (!(mask & LUA_MASKLINE))
|
||||||
return 1; /* no line hook and count != 0; nothing to be done now */
|
return 1; /* no line hook and count != 0; nothing to be done now */
|
||||||
if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */
|
if (ci->callstatus & CIST_HOOKYIELD) { /* hook yielded last time? */
|
||||||
ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
|
ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
|
||||||
return 1; /* do not call hook again (VM yielded, so it did not move) */
|
return 1; /* do not call hook again (VM yielded, so it did not move) */
|
||||||
}
|
}
|
||||||
@@ -954,7 +954,6 @@ int luaG_traceexec (lua_State *L, const Instruction *pc) {
|
|||||||
if (L->status == LUA_YIELD) { /* did hook yield? */
|
if (L->status == LUA_YIELD) { /* did hook yield? */
|
||||||
if (counthook)
|
if (counthook)
|
||||||
L->hookcount = 1; /* undo decrement to zero */
|
L->hookcount = 1; /* undo decrement to zero */
|
||||||
ci->u.l.savedpc--; /* undo increment (resume will increment it again) */
|
|
||||||
ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
|
ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
|
||||||
luaD_throw(L, LUA_YIELD);
|
luaD_throw(L, LUA_YIELD);
|
||||||
}
|
}
|
||||||
|
|||||||
4
ldo.c
4
ldo.c
@@ -792,6 +792,10 @@ static void resume (lua_State *L, void *ud) {
|
|||||||
lua_assert(L->status == LUA_YIELD);
|
lua_assert(L->status == LUA_YIELD);
|
||||||
L->status = LUA_OK; /* mark that it is running (again) */
|
L->status = LUA_OK; /* mark that it is running (again) */
|
||||||
if (isLua(ci)) { /* yielded inside a hook? */
|
if (isLua(ci)) { /* yielded inside a hook? */
|
||||||
|
/* undo increment made by 'luaG_traceexec': instruction was not
|
||||||
|
executed yet */
|
||||||
|
lua_assert(ci->callstatus & CIST_HOOKYIELD);
|
||||||
|
ci->u.l.savedpc--;
|
||||||
L->top.p = firstArg; /* discard arguments */
|
L->top.p = firstArg; /* discard arguments */
|
||||||
luaV_execute(L, ci); /* just continue running Lua code */
|
luaV_execute(L, ci); /* just continue running Lua code */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
|
|||||||
return internshrstr(L, str, l);
|
return internshrstr(L, str, l);
|
||||||
else {
|
else {
|
||||||
TString *ts;
|
TString *ts;
|
||||||
if (l_unlikely(l >= (MAX_SIZE - sizeof(TString))/sizeof(char)))
|
if (l_unlikely(l * sizeof(char) >= (MAX_SIZE - sizeof(TString))))
|
||||||
luaM_toobig(L);
|
luaM_toobig(L);
|
||||||
ts = luaS_createlngstrobj(L, l);
|
ts = luaS_createlngstrobj(L, l);
|
||||||
memcpy(getlngstr(ts), str, l * sizeof(char));
|
memcpy(getlngstr(ts), str, l * sizeof(char));
|
||||||
|
|||||||
5
ltests.c
5
ltests.c
@@ -73,8 +73,9 @@ static void badexit (const char *fmt, const char *s1, const char *s2) {
|
|||||||
|
|
||||||
|
|
||||||
static int tpanic (lua_State *L) {
|
static int tpanic (lua_State *L) {
|
||||||
const char *msg = lua_tostring(L, -1);
|
const char *msg = (lua_type(L, -1) == LUA_TSTRING)
|
||||||
if (msg == NULL) msg = "error object is not a string";
|
? lua_tostring(L, -1)
|
||||||
|
: "error object is not a string";
|
||||||
return (badexit("PANIC: unprotected error in call to Lua API (%s)\n",
|
return (badexit("PANIC: unprotected error in call to Lua API (%s)\n",
|
||||||
msg, NULL),
|
msg, NULL),
|
||||||
0); /* do not return to Lua */
|
0); /* do not return to Lua */
|
||||||
|
|||||||
2
lvm.c
2
lvm.c
@@ -655,7 +655,7 @@ void luaV_concat (lua_State *L, int total) {
|
|||||||
/* collect total length and number of strings */
|
/* collect total length and number of strings */
|
||||||
for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) {
|
for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) {
|
||||||
size_t l = tsslen(tsvalue(s2v(top - n - 1)));
|
size_t l = tsslen(tsvalue(s2v(top - n - 1)));
|
||||||
if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) {
|
if (l_unlikely(l >= MAX_SIZE - sizeof(TString) - tl)) {
|
||||||
L->top.p = top - total; /* pop strings to avoid wasting stack */
|
L->top.p = top - total; /* pop strings to avoid wasting stack */
|
||||||
luaG_runerror(L, "string length overflow");
|
luaG_runerror(L, "string length overflow");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4552,6 +4552,10 @@ The pointer returned by @id{lua_tolstring}
|
|||||||
may be invalidated by the garbage collector if the
|
may be invalidated by the garbage collector if the
|
||||||
corresponding Lua value is removed from the stack @see{constchar}.
|
corresponding Lua value is removed from the stack @see{constchar}.
|
||||||
|
|
||||||
|
This function can raise memory errors only
|
||||||
|
when converting a number to a string
|
||||||
|
(as then it may have to create a new string).
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@APIEntry{lua_Number lua_tonumber (lua_State *L, int index);|
|
@APIEntry{lua_Number lua_tonumber (lua_State *L, int index);|
|
||||||
|
|||||||
@@ -610,18 +610,20 @@ else
|
|||||||
-- (bug in 5.2/5.3)
|
-- (bug in 5.2/5.3)
|
||||||
c = coroutine.create(function (a, ...)
|
c = coroutine.create(function (a, ...)
|
||||||
T.sethook("yield 0", "l") -- will yield on next two lines
|
T.sethook("yield 0", "l") -- will yield on next two lines
|
||||||
assert(a == 10)
|
local b = a
|
||||||
return ...
|
return ...
|
||||||
end)
|
end)
|
||||||
|
|
||||||
assert(coroutine.resume(c, 1, 2, 3)) -- start coroutine
|
assert(coroutine.resume(c, 1, 2, 3)) -- start coroutine
|
||||||
local n,v = debug.getlocal(c, 0, 1) -- check its local
|
local n,v = debug.getlocal(c, 0, 1) -- check its local
|
||||||
assert(n == "a" and v == 1)
|
assert(n == "a" and v == 1 and debug.getlocal(c, 0, 2) ~= "b")
|
||||||
assert(debug.setlocal(c, 0, 1, 10)) -- test 'setlocal'
|
assert(debug.setlocal(c, 0, 1, 10)) -- test 'setlocal'
|
||||||
local t = debug.getinfo(c, 0) -- test 'getinfo'
|
local t = debug.getinfo(c, 0) -- test 'getinfo'
|
||||||
assert(t.currentline == t.linedefined + 1)
|
assert(t.currentline == t.linedefined + 2)
|
||||||
assert(not debug.getinfo(c, 1)) -- no other level
|
assert(not debug.getinfo(c, 1)) -- no other level
|
||||||
assert(coroutine.resume(c)) -- run next line
|
assert(coroutine.resume(c)) -- run next line
|
||||||
|
local n,v = debug.getlocal(c, 0, 2) -- check next local
|
||||||
|
assert(n == "b" and v == 10)
|
||||||
v = {coroutine.resume(c)} -- finish coroutine
|
v = {coroutine.resume(c)} -- finish coroutine
|
||||||
assert(v[1] == true and v[2] == 2 and v[3] == 3 and v[4] == undef)
|
assert(v[1] == true and v[2] == 2 and v[3] == 3 and v[4] == undef)
|
||||||
assert(not coroutine.resume(c))
|
assert(not coroutine.resume(c))
|
||||||
|
|||||||
Reference in New Issue
Block a user