diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-07-07 18:03:48 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-07-07 18:03:48 -0300 |
commit | eb41999461b6f428186c55abd95f4ce1a76217d5 (patch) | |
tree | 577e56c4ad5999b34966232b1e2a2bf9a63f7cc2 /ltm.c | |
parent | 314c6057b785cd94ac88905ccfce61724107d66b (diff) | |
download | lua-eb41999461b6f428186c55abd95f4ce1a76217d5.tar.gz lua-eb41999461b6f428186c55abd95f4ce1a76217d5.tar.bz2 lua-eb41999461b6f428186c55abd95f4ce1a76217d5.zip |
Fixed bugs of stack reallocation x GC
Macro 'checkstackGC' was doing a GC step after resizing the stack;
the GC could shrink the stack and undo the resize. Moreover, macro
'checkstackp' also does a GC step, which could remove the preallocated
CallInfo when calling a function. (Its name has been changed to
'checkstackGCp' to emphasize that it calls the GC.)
Diffstat (limited to 'ltm.c')
-rw-r--r-- | ltm.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -240,7 +240,7 @@ void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci, | |||
240 | int actual = cast_int(L->top - ci->func) - 1; /* number of arguments */ | 240 | int actual = cast_int(L->top - ci->func) - 1; /* number of arguments */ |
241 | int nextra = actual - nfixparams; /* number of extra arguments */ | 241 | int nextra = actual - nfixparams; /* number of extra arguments */ |
242 | ci->u.l.nextraargs = nextra; | 242 | ci->u.l.nextraargs = nextra; |
243 | checkstackGC(L, p->maxstacksize + 1); | 243 | luaD_checkstack(L, p->maxstacksize + 1); |
244 | /* copy function to the top of the stack */ | 244 | /* copy function to the top of the stack */ |
245 | setobjs2s(L, L->top++, ci->func); | 245 | setobjs2s(L, L->top++, ci->func); |
246 | /* move fixed parameters to the top of the stack */ | 246 | /* move fixed parameters to the top of the stack */ |
@@ -259,7 +259,7 @@ void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted) { | |||
259 | int nextra = ci->u.l.nextraargs; | 259 | int nextra = ci->u.l.nextraargs; |
260 | if (wanted < 0) { | 260 | if (wanted < 0) { |
261 | wanted = nextra; /* get all extra arguments available */ | 261 | wanted = nextra; /* get all extra arguments available */ |
262 | checkstackp(L, nextra, where); /* ensure stack space */ | 262 | checkstackGCp(L, nextra, where); /* ensure stack space */ |
263 | L->top = where + nextra; /* next instruction will need top */ | 263 | L->top = where + nextra; /* next instruction will need top */ |
264 | } | 264 | } |
265 | for (i = 0; i < wanted && i < nextra; i++) | 265 | for (i = 0; i < wanted && i < nextra; i++) |