/* if object 'o' has a finalizer, remove it from 'allgc' list (must search the list to find it) and link it in 'finobj' list.  */
void luaC_checkfinalizer(lua_State *L, GCObject *o, Table *mt)
/* if object 'o' has a finalizer, remove it from 'allgc' list (must search the list to find it) and link it in 'finobj' list.  */
void luaC_checkfinalizer(lua_State *L, GCObject *o, Table *mt)
{
    GCObject **p;
    if (issweepphase(g)) {
      makewhite(g, o);
      if (g->sweepgc == &o->next)
        g->sweepgc = sweeptolive(L, g->sweepgc);
    }
    for (p = &g->allgc; *p != o; p = &(*p)->next) { }
    *p = o->next;
    o->next = g->finobj;
    g->finobj = o;
    l_setbit(o->marked, FINALIZEDBIT);
  }
}