diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-07-11 12:53:29 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-07-11 12:53:29 -0300 |
| commit | 3ca9af51a4f060cf2178901a67a21f8269af3224 (patch) | |
| tree | 4f1bb541280aa8b4960b16d0925eca60adb2b1a8 /ldo.c | |
| parent | c7b89dd28097296bbc14d9b47b4cea72514b2b76 (diff) | |
| download | lua-3ca9af51a4f060cf2178901a67a21f8269af3224.tar.gz lua-3ca9af51a4f060cf2178901a67a21f8269af3224.tar.bz2 lua-3ca9af51a4f060cf2178901a67a21f8269af3224.zip | |
emergency garbage collector (core forces a GC when allocation fails)
Diffstat (limited to 'ldo.c')
| -rw-r--r-- | ldo.c | 21 |
1 files changed, 12 insertions, 9 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.37 2005/12/22 16:19:56 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.38 2006/06/05 19:36:14 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 | */ |
| @@ -81,7 +81,7 @@ static void restore_stack_limit (lua_State *L) { | |||
| 81 | static void resetstack (lua_State *L, int status) { | 81 | static void resetstack (lua_State *L, int status) { |
| 82 | L->ci = L->base_ci; | 82 | L->ci = L->base_ci; |
| 83 | L->base = L->ci->base; | 83 | L->base = L->ci->base; |
| 84 | luaF_close(L, L->base); /* close eventual pending closures */ | 84 | luaF_close(L, L->base); /* close possible pending closures */ |
| 85 | luaD_seterrorobj(L, status, L->base); | 85 | luaD_seterrorobj(L, status, L->base); |
| 86 | L->nCcalls = 0; | 86 | L->nCcalls = 0; |
| 87 | L->allowhook = 1; | 87 | L->allowhook = 1; |
| @@ -217,11 +217,13 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { | |||
| 217 | int nvar = actual - nfixargs; /* number of extra arguments */ | 217 | int nvar = actual - nfixargs; /* number of extra arguments */ |
| 218 | lua_assert(p->is_vararg & VARARG_HASARG); | 218 | lua_assert(p->is_vararg & VARARG_HASARG); |
| 219 | luaC_checkGC(L); | 219 | luaC_checkGC(L); |
| 220 | htab = luaH_new(L, nvar, 1); /* create `arg' table */ | 220 | htab = luaH_new(L); /* create `arg' table */ |
| 221 | sethvalue(L, L->top++, htab); | ||
| 221 | for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ | 222 | for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ |
| 222 | setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i); | 223 | setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i - 1); |
| 223 | /* store counter in field `n' */ | 224 | /* store counter in field `n' */ |
| 224 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); | 225 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); |
| 226 | L->top--; | ||
| 225 | } | 227 | } |
| 226 | #endif | 228 | #endif |
| 227 | /* move fixed parameters to final position */ | 229 | /* move fixed parameters to final position */ |
| @@ -332,7 +334,7 @@ static StkId callrethooks (lua_State *L, StkId firstResult) { | |||
| 332 | ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ | 334 | ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ |
| 333 | luaD_callhook(L, LUA_HOOKRET, -1); | 335 | luaD_callhook(L, LUA_HOOKRET, -1); |
| 334 | if (f_isLua(L->ci)) { /* Lua function? */ | 336 | if (f_isLua(L->ci)) { /* Lua function? */ |
| 335 | while (L->ci->tailcalls--) /* call hook for eventual tail calls */ | 337 | while (L->ci->tailcalls--) /* call hook for possible tail calls */ |
| 336 | luaD_callhook(L, LUA_HOOKTAILRET, -1); | 338 | luaD_callhook(L, LUA_HOOKTAILRET, -1); |
| 337 | } | 339 | } |
| 338 | return restorestack(L, fr); | 340 | return restorestack(L, fr); |
| @@ -461,7 +463,7 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u, | |||
| 461 | status = luaD_rawrunprotected(L, func, u); | 463 | status = luaD_rawrunprotected(L, func, u); |
| 462 | if (status != 0) { /* an error occurred? */ | 464 | if (status != 0) { /* an error occurred? */ |
| 463 | StkId oldtop = restorestack(L, old_top); | 465 | StkId oldtop = restorestack(L, old_top); |
| 464 | luaF_close(L, oldtop); /* close eventual pending closures */ | 466 | luaF_close(L, oldtop); /* close possible pending closures */ |
| 465 | luaD_seterrorobj(L, status, oldtop); | 467 | luaD_seterrorobj(L, status, oldtop); |
| 466 | L->nCcalls = oldnCcalls; | 468 | L->nCcalls = oldnCcalls; |
| 467 | L->ci = restoreci(L, old_ci); | 469 | L->ci = restoreci(L, old_ci); |
| @@ -494,12 +496,13 @@ static void f_parser (lua_State *L, void *ud) { | |||
| 494 | luaC_checkGC(L); | 496 | luaC_checkGC(L); |
| 495 | tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, | 497 | tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, |
| 496 | &p->buff, p->name); | 498 | &p->buff, p->name); |
| 499 | setptvalue2s(L, L->top, tf); | ||
| 500 | incr_top(L); | ||
| 497 | cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); | 501 | cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); |
| 498 | cl->l.p = tf; | 502 | cl->l.p = tf; |
| 499 | for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ | 503 | setclvalue(L, L->top - 1, cl); |
| 504 | for (i = 0; i < tf->nups; i++) /* initialize upvalues */ | ||
| 500 | cl->l.upvals[i] = luaF_newupval(L); | 505 | cl->l.upvals[i] = luaF_newupval(L); |
| 501 | setclvalue(L, L->top, cl); | ||
| 502 | incr_top(L); | ||
| 503 | } | 506 | } |
| 504 | 507 | ||
| 505 | 508 | ||
