diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-28 16:45:15 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-28 16:45:15 -0300 |
commit | 69dd9461e5aeb98fe9bbc71f1e81859d03ec8a34 (patch) | |
tree | d9505d7a0e89940c55ff0a1fd3c13311b9084197 /ldo.c | |
parent | 6b6bc532a4f5e335540e6f19914cfe8435d064ed (diff) | |
download | lua-69dd9461e5aeb98fe9bbc71f1e81859d03ec8a34.tar.gz lua-69dd9461e5aeb98fe9bbc71f1e81859d03ec8a34.tar.bz2 lua-69dd9461e5aeb98fe9bbc71f1e81859d03ec8a34.zip |
bug: GC metamethod calls could mess C/Lua stack syncronization
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.214 2003/02/27 11:52:30 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.215 2003/02/28 15:42:08 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -292,7 +292,6 @@ void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { | |||
292 | while (wanted-- > 0) | 292 | while (wanted-- > 0) |
293 | setnilvalue(res++); | 293 | setnilvalue(res++); |
294 | L->top = res; | 294 | L->top = res; |
295 | luaC_checkGC(L); | ||
296 | } | 295 | } |
297 | 296 | ||
298 | 297 | ||
@@ -304,9 +303,10 @@ void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { | |||
304 | */ | 303 | */ |
305 | void luaD_call (lua_State *L, StkId func, int nResults) { | 304 | void luaD_call (lua_State *L, StkId func, int nResults) { |
306 | StkId firstResult; | 305 | StkId firstResult; |
306 | lua_assert(!(L->ci->state & CI_CALLING)); | ||
307 | if (++L->nCcalls >= LUA_MAXCCALLS) { | 307 | if (++L->nCcalls >= LUA_MAXCCALLS) { |
308 | if (L->nCcalls == LUA_MAXCCALLS) | 308 | if (L->nCcalls == LUA_MAXCCALLS) |
309 | luaG_runerror(L, "stack overflow"); | 309 | luaG_runerror(L, "C stack overflow"); |
310 | else if (L->nCcalls >= (LUA_MAXCCALLS + (LUA_MAXCCALLS>>3))) | 310 | else if (L->nCcalls >= (LUA_MAXCCALLS + (LUA_MAXCCALLS>>3))) |
311 | luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ | 311 | luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ |
312 | } | 312 | } |
@@ -315,6 +315,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
315 | firstResult = luaV_execute(L); /* call it */ | 315 | firstResult = luaV_execute(L); /* call it */ |
316 | luaD_poscall(L, nResults, firstResult); | 316 | luaD_poscall(L, nResults, firstResult); |
317 | L->nCcalls--; | 317 | L->nCcalls--; |
318 | luaC_checkGC(L); | ||
318 | } | 319 | } |
319 | 320 | ||
320 | 321 | ||
@@ -428,10 +429,13 @@ struct SParser { /* data to `f_parser' */ | |||
428 | }; | 429 | }; |
429 | 430 | ||
430 | static void f_parser (lua_State *L, void *ud) { | 431 | static void f_parser (lua_State *L, void *ud) { |
431 | struct SParser *p = cast(struct SParser *, ud); | 432 | struct SParser *p; |
432 | Proto *tf = p->bin ? luaU_undump(L, p->z, &p->buff) : | 433 | Proto *tf; |
433 | luaY_parser(L, p->z, &p->buff); | 434 | Closure *cl; |
434 | Closure *cl = luaF_newLclosure(L, 0, gt(L)); | 435 | luaC_checkGC(L); |
436 | p = cast(struct SParser *, ud); | ||
437 | tf = p->bin ? luaU_undump(L, p->z, &p->buff) : luaY_parser(L, p->z, &p->buff); | ||
438 | cl = luaF_newLclosure(L, 0, gt(L)); | ||
435 | cl->l.p = tf; | 439 | cl->l.p = tf; |
436 | setclvalue(L->top, cl); | 440 | setclvalue(L->top, cl); |
437 | incr_top(L); | 441 | incr_top(L); |