diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2026-01-11 15:36:03 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2026-01-11 15:36:03 -0300 |
| commit | 2a7cf4f319fc276f4554a8f6364e6b1ba4eb2ded (patch) | |
| tree | a99a8361664b0adda83186f04e2e9c98afd86b44 /ltests.c | |
| parent | 5cfc725a8b61a6f96c7324f60ac26739315095ba (diff) | |
| download | lua-2a7cf4f319fc276f4554a8f6364e6b1ba4eb2ded.tar.gz lua-2a7cf4f319fc276f4554a8f6364e6b1ba4eb2ded.tar.bz2 lua-2a7cf4f319fc276f4554a8f6364e6b1ba4eb2ded.zip | |
Before calling a finalizer, Lua not only checks stack limits, but
actually ensures that a minimum number of slots are already allocated
for the call. (If it cannot ensure that, it postpones the finalizer.)
That avoids finalizers not running due to memory errors that the
programmer cannot control.
Diffstat (limited to 'ltests.c')
| -rw-r--r-- | ltests.c | 23 |
1 files changed, 23 insertions, 0 deletions
| @@ -1106,6 +1106,27 @@ static int stacklevel (lua_State *L) { | |||
| 1106 | } | 1106 | } |
| 1107 | 1107 | ||
| 1108 | 1108 | ||
| 1109 | static int resetCI (lua_State *L) { | ||
| 1110 | CallInfo *ci = L->ci; | ||
| 1111 | while (ci->next != NULL) { | ||
| 1112 | CallInfo *tofree = ci->next; | ||
| 1113 | ci->next = ci->next->next; | ||
| 1114 | luaM_free(L, tofree); | ||
| 1115 | L->nci--; | ||
| 1116 | } | ||
| 1117 | return 0; | ||
| 1118 | } | ||
| 1119 | |||
| 1120 | |||
| 1121 | static int reallocstack (lua_State *L) { | ||
| 1122 | int n = cast_int(luaL_checkinteger(L, 1)); | ||
| 1123 | lua_lock(L); | ||
| 1124 | luaD_reallocstack(L, cast_int(L->top.p - L->stack.p) + n, 1); | ||
| 1125 | lua_unlock(L); | ||
| 1126 | return 0; | ||
| 1127 | } | ||
| 1128 | |||
| 1129 | |||
| 1109 | static int table_query (lua_State *L) { | 1130 | static int table_query (lua_State *L) { |
| 1110 | const Table *t; | 1131 | const Table *t; |
| 1111 | int i = cast_int(luaL_optinteger(L, 2, -1)); | 1132 | int i = cast_int(luaL_optinteger(L, 2, -1)); |
| @@ -2182,6 +2203,8 @@ static const struct luaL_Reg tests_funcs[] = { | |||
| 2182 | {"s2d", s2d}, | 2203 | {"s2d", s2d}, |
| 2183 | {"sethook", sethook}, | 2204 | {"sethook", sethook}, |
| 2184 | {"stacklevel", stacklevel}, | 2205 | {"stacklevel", stacklevel}, |
| 2206 | {"resetCI", resetCI}, | ||
| 2207 | {"reallocstack", reallocstack}, | ||
| 2185 | {"sizes", get_sizes}, | 2208 | {"sizes", get_sizes}, |
| 2186 | {"testC", testC}, | 2209 | {"testC", testC}, |
| 2187 | {"makeCfunc", makeCfunc}, | 2210 | {"makeCfunc", makeCfunc}, |
