static void close_state (lua_State *L) { global_State globalState; lua_State luaState; luaF_close(L, L->stack); /* close all upvalues for this thread */ luaState.l_G = &globalState; globalState.reallocFunc = G(L)->reallocFunc; globalState.freeFunc = G(L)->freeFunc; globalState.memData = G(L)->memData; if (G(L)) { /* close global state */ luaC_sweep(L, 1); /* collect all elements */ #if !LUA_REFCOUNT lua_assert(G(L)->rootgc == NULL); lua_assert(G(L)->rootudata == NULL); #endif LUA_REFCOUNT luaS_freeall(L); luaZ_freebuffer(L, &G(L)->buff); } freestack(L, L); if (G(L)) { //jj This check doesn't work anymore, because LuaState variables are allocated through the //jj memory interface, too. //jj lua_assert(G(L)->nblocks == sizeof(lua_State) + sizeof(global_State)); luaM_freelem(&luaState, G(L)); } freestate(&luaState, L); }
void lua_close() { TaggedString *alludata = luaS_collectudata(); GCthreshold = MAX_INT; // to avoid GC during GC luaC_hashcallIM((Hash *)roottable.next); // GC t.methods for tables luaC_strcallIM(alludata); // GC tag methods for userdata luaD_gcIM(&luaO_nilobject); // GC tag method for nil (signal end of GC) luaH_free((Hash *)roottable.next); luaF_freeproto((TProtoFunc *)rootproto.next); luaF_freeclosure((Closure *)rootcl.next); luaS_free(alludata); luaS_freeall(); luaM_free(IMtable); luaM_free(refArray); luaM_free(Mbuffer); LState *tmpState, *state; for (state = lua_rootState; state != nullptr;) { tmpState = state->next; lua_statedeinit(state); luaM_free(state); state = tmpState; } Mbuffer = nullptr; IMtable = nullptr; refArray = nullptr; lua_rootState = lua_state = nullptr; #ifdef LUA_DEBUG printf("total de blocos: %ld\n", numblocks); printf("total de memoria: %ld\n", totalmem); #endif }
static void close_state (lua_State *L) { luaF_close(L, L->stack); /* close all upvalues for this thread */ if (G(L)) { /* close global state */ luaC_sweep(L, 1); /* collect all elements */ lua_assert(G(L)->rootgc == NULL); lua_assert(G(L)->rootudata == NULL); luaS_freeall(L); luaZ_freebuffer(L, &G(L)->buff); } freestack(L, L); if (G(L)) { lua_assert(G(L)->nblocks == sizeof(lua_State) + sizeof(global_State)); luaM_freelem(NULL, G(L)); } freestate(NULL, L); }
LUA_API void lua_close (lua_State *L) { LUA_ASSERT(L != lua_state || lua_gettop(L) == 0, "garbage in C stack"); luaC_collect(L, 1); /* collect all elements */ LUA_ASSERT(L->rootproto == NULL, "list should be empty"); LUA_ASSERT(L->rootcl == NULL, "list should be empty"); LUA_ASSERT(L->roottable == NULL, "list should be empty"); luaS_freeall(L); if (L->stack) L->nblocks -= (L->stack_last - L->stack + 1)*sizeof(TObject); luaM_free(L, L->stack); L->nblocks -= (L->last_tag+1)*sizeof(struct TM); luaM_free(L, L->TMtable); L->nblocks -= (L->refSize)*sizeof(struct Ref); luaM_free(L, L->refArray); L->nblocks -= (L->Mbuffsize)*sizeof(char); luaM_free(L, L->Mbuffer); LUA_ASSERT(L->nblocks == sizeof(lua_State), "wrong count for nblocks"); luaM_free(L, L); LUA_ASSERT(L != lua_state || memdebug_numblocks == 0, "memory leak!"); LUA_ASSERT(L != lua_state || memdebug_total == 0,"memory leak!"); }
void lua_close (void) { TaggedString *alludata = luaS_collectudata(); L->GCthreshold = MAX_INT; /* to avoid GC during GC */ luaC_hashcallIM((Hash *)L->roottable.next); /* GC t.methods for tables */ luaC_strcallIM(alludata); /* GC tag methods for userdata */ luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */ luaH_free((Hash *)L->roottable.next); luaF_freeproto((TProtoFunc *)L->rootproto.next); luaF_freeclosure((Closure *)L->rootcl.next); luaS_free(alludata); luaS_freeall(); luaM_free(L->stack.stack); luaM_free(L->IMtable); luaM_free(L->refArray); luaM_free(L->Mbuffer); luaM_free(L->Cblocks); luaM_free(L); L = NULL; #ifdef DEBUG printf("total de blocos: %ld\n", numblocks); printf("total de memoria: %ld\n", totalmem); #endif }