** if object 'o' has a finalizer, remove it from 'allgc' list (must ** search the list to find it) and link it in 'finobj' list. */
| 925 | ** search the list to find it) and link it in 'finobj' list. |
| 926 | */ |
| 927 | void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { |
| 928 | global_State *g = G(L); |
| 929 | if (tofinalize(o) || /* obj. is already marked... */ |
| 930 | gfasttm(g, mt, TM_GC) == NULL) /* or has no finalizer? */ |
| 931 | return; /* nothing to be done */ |
| 932 | else { /* move 'o' to 'finobj' list */ |
| 933 | GCObject **p; |
| 934 | if (issweepphase(g)) { |
| 935 | makewhite(g, o); /* "sweep" object 'o' */ |
| 936 | if (g->sweepgc == &o->next) /* should not remove 'sweepgc' object */ |
| 937 | g->sweepgc = sweeptolive(L, g->sweepgc); /* change 'sweepgc' */ |
| 938 | } |
| 939 | else { /* correct pointers into 'allgc' list, if needed */ |
| 940 | if (o == g->survival) |
| 941 | g->survival = o->next; |
| 942 | if (o == g->old) |
| 943 | g->old = o->next; |
| 944 | if (o == g->reallyold) |
| 945 | g->reallyold = o->next; |
| 946 | } |
| 947 | /* search for pointer pointing to 'o' */ |
| 948 | for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ } |
| 949 | *p = o->next; /* remove 'o' from 'allgc' list */ |
| 950 | o->next = g->finobj; /* link it in 'finobj' list */ |
| 951 | g->finobj = o; |
| 952 | l_setbit(o->marked, FINALIZEDBIT); /* mark it as such */ |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | /* }====================================================== */ |
| 957 |
no test coverage detected