lua_unlock(L);
return res;
}
-@@ -1040,20 +1046,22 @@ LUA_API int lua_next (lua_State *L, int
+@@ -1040,8 +1046,9 @@ LUA_API int lua_next (lua_State *L, int
if (more) {
api_incr_top(L);
}
lua_unlock(L);
return more;
}
-
-
- LUA_API void lua_concat (lua_State *L, int n) {
-+ int i;
- lua_lock(L);
- api_checknelems(L, n);
+@@ -1053,7 +1060,7 @@ LUA_API void lua_concat (lua_State *L, i
if (n >= 2) {
luaC_checkGC(L);
luaV_concat(L, n, cast_int(L->top - L->base) - 1);
}
else if (n == 0) { /* push empty string */
setsvalue2s(L, L->top, luaS_newlstr(L, "", 0));
-@@ -1139,6 +1147,7 @@ LUA_API const char *lua_setupvalue (lua_
+@@ -1139,6 +1146,7 @@ LUA_API const char *lua_setupvalue (lua_
if (name) {
L->top--;
setobj(L, val, L->top);
luaC_barrier(L, clvalue(fi), L->top);
}
lua_unlock(L);
-@@ -1160,7 +1169,7 @@ LUA_API const char *lua_setupvalue (lua_
+@@ -1160,7 +1168,7 @@ LUA_API const char *lua_setupvalue (lua_
int lua_pushvalue_as_number (lua_State *L, int idx)
{
const TValue *o = index2adr(L, idx);
}
}
return p;
-@@ -452,22 +455,27 @@ static void GCTM (lua_State *L) {
- g->tmudata = NULL;
- else
- g->tmudata->gch.next = udata->uv.next;
-+ udata->uv.prev = (GCObject *)g->mainthread;
- udata->uv.next = g->mainthread->next; /* return it to `root' list */
- g->mainthread->next = o;
-+ if (udata->uv.next)
-+ udata->uv.next->uv.prev = o;
- makewhite(g, o);
-+ L->top++;
- tm = fasttm(L, udata->uv.metatable, TM_GC);
- if (tm != NULL) {
- lu_byte oldah = L->allowhook;
- lu_mem oldt = g->GCthreshold;
- L->allowhook = 0; /* stop debug hooks during GC tag method */
- g->GCthreshold = 2*g->totalbytes; /* avoid GC steps */
-- setobj2s(L, L->top, tm);
-- setuvalue(L, L->top+1, udata);
- L->top += 2;
-+ setobj2s(L, L->top - 2, tm);
-+ setuvalue(L, L->top - 1, udata);
- luaD_call(L, L->top - 2, 0);
- L->allowhook = oldah; /* restore hooks */
- g->GCthreshold = oldt; /* restore threshold */
- }
-+ L->top--;
- }
-
-
-@@ -543,7 +551,7 @@ static void atomic (lua_State *L) {
+@@ -543,7 +546,7 @@ static void atomic (lua_State *L) {
udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */
marktmu(g); /* mark `preserved' userdata */
udsize += propagateall(g); /* remark, to propagate `preserveness' */
/* flip current white */
g->currentwhite = cast_byte(otherwhite(g));
g->sweepstrgc = 0;
-@@ -685,8 +693,11 @@ void luaC_barrierback (lua_State *L, Tab
+@@ -685,8 +688,11 @@ void luaC_barrierback (lua_State *L, Tab
void luaC_link (lua_State *L, GCObject *o, lu_byte tt) {
global_State *g = G(L);
lua_Number d;
lua_Integer i;
-@@ -104,6 +105,7 @@ static void callTMres (lua_State *L, Stk
- res = restorestack(L, result);
- L->top--;
- setobjs2s(L, res, L->top);
-+ setnilvalue(L, L->top);
- }
-
-
-@@ -384,6 +386,7 @@ void luaV_concat (lua_State *L, int tota
+@@ -384,6 +385,7 @@ void luaV_concat (lua_State *L, int tota
size_t l = tsvalue(top-i)->len;
memcpy(buffer+tl, svalue(top-i), l);
tl += l;
}
setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
}
-@@ -420,7 +423,7 @@ void luaV_concat (lua_State *L, int tota
+@@ -420,7 +422,7 @@ void luaV_concat (lua_State *L, int tota
*/
static void Arith (lua_State *L, StkId ra, const TValue *rb,
const TValue *rc, TMS op) {
const TValue *b, *c;
lua_Number nb,nc;
-@@ -663,7 +666,7 @@ void luaV_execute (lua_State *L, int nex
+@@ -663,7 +665,7 @@ void luaV_execute (lua_State *L, int nex
OPCODE_TARGET(LOADNIL) {
TValue *rb = RB(i);
do {
} while (rb >= ra);
continue;
}
-@@ -673,7 +676,7 @@ void luaV_execute (lua_State *L, int nex
+@@ -673,7 +675,7 @@ void luaV_execute (lua_State *L, int nex
continue;
}
OPCODE_TARGET(GETGLOBAL) {
TValue *rb = KBx(i);
sethvalue(L, &g, cl->env);
lua_assert(ttisstring(rb));
-@@ -685,7 +688,7 @@ void luaV_execute (lua_State *L, int nex
+@@ -685,7 +687,7 @@ void luaV_execute (lua_State *L, int nex
continue;
}
OPCODE_TARGET(SETGLOBAL) {
sethvalue(L, &g, cl->env);
lua_assert(ttisstring(KBx(i)));
Protect(luaV_settable(L, &g, KBx(i), ra));
-@@ -693,7 +696,7 @@ void luaV_execute (lua_State *L, int nex
- }
- OPCODE_TARGET(SETUPVAL) {
- UpVal *uv = cl->upvals[GETARG_B(i)];
-- setobj(L, uv->v, ra);
-+ setobj(L, uv->v, luaV_ref(ra));
- luaC_barrier(L, uv, ra);
- continue;
- }
-@@ -856,7 +859,8 @@ void luaV_execute (lua_State *L, int nex
- }
- OPCODE_TARGET(TAILCALL) {
- int b = GETARG_B(i);
-- if (b != 0) L->top = ra+b; /* else previous instruction set top */
-+ if (b != 0)
-+ L->top = ra+b; /* else previous instruction set top */
- L->savedpc = pc;
- lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
- switch (luaD_precall(L, ra, LUA_MULTRET)) {
-@@ -870,7 +874,8 @@ void luaV_execute (lua_State *L, int nex
- L->base = ci->base = ci->func + ((ci+1)->base - pfunc);
- for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */
- setobjs2s(L, func+aux, pfunc+aux);
-- ci->top = L->top = func+aux; /* correct top */
-+ ci->top = func+aux; /* correct top */
-+ L->top = ci->top;
- lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize);
- ci->savedpc = L->savedpc;
- ci->tailcalls++; /* one more call lost */
-@@ -895,7 +900,7 @@ void luaV_execute (lua_State *L, int nex
+@@ -895,7 +897,7 @@ void luaV_execute (lua_State *L, int nex
if (--nexeccalls == 0) /* was previous function running `here'? */
return; /* no: return */
else { /* yes: continue its execution */
lua_assert(isLua(L->ci));
lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL);
goto reentry;
-@@ -986,6 +991,7 @@ void luaV_execute (lua_State *L, int nex
+@@ -986,6 +988,7 @@ void luaV_execute (lua_State *L, int nex
for (; n > 0; n--) {
TValue *val = ra+n;
setobj2t(L, luaH_setint(L, h, last--), val);
-+ setnilvalue(L, val);
++ setnilvalue(L, val);
luaC_barriert(L, h, val);
}
continue;
-@@ -1030,7 +1036,7 @@ void luaV_execute (lua_State *L, int nex
+@@ -1030,7 +1033,7 @@ void luaV_execute (lua_State *L, int nex
setobjs2s(L, ra + j, ci->base - n + j);
}
else {
+#define setlvmtop(L, val) do { \
+ int __i; \
+ for (__i = L->top - val; __i-- > 0;) \
-+ setnilvalue(L, L->top + __i); \
++ setnilvalue(L, val + __i); \
+ L->top = val; \
+} while (0)
+