From 7af27ef59da4051914d93d8b63efac663b64765a Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 28 Dec 2020 11:40:30 -0300 Subject: Cleaner handling of errors in '__close' metamethods Instead of protecting each individual metamethod call, protect the entire call to 'luaF_close'. --- lstate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lstate.c') diff --git a/lstate.c b/lstate.c index 96187c66..e01a7e7b 100644 --- a/lstate.c +++ b/lstate.c @@ -268,7 +268,7 @@ static void preinit_thread (lua_State *L, global_State *g) { static void close_state (lua_State *L) { global_State *g = G(L); - luaF_close(L, L->stack, CLOSEPROTECT); /* close all upvalues */ + luaD_closeprotected(L, 0, LUA_OK); /* close all upvalues */ luaC_freeallobjects(L); /* collect all objects */ if (ttisnil(&g->nilvalue)) /* closing a fully built state? */ luai_userstateclose(L); @@ -329,10 +329,10 @@ int lua_resetthread (lua_State *L) { setnilvalue(s2v(L->stack)); /* 'function' entry for basic 'ci' */ ci->func = L->stack; ci->callstatus = CIST_C; - if (status == LUA_OK || status == LUA_YIELD) - status = CLOSEPROTECT; /* run closing methods in protected mode */ - status = luaF_close(L, L->stack, status); - if (status != CLOSEPROTECT) /* errors? */ + if (status == LUA_YIELD) + status = LUA_OK; + status = luaD_closeprotected(L, 0, status); + if (status != LUA_OK) /* errors? */ luaD_seterrorobj(L, status, L->stack + 1); else { status = LUA_OK; -- cgit v1.2.3-55-g6feb