** if object 'o' has a finalizer, remove it from 'allgc' list (must ** search the list to find it) and link it in 'finobj' list. */
| 1017 | ** search the list to find it) and link it in 'finobj' list. |
| 1018 | */ |
| 1019 | void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { |
| 1020 | global_State *g = G(L); |
| 1021 | if (tofinalize(o) || /* obj. is already marked... */ |
| 1022 | gfasttm(g, mt, TM_GC) == NULL || /* or has no finalizer... */ |
| 1023 | (g->gcstp & GCSTPCLS)) /* or closing state? */ |
| 1024 | return; /* nothing to be done */ |
| 1025 | else { /* move 'o' to 'finobj' list */ |
| 1026 | GCObject **p; |
| 1027 | if (issweepphase(g)) { |
| 1028 | makewhite(g, o); /* "sweep" object 'o' */ |
| 1029 | if (g->sweepgc == &o->next) /* should not remove 'sweepgc' object */ |
| 1030 | g->sweepgc = sweeptolive(L, g->sweepgc); /* change 'sweepgc' */ |
| 1031 | } |
| 1032 | else |
| 1033 | correctpointers(g, o); |
| 1034 | /* search for pointer pointing to 'o' */ |
| 1035 | for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ } |
| 1036 | *p = o->next; /* remove 'o' from 'allgc' list */ |
| 1037 | o->next = g->finobj; /* link it in 'finobj' list */ |
| 1038 | g->finobj = o; |
| 1039 | l_setbit(o->marked, FINALIZEDBIT); /* mark it as such */ |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | /* }====================================================== */ |
| 1044 |
no test coverage detected