diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-01-28 10:08:04 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-01-28 10:08:04 -0200 |
commit | 53979dfe0dbd7eba767ff37b1148d1e4dc9f8294 (patch) | |
tree | cdb8fac7540edc3fcd7695aa6cf09fdc5e171b53 | |
parent | 6710a2b0ef164cb5bf3412353400aada5ac3f373 (diff) | |
download | lua-53979dfe0dbd7eba767ff37b1148d1e4dc9f8294.tar.gz lua-53979dfe0dbd7eba767ff37b1148d1e4dc9f8294.tar.bz2 lua-53979dfe0dbd7eba767ff37b1148d1e4dc9f8294.zip |
calling a vararg function needs to check GC
(because it creates a new table)
-rw-r--r-- | ldo.c | 14 | ||||
-rw-r--r-- | ltm.c | 4 |
2 files changed, 10 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.185 2017/12/29 15:44:51 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.186 2018/01/10 19:19:27 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 | */ |
@@ -417,14 +417,14 @@ void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n) { | |||
417 | checkstackp(L, fsize, func); | 417 | checkstackp(L, fsize, func); |
418 | for (; i <= p->numparams; i++) | 418 | for (; i <= p->numparams; i++) |
419 | setnilvalue(s2v(ci->func + i)); /* complete missing arguments */ | 419 | setnilvalue(s2v(ci->func + i)); /* complete missing arguments */ |
420 | if (p->is_vararg) { | ||
421 | L->top -= (func - ci->func); /* move down top */ | ||
422 | luaT_adjustvarargs(L, p, n - 1); | ||
423 | } | ||
424 | ci->top = ci->func + 1 + fsize; /* top for new function */ | 420 | ci->top = ci->func + 1 + fsize; /* top for new function */ |
425 | lua_assert(ci->top <= L->stack_last); | 421 | lua_assert(ci->top <= L->stack_last); |
426 | ci->u.l.savedpc = p->code; /* starting point */ | 422 | ci->u.l.savedpc = p->code; /* starting point */ |
427 | ci->callstatus |= CIST_TAIL; | 423 | ci->callstatus |= CIST_TAIL; |
424 | if (p->is_vararg) { | ||
425 | L->top -= (func - ci->func); /* move down top */ | ||
426 | luaT_adjustvarargs(L, p, n - 1); | ||
427 | } | ||
428 | if (L->hookmask) | 428 | if (L->hookmask) |
429 | hookcall(L, ci, 1); | 429 | hookcall(L, ci, 1); |
430 | } | 430 | } |
@@ -471,8 +471,6 @@ void luaD_call (lua_State *L, StkId func, int nresults) { | |||
471 | checkstackp(L, fsize, func); | 471 | checkstackp(L, fsize, func); |
472 | for (; n < p->numparams; n++) | 472 | for (; n < p->numparams; n++) |
473 | setnilvalue(s2v(L->top++)); /* complete missing arguments */ | 473 | setnilvalue(s2v(L->top++)); /* complete missing arguments */ |
474 | if (p->is_vararg) | ||
475 | luaT_adjustvarargs(L, p, n); | ||
476 | ci = next_ci(L); /* now 'enter' new function */ | 474 | ci = next_ci(L); /* now 'enter' new function */ |
477 | ci->nresults = nresults; | 475 | ci->nresults = nresults; |
478 | ci->func = func; | 476 | ci->func = func; |
@@ -480,6 +478,8 @@ void luaD_call (lua_State *L, StkId func, int nresults) { | |||
480 | lua_assert(ci->top <= L->stack_last); | 478 | lua_assert(ci->top <= L->stack_last); |
481 | ci->u.l.savedpc = p->code; /* starting point */ | 479 | ci->u.l.savedpc = p->code; /* starting point */ |
482 | ci->callstatus = 0; | 480 | ci->callstatus = 0; |
481 | if (p->is_vararg) | ||
482 | luaT_adjustvarargs(L, p, n); /* may invoke GC */ | ||
483 | if (L->hookmask) | 483 | if (L->hookmask) |
484 | hookcall(L, ci, 0); | 484 | hookcall(L, ci, 0); |
485 | luaV_execute(L, ci); /* run the function */ | 485 | luaV_execute(L, ci); /* run the function */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 2.55 2017/12/20 14:58:05 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 2.56 2017/12/28 15:42:57 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | #include "ldebug.h" | 17 | #include "ldebug.h" |
18 | #include "ldo.h" | 18 | #include "ldo.h" |
19 | #include "lgc.h" | ||
19 | #include "lobject.h" | 20 | #include "lobject.h" |
20 | #include "lstate.h" | 21 | #include "lstate.h" |
21 | #include "lstring.h" | 22 | #include "lstring.h" |
@@ -231,6 +232,7 @@ void luaT_adjustvarargs (lua_State *L, Proto *p, int actual) { | |||
231 | setivalue(luaH_set(L, vtab, &nname), actual); /* store counter there */ | 232 | setivalue(luaH_set(L, vtab, &nname), actual); /* store counter there */ |
232 | L->top -= actual; /* remove extra elements from the stack */ | 233 | L->top -= actual; /* remove extra elements from the stack */ |
233 | sethvalue2s(L, L->top - 1, vtab); /* move table to new top */ | 234 | sethvalue2s(L, L->top - 1, vtab); /* move table to new top */ |
235 | luaC_checkGC(L); | ||
234 | } | 236 | } |
235 | 237 | ||
236 | 238 | ||