diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-02-09 14:00:05 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-02-09 14:00:05 -0300 |
commit | 4e47f81188d37e29027158b76271d02a781242e2 (patch) | |
tree | c360912d1901acf8371390cc1f716278e5d91bb4 /lapi.c | |
parent | c63e5d212bc5dec1b1c749e3f07b42cd83081826 (diff) | |
download | lua-4e47f81188d37e29027158b76271d02a781242e2.tar.gz lua-4e47f81188d37e29027158b76271d02a781242e2.tar.bz2 lua-4e47f81188d37e29027158b76271d02a781242e2.zip |
New implementation for to-be-closed variables
To-be-closed variables are linked in their own list, embedded into the
stack elements. (Due to alignment, this information does not change
the size of the stack elements in most architectures.) This new list
does not produce garbage and avoids memory errors when creating tbc
variables.
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 9 |
1 files changed, 3 insertions, 6 deletions
@@ -192,9 +192,8 @@ LUA_API void lua_settop (lua_State *L, int idx) { | |||
192 | if (diff < 0 && hastocloseCfunc(ci->nresults)) | 192 | if (diff < 0 && hastocloseCfunc(ci->nresults)) |
193 | luaF_close(L, L->top + diff, CLOSEKTOP, 0); | 193 | luaF_close(L, L->top + diff, CLOSEKTOP, 0); |
194 | #endif | 194 | #endif |
195 | api_check(L, L->tbclist < L->top + diff, "cannot pop an unclosed slot"); | ||
195 | L->top += diff; | 196 | L->top += diff; |
196 | api_check(L, L->openupval == NULL || uplevel(L->openupval) < L->top, | ||
197 | "cannot pop an unclosed slot"); | ||
198 | lua_unlock(L); | 197 | lua_unlock(L); |
199 | } | 198 | } |
200 | 199 | ||
@@ -203,8 +202,7 @@ LUA_API void lua_closeslot (lua_State *L, int idx) { | |||
203 | StkId level; | 202 | StkId level; |
204 | lua_lock(L); | 203 | lua_lock(L); |
205 | level = index2stack(L, idx); | 204 | level = index2stack(L, idx); |
206 | api_check(L, hastocloseCfunc(L->ci->nresults) && L->openupval != NULL && | 205 | api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist == level, |
207 | uplevel(L->openupval) == level, | ||
208 | "no variable to close at given level"); | 206 | "no variable to close at given level"); |
209 | luaF_close(L, level, CLOSEKTOP, 0); | 207 | luaF_close(L, level, CLOSEKTOP, 0); |
210 | level = index2stack(L, idx); /* stack may be moved */ | 208 | level = index2stack(L, idx); /* stack may be moved */ |
@@ -1266,8 +1264,7 @@ LUA_API void lua_toclose (lua_State *L, int idx) { | |||
1266 | lua_lock(L); | 1264 | lua_lock(L); |
1267 | o = index2stack(L, idx); | 1265 | o = index2stack(L, idx); |
1268 | nresults = L->ci->nresults; | 1266 | nresults = L->ci->nresults; |
1269 | api_check(L, L->openupval == NULL || uplevel(L->openupval) <= o, | 1267 | api_check(L, L->tbclist < o, "given index below or equal a marked one"); |
1270 | "marked index below or equal new one"); | ||
1271 | luaF_newtbcupval(L, o); /* create new to-be-closed upvalue */ | 1268 | luaF_newtbcupval(L, o); /* create new to-be-closed upvalue */ |
1272 | if (!hastocloseCfunc(nresults)) /* function not marked yet? */ | 1269 | if (!hastocloseCfunc(nresults)) /* function not marked yet? */ |
1273 | L->ci->nresults = codeNresults(nresults); /* mark it */ | 1270 | L->ci->nresults = codeNresults(nresults); /* mark it */ |