From 76953316d1283ab6324b59b914ef53a521408444 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 3 Nov 2022 16:37:13 -0300 Subject: Added a counter of the total number of existing objects It may simplify the control of the garbage collector. --- lstate.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lstate.c') diff --git a/lstate.c b/lstate.c index 1fbefb4b..3091a00e 100644 --- a/lstate.c +++ b/lstate.c @@ -279,6 +279,7 @@ static void close_state (lua_State *L) { luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); freestack(L); lua_assert(gettotalbytes(g) == sizeof(LG)); + lua_assert(g->totalobjs == 1); (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ } @@ -387,6 +388,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { g->weak = g->ephemeron = g->allweak = NULL; g->twups = NULL; g->totalbytes = sizeof(LG); + g->totalobjs = 1; g->GCdebt = 0; g->lastatomic = 0; setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */ -- cgit v1.2.3-55-g6feb