MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / GCTM

Function GCTM

3rd/lua-5.4.3/src/lgc.c:899–924  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

897
898
899static void GCTM (lua_State *L) {
900 global_State *g = G(L);
901 const TValue *tm;
902 TValue v;
903 lua_assert(!g->gcemergency);
904 setgcovalue(L, &v, udata2finalize(g));
905 tm = luaT_gettmbyobj(L, &v, TM_GC);
906 if (!notm(tm)) { /* is there a finalizer? */
907 int status;
908 lu_byte oldah = L->allowhook;
909 int running = g->gcrunning;
910 L->allowhook = 0; /* stop debug hooks during GC metamethod */
911 g->gcrunning = 0; /* avoid GC steps */
912 setobj2s(L, L->top++, tm); /* push finalizer... */
913 setobj2s(L, L->top++, &v); /* ... and its argument */
914 L->ci->callstatus |= CIST_FIN; /* will run a finalizer */
915 status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);
916 L->ci->callstatus &= ~CIST_FIN; /* not running a finalizer anymore */
917 L->allowhook = oldah; /* restore hooks */
918 g->gcrunning = running; /* restore state */
919 if (l_unlikely(status != LUA_OK)) { /* error while running __gc? */
920 luaE_warnerror(L, "__gc metamethod");
921 L->top--; /* pops error object */
922 }
923 }
924}
925
926
927/*

Callers 2

runafewfinalizersFunction · 0.85
callallpendingfinalizersFunction · 0.85

Calls 4

udata2finalizeFunction · 0.85
luaT_gettmbyobjFunction · 0.85
luaD_pcallFunction · 0.85
luaE_warnerrorFunction · 0.85

Tested by

no test coverage detected