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

Function luaC_checkfinalizer

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

** if object 'o' has a finalizer, remove it from 'allgc' list (must ** search the list to find it) and link it in 'finobj' list. */

Source from the content-addressed store, hash-verified

1009** search the list to find it) and link it in 'finobj' list.
1010*/
1011void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
1012 global_State *g = G(L);
1013 if (tofinalize(o) || /* obj. is already marked... */
1014 gfasttm(g, mt, TM_GC) == NULL) /* or has no finalizer? */
1015 return; /* nothing to be done */
1016 else { /* move 'o' to 'finobj' list */
1017 GCObject **p;
1018 if (issweepphase(g)) {
1019 makewhite(g, o); /* "sweep" object 'o' */
1020 if (g->sweepgc == &o->next) /* should not remove 'sweepgc' object */
1021 g->sweepgc = sweeptolive(L, g->sweepgc); /* change 'sweepgc' */
1022 }
1023 else
1024 correctpointers(g, o);
1025 /* search for pointer pointing to 'o' */
1026 for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ }
1027 *p = o->next; /* remove 'o' from 'allgc' list */
1028 o->next = g->finobj; /* link it in 'finobj' list */
1029 g->finobj = o;
1030 l_setbit(o->marked, FINALIZEDBIT); /* mark it as such */
1031 }
1032}
1033
1034/* }====================================================== */
1035

Callers 1

lua_setmetatableFunction · 0.85

Calls 2

sweeptoliveFunction · 0.85
correctpointersFunction · 0.85

Tested by

no test coverage detected