mirror of
https://github.com/lua/lua
synced 2025-04-09 14:32:55 +03:00
small bugs when stack is reallocated
This commit is contained in:
parent
260e35f576
commit
b6e2f1a86e
12
lapi.c
12
lapi.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lapi.c,v 1.208 2002/08/06 17:06:56 roberto Exp roberto $
|
** $Id: lapi.c,v 1.209 2002/08/06 18:54:18 roberto Exp roberto $
|
||||||
** Lua API
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -747,15 +747,15 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
|
|||||||
|
|
||||||
|
|
||||||
LUA_API int lua_pushupvalues (lua_State *L) {
|
LUA_API int lua_pushupvalues (lua_State *L) {
|
||||||
TObject *func;
|
Closure *func;
|
||||||
int n, i;
|
int n, i;
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
func = (L->ci->base - 1);
|
api_check(L, iscfunction(L->ci->base - 1));
|
||||||
api_check(L, iscfunction(func));
|
func = clvalue(L->ci->base - 1);
|
||||||
n = clvalue(func)->c.nupvalues;
|
n = func->c.nupvalues;
|
||||||
luaD_checkstack(L, n + LUA_MINSTACK);
|
luaD_checkstack(L, n + LUA_MINSTACK);
|
||||||
for (i=0; i<n; i++) {
|
for (i=0; i<n; i++) {
|
||||||
setobj(L->top, &clvalue(func)->c.upvalue[i]);
|
setobj(L->top, &func->c.upvalue[i]);
|
||||||
L->top++;
|
L->top++;
|
||||||
}
|
}
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
|
20
lvm.c
20
lvm.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lvm.c,v 1.248 2002/07/17 16:25:13 roberto Exp $
|
** $Id: lvm.c,v 1.249 2002/08/05 17:36:24 roberto Exp roberto $
|
||||||
** Lua virtual machine
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -385,10 +385,12 @@ StkId luaV_execute (lua_State *L) {
|
|||||||
/* main loop of interpreter */
|
/* main loop of interpreter */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const Instruction i = *pc++;
|
const Instruction i = *pc++;
|
||||||
const StkId ra = RA(i);
|
StkId ra;
|
||||||
if (L->hookmask >= LUA_MASKLINE &&
|
if (L->hookmask >= LUA_MASKLINE &&
|
||||||
(--L->hookcount == 0 || L->hookmask & LUA_MASKLINE))
|
(--L->hookcount == 0 || L->hookmask & LUA_MASKLINE))
|
||||||
traceexec(L);
|
traceexec(L);
|
||||||
|
/* warning!! several calls may realloc the stack and invalidate `ra' */
|
||||||
|
ra = RA(i);
|
||||||
lua_assert(L->top <= L->stack + L->stacksize && L->top >= L->ci->base);
|
lua_assert(L->top <= L->stack + L->stacksize && L->top >= L->ci->base);
|
||||||
lua_assert(L->top == L->ci->top ||
|
lua_assert(L->top == L->ci->top ||
|
||||||
GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL ||
|
GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL ||
|
||||||
@ -544,7 +546,7 @@ StkId luaV_execute (lua_State *L) {
|
|||||||
int b = GETARG_B(i);
|
int b = GETARG_B(i);
|
||||||
int c = GETARG_C(i);
|
int c = GETARG_C(i);
|
||||||
luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */
|
luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */
|
||||||
setobj(base+GETARG_A(i), base+b);
|
setobj(RA(i), base+b);
|
||||||
luaV_checkGC(L, base+c+1);
|
luaV_checkGC(L, base+c+1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -634,13 +636,13 @@ StkId luaV_execute (lua_State *L) {
|
|||||||
return ra; /* no: return */
|
return ra; /* no: return */
|
||||||
else { /* yes: continue its execution (go through) */
|
else { /* yes: continue its execution (go through) */
|
||||||
int nresults;
|
int nresults;
|
||||||
lua_assert(ttisfunction(ci->base-1));
|
lua_assert(ttisfunction(ci->base - 1));
|
||||||
ci->pc = &pc; /* function is active again */
|
lua_assert(GET_OPCODE(*(ci->u.l.savedpc - 1)) == OP_CALL);
|
||||||
pc = ci->u.l.savedpc;
|
nresults = GETARG_C(*(ci->u.l.savedpc - 1)) - 1;
|
||||||
lua_assert(GET_OPCODE(*(pc-1)) == OP_CALL);
|
|
||||||
nresults = GETARG_C(*(pc-1)) - 1;
|
|
||||||
luaD_poscall(L, nresults, ra);
|
luaD_poscall(L, nresults, ra);
|
||||||
if (nresults >= 0) L->top = L->ci->top;
|
if (nresults >= 0) L->top = L->ci->top;
|
||||||
|
L->ci->pc = &pc; /* function is active again */
|
||||||
|
pc = L->ci->u.l.savedpc;
|
||||||
goto retentry;
|
goto retentry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -670,7 +672,7 @@ StkId luaV_execute (lua_State *L) {
|
|||||||
L->top = ra+5;
|
L->top = ra+5;
|
||||||
luaD_call(L, ra+2, GETARG_C(i) + 1);
|
luaD_call(L, ra+2, GETARG_C(i) + 1);
|
||||||
L->top = L->ci->top;
|
L->top = L->ci->top;
|
||||||
if (ttisnil(ra+2)) pc++; /* skip jump (break loop) */
|
if (ttisnil(RA(i)+2)) pc++; /* skip jump (break loop) */
|
||||||
else dojump(pc, GETARG_sBx(*pc) + 1); /* else jump back */
|
else dojump(pc, GETARG_sBx(*pc) + 1); /* else jump back */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user