diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-12-28 11:40:30 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-12-28 11:40:30 -0300 |
commit | 7af27ef59da4051914d93d8b63efac663b64765a (patch) | |
tree | 73ac919879b442904112dbb972412fc15983d50e /lstate.c | |
parent | 0ceada8da92135717d31a3954b5b89a954f9e71a (diff) | |
download | lua-7af27ef59da4051914d93d8b63efac663b64765a.tar.gz lua-7af27ef59da4051914d93d8b63efac663b64765a.tar.bz2 lua-7af27ef59da4051914d93d8b63efac663b64765a.zip |
Cleaner handling of errors in '__close' metamethods
Instead of protecting each individual metamethod call, protect the
entire call to 'luaF_close'.
Diffstat (limited to 'lstate.c')
-rw-r--r-- | lstate.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -268,7 +268,7 @@ static void preinit_thread (lua_State *L, global_State *g) { | |||
268 | 268 | ||
269 | static void close_state (lua_State *L) { | 269 | static void close_state (lua_State *L) { |
270 | global_State *g = G(L); | 270 | global_State *g = G(L); |
271 | luaF_close(L, L->stack, CLOSEPROTECT); /* close all upvalues */ | 271 | luaD_closeprotected(L, 0, LUA_OK); /* close all upvalues */ |
272 | luaC_freeallobjects(L); /* collect all objects */ | 272 | luaC_freeallobjects(L); /* collect all objects */ |
273 | if (ttisnil(&g->nilvalue)) /* closing a fully built state? */ | 273 | if (ttisnil(&g->nilvalue)) /* closing a fully built state? */ |
274 | luai_userstateclose(L); | 274 | luai_userstateclose(L); |
@@ -329,10 +329,10 @@ int lua_resetthread (lua_State *L) { | |||
329 | setnilvalue(s2v(L->stack)); /* 'function' entry for basic 'ci' */ | 329 | setnilvalue(s2v(L->stack)); /* 'function' entry for basic 'ci' */ |
330 | ci->func = L->stack; | 330 | ci->func = L->stack; |
331 | ci->callstatus = CIST_C; | 331 | ci->callstatus = CIST_C; |
332 | if (status == LUA_OK || status == LUA_YIELD) | 332 | if (status == LUA_YIELD) |
333 | status = CLOSEPROTECT; /* run closing methods in protected mode */ | 333 | status = LUA_OK; |
334 | status = luaF_close(L, L->stack, status); | 334 | status = luaD_closeprotected(L, 0, status); |
335 | if (status != CLOSEPROTECT) /* errors? */ | 335 | if (status != LUA_OK) /* errors? */ |
336 | luaD_seterrorobj(L, status, L->stack + 1); | 336 | luaD_seterrorobj(L, status, L->stack + 1); |
337 | else { | 337 | else { |
338 | status = LUA_OK; | 338 | status = LUA_OK; |