From 6ccd24eff58340c00db2877c4558a63c6b859442 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 19 Jan 2021 10:03:13 -0300 Subject: Simpler handling of errors when creating tbc variables New field 'lua_State.ptbc' keeps to-be-closed variable until its upvalue is created, so that it can be closed in case of a memory-allocation error. --- lstate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lstate.c') diff --git a/lstate.c b/lstate.c index 92ccbf9b..c708a162 100644 --- a/lstate.c +++ b/lstate.c @@ -253,6 +253,7 @@ static void preinit_thread (lua_State *L, global_State *g) { L->ci = NULL; L->nci = 0; L->twups = L; /* thread has no upvalues */ + L->nCcalls = 0; L->errorJmp = NULL; L->hook = NULL; L->hookmask = 0; @@ -263,6 +264,7 @@ static void preinit_thread (lua_State *L, global_State *g) { L->status = LUA_OK; L->errfunc = 0; L->oldpc = 0; + L->ptbc = NULL; } @@ -296,7 +298,6 @@ LUA_API lua_State *lua_newthread (lua_State *L) { setthvalue2s(L, L->top, L1); api_incr_top(L); preinit_thread(L1, g); - L1->nCcalls = 0; L1->hookmask = L->hookmask; L1->basehookcount = L->basehookcount; L1->hook = L->hook; @@ -363,7 +364,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { preinit_thread(L, g); g->allgc = obj2gco(L); /* by now, only object is the main thread */ L->next = NULL; - L->nCcalls = 0; incnny(L); /* main thread is always non yieldable */ g->frealloc = f; g->ud = ud; -- cgit v1.2.3-55-g6feb