예제 #1
0
        /*
        ** if object 'o' has a finalizer, remove it from 'allgc' list (must
        ** search the list to find it) and link it in 'finobj' list.
        */
        public static void luaC_checkfinalizer(lua_State L, GCObject o, Table mt)
        {
            global_State g = G(L);

            if (testbit(gch(o).marked, SEPARATED) || /* obj. is already separated... */
                isfinalized(o) ||                    /* ... or is finalized... */
                gfasttm(g, mt, TMS.TM_GC) == null)   /* or has no finalizer? */
            {
                return;                              /* nothing to be done */
            }
            else                                     /* move 'o' to 'finobj' list */
            {
                GCObjectRef p;
                for (p = new AllGCRef(g); p.get() != o; p = new NextRef(gch(p.get())))
                {
                    ;
                }
                p.set(gch(o).next);                     /* remove 'o' from root list */
                gch(o).next = g.finobj;                 /* link it in list 'finobj' */
                g.finobj    = o;
                l_setbit(ref gch(o).marked, SEPARATED); /* mark it as such */
                resetoldbit(o);                         /* see MOVE OLD rule */
            }
        }
예제 #2
0
        /*
        ** if userdata 'u' has a finalizer, remove it from 'allgc' list (must
        ** search the list to find it) and link it in 'udgc' list.
        */
        public static void luaC_checkfinalizer(lua_State L, Udata u)
        {
            global_State g = G(L);

            if (testbit(u.uv.marked, SEPARATED) ||             /* userdata is already separated... */
                isfinalized(u.uv) ||                           /* ... or is finalized... */
                gfasttm(g, u.uv.metatable, TMS.TM_GC) == null) /* or has no finalization? */
            {
                return;                                        /* nothing to be done */
            }
            else                                               /* move 'u' to 'udgc' list */
            {
                GCObjectRef p;
                for (p = new AllGCRef(g); p.get() != obj2gco(u); p = new NextRef(gch(p.get())))
                {
                    ;
                }
                p.set(u.uv.next);                     /* remove 'u' from root list */
                u.uv.next = g.udgc;                   /* link it in list 'udgc' */
                g.udgc    = obj2gco(u);
                l_setbit(ref u.uv.marked, SEPARATED); /* mark it as such */
                resetoldbit(obj2gco(u));              /* see MOVE OLD rule */
            }
        }