diff options
Diffstat (limited to 'apps/plugins/lua/ldo.c')
-rw-r--r-- | apps/plugins/lua/ldo.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/apps/plugins/lua/ldo.c b/apps/plugins/lua/ldo.c index 43266de95e..7eccc54480 100644 --- a/apps/plugins/lua/ldo.c +++ b/apps/plugins/lua/ldo.c | |||
@@ -51,11 +51,13 @@ struct lua_longjmp { | |||
51 | void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { | 51 | void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { |
52 | switch (errcode) { | 52 | switch (errcode) { |
53 | case LUA_ERRMEM: { | 53 | case LUA_ERRMEM: { |
54 | setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG)); | 54 | ptrdiff_t oldtopr = savestack(L, oldtop); |
55 | setsvalue2s(L, restorestack(L, oldtopr), luaS_newliteral(L, MEMERRMSG)); | ||
55 | break; | 56 | break; |
56 | } | 57 | } |
57 | case LUA_ERRERR: { | 58 | case LUA_ERRERR: { |
58 | setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); | 59 | ptrdiff_t oldtopr = savestack(L, oldtop); |
60 | setsvalue2s(L, restorestack(L, oldtopr), luaS_newliteral(L, "error in error handling")); | ||
59 | break; | 61 | break; |
60 | } | 62 | } |
61 | case LUA_ERRSYNTAX: | 63 | case LUA_ERRSYNTAX: |
@@ -92,6 +94,8 @@ static void resetstack (lua_State *L, int status) { | |||
92 | 94 | ||
93 | 95 | ||
94 | void luaD_throw (lua_State *L, int errcode) { | 96 | void luaD_throw (lua_State *L, int errcode) { |
97 | unfixedstack(L); /* make sure the fixedstack & block_gc flags get reset. */ | ||
98 | unset_block_gc(L); | ||
95 | if (L->errorJmp) { | 99 | if (L->errorJmp) { |
96 | L->errorJmp->status = errcode; | 100 | L->errorJmp->status = errcode; |
97 | LUAI_THROW(L, L->errorJmp); | 101 | LUAI_THROW(L, L->errorJmp); |
@@ -208,7 +212,9 @@ void luaD_callhook (lua_State *L, int event, int line) { | |||
208 | static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { | 212 | static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { |
209 | int i; | 213 | int i; |
210 | int nfixargs = p->numparams; | 214 | int nfixargs = p->numparams; |
215 | #if defined(LUA_COMPAT_VARARG) | ||
211 | Table *htab = NULL; | 216 | Table *htab = NULL; |
217 | #endif | ||
212 | StkId base, fixed; | 218 | StkId base, fixed; |
213 | for (; actual < nfixargs; ++actual) | 219 | for (; actual < nfixargs; ++actual) |
214 | setnilvalue(L->top++); | 220 | setnilvalue(L->top++); |
@@ -219,10 +225,15 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { | |||
219 | luaC_checkGC(L); | 225 | luaC_checkGC(L); |
220 | luaD_checkstack(L, p->maxstacksize); | 226 | luaD_checkstack(L, p->maxstacksize); |
221 | htab = luaH_new(L, nvar, 1); /* create `arg' table */ | 227 | htab = luaH_new(L, nvar, 1); /* create `arg' table */ |
228 | sethvalue2s(L, L->top, htab); /* put table on stack */ | ||
229 | incr_top(L); | ||
230 | fixedstack(L); | ||
222 | for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ | 231 | for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ |
223 | setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i); | 232 | setobj2n(L, luaH_setnum(L, htab, i+1), L->top - 1 - nvar + i); |
233 | unfixedstack(L); | ||
224 | /* store counter in field `n' */ | 234 | /* store counter in field `n' */ |
225 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); | 235 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); |
236 | L->top--; /* remove table from stack */ | ||
226 | } | 237 | } |
227 | #endif | 238 | #endif |
228 | /* move fixed parameters to final position */ | 239 | /* move fixed parameters to final position */ |
@@ -232,11 +243,13 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { | |||
232 | setobjs2s(L, L->top++, fixed+i); | 243 | setobjs2s(L, L->top++, fixed+i); |
233 | setnilvalue(fixed+i); | 244 | setnilvalue(fixed+i); |
234 | } | 245 | } |
246 | #if defined(LUA_COMPAT_VARARG) | ||
235 | /* add `arg' parameter */ | 247 | /* add `arg' parameter */ |
236 | if (htab) { | 248 | if (htab) { |
237 | sethvalue(L, L->top++, htab); | 249 | sethvalue(L, L->top++, htab); |
238 | lua_assert(iswhite(obj2gco(htab))); | 250 | lua_assert(iswhite(obj2gco(htab))); |
239 | } | 251 | } |
252 | #endif | ||
240 | return base; | 253 | return base; |
241 | } | 254 | } |
242 | 255 | ||
@@ -495,6 +508,7 @@ static void f_parser (lua_State *L, void *ud) { | |||
495 | struct SParser *p = cast(struct SParser *, ud); | 508 | struct SParser *p = cast(struct SParser *, ud); |
496 | int c = luaZ_lookahead(p->z); | 509 | int c = luaZ_lookahead(p->z); |
497 | luaC_checkGC(L); | 510 | luaC_checkGC(L); |
511 | set_block_gc(L); /* stop collector during parsing */ | ||
498 | tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, | 512 | tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, |
499 | &p->buff, p->name); | 513 | &p->buff, p->name); |
500 | cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); | 514 | cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); |
@@ -503,6 +517,7 @@ static void f_parser (lua_State *L, void *ud) { | |||
503 | cl->l.upvals[i] = luaF_newupval(L); | 517 | cl->l.upvals[i] = luaF_newupval(L); |
504 | setclvalue(L, L->top, cl); | 518 | setclvalue(L, L->top, cl); |
505 | incr_top(L); | 519 | incr_top(L); |
520 | unset_block_gc(L); | ||
506 | } | 521 | } |
507 | 522 | ||
508 | 523 | ||