** if object 'o' has a finalizer, remove it from 'allgc' list (must ** search the list to find it) and link it in 'finobj' list. */
| 900 | ** search the list to find it) and link it in 'finobj' list. |
| 901 | */ |
| 902 | void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { |
| 903 | global_State *g = G(L); |
| 904 | if (tofinalize(o) || /* obj. is already marked... */ |
| 905 | gfasttm(g, mt, TM_GC) == NULL) /* or has no finalizer? */ |
| 906 | return; /* nothing to be done */ |
| 907 | else { /* move 'o' to 'finobj' list */ |
| 908 | GCObject **p; |
| 909 | if (issweepphase(g)) { |
| 910 | makewhite(g, o); /* "sweep" object 'o' */ |
| 911 | if (g->sweepgc == &o->next) /* should not remove 'sweepgc' object */ |
| 912 | g->sweepgc = sweeptolive(L, g->sweepgc); /* change 'sweepgc' */ |
| 913 | } |
| 914 | /* search for pointer pointing to 'o' */ |
| 915 | for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ } |
| 916 | *p = o->next; /* remove 'o' from 'allgc' list */ |
| 917 | o->next = g->finobj; /* link it in 'finobj' list */ |
| 918 | g->finobj = o; |
| 919 | l_setbit(o->marked, FINALIZEDBIT); /* mark it as such */ |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | /* }====================================================== */ |
| 924 |
no test coverage detected