diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-02-05 11:00:28 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-02-05 11:00:28 -0300 |
commit | 2bfa13e520e53210b96ead88f49a9ca20c5a5d18 (patch) | |
tree | ef9c505f3ef9f6008d0bf993f2ed03fa04faac0e | |
parent | e500892e18e994781760819e33098322728796e8 (diff) | |
download | lua-2bfa13e520e53210b96ead88f49a9ca20c5a5d18.tar.gz lua-2bfa13e520e53210b96ead88f49a9ca20c5a5d18.tar.bz2 lua-2bfa13e520e53210b96ead88f49a9ca20c5a5d18.zip |
Fixed some bugs around stack reallocation
Long time without using HARDSTACKTESTS...
-rw-r--r-- | lapi.c | 1 | ||||
-rw-r--r-- | ldo.c | 2 | ||||
-rw-r--r-- | lfunc.c | 2 | ||||
-rw-r--r-- | lvm.c | 2 |
4 files changed, 6 insertions, 1 deletions
@@ -207,6 +207,7 @@ LUA_API void lua_closeslot (lua_State *L, int idx) { | |||
207 | uplevel(L->openupval) == level, | 207 | uplevel(L->openupval) == level, |
208 | "no variable to close at given level"); | 208 | "no variable to close at given level"); |
209 | luaF_close(L, level, CLOSEKTOP, 0); | 209 | luaF_close(L, level, CLOSEKTOP, 0); |
210 | level = index2stack(L, idx); /* stack may be moved */ | ||
210 | setnilvalue(s2v(level)); | 211 | setnilvalue(s2v(level)); |
211 | lua_unlock(L); | 212 | lua_unlock(L); |
212 | } | 213 | } |
@@ -412,12 +412,12 @@ static void moveresults (lua_State *L, StkId res, int nres, int wanted) { | |||
412 | if (hastocloseCfunc(wanted)) { /* to-be-closed variables? */ | 412 | if (hastocloseCfunc(wanted)) { /* to-be-closed variables? */ |
413 | ptrdiff_t savedres = savestack(L, res); | 413 | ptrdiff_t savedres = savestack(L, res); |
414 | luaF_close(L, res, CLOSEKTOP, 0); /* may change the stack */ | 414 | luaF_close(L, res, CLOSEKTOP, 0); /* may change the stack */ |
415 | res = restorestack(L, savedres); | ||
416 | wanted = codeNresults(wanted); /* correct value */ | 415 | wanted = codeNresults(wanted); /* correct value */ |
417 | if (wanted == LUA_MULTRET) | 416 | if (wanted == LUA_MULTRET) |
418 | wanted = nres; | 417 | wanted = nres; |
419 | if (L->hookmask) /* if needed, call hook after '__close's */ | 418 | if (L->hookmask) /* if needed, call hook after '__close's */ |
420 | rethook(L, L->ci, nres); | 419 | rethook(L, L->ci, nres); |
420 | res = restorestack(L, savedres); /* close and hook can move stack */ | ||
421 | } | 421 | } |
422 | break; | 422 | break; |
423 | } | 423 | } |
@@ -190,9 +190,11 @@ void luaF_close (lua_State *L, StkId level, int status, int yy) { | |||
190 | UpVal *uv; | 190 | UpVal *uv; |
191 | StkId upl; /* stack index pointed by 'uv' */ | 191 | StkId upl; /* stack index pointed by 'uv' */ |
192 | if (unlikely(status == LUA_ERRMEM && L->ptbc != NULL)) { | 192 | if (unlikely(status == LUA_ERRMEM && L->ptbc != NULL)) { |
193 | ptrdiff_t levelrel = savestack(L, level); | ||
193 | upl = L->ptbc; | 194 | upl = L->ptbc; |
194 | L->ptbc = NULL; /* remove from "list" before closing */ | 195 | L->ptbc = NULL; /* remove from "list" before closing */ |
195 | prepcallclosemth(L, upl, status, yy); | 196 | prepcallclosemth(L, upl, status, yy); |
197 | level = restorestack(L, levelrel); | ||
196 | } | 198 | } |
197 | else | 199 | else |
198 | lua_assert(L->ptbc == NULL); /* must be empty for other status */ | 200 | lua_assert(L->ptbc == NULL); /* must be empty for other status */ |
@@ -1150,6 +1150,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1150 | Instruction i; /* instruction being executed */ | 1150 | Instruction i; /* instruction being executed */ |
1151 | StkId ra; /* instruction's A register */ | 1151 | StkId ra; /* instruction's A register */ |
1152 | vmfetch(); | 1152 | vmfetch(); |
1153 | // low-level line tracing for debugging Lua | ||
1154 | // printf("line: %d\n", luaG_getfuncline(cl->p, pcRel(pc, cl->p))); | ||
1153 | lua_assert(base == ci->func + 1); | 1155 | lua_assert(base == ci->func + 1); |
1154 | lua_assert(base <= L->top && L->top < L->stack_last); | 1156 | lua_assert(base <= L->top && L->top < L->stack_last); |
1155 | /* invalidate top for instructions not expecting it */ | 1157 | /* invalidate top for instructions not expecting it */ |