FFI: Fix __gc for VLA/VLS cdata objects.

This commit is contained in:
Mike Pall 2011-05-23 02:43:36 +02:00
parent 288085afbe
commit 7b21a660a8
3 changed files with 8 additions and 5 deletions

View File

@ -55,7 +55,8 @@ void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd)
{ {
if (LJ_UNLIKELY(cd->marked & LJ_GC_CDATA_FIN)) { if (LJ_UNLIKELY(cd->marked & LJ_GC_CDATA_FIN)) {
GCobj *root; GCobj *root;
cd->marked = curwhite(g) | LJ_GC_FINALIZED; makewhite(g, obj2gco(cd));
obj2gco(cd)->gch.marked |= LJ_GC_FINALIZED;
if ((root = gcref(g->gc.mmudata)) != NULL) { if ((root = gcref(g->gc.mmudata)) != NULL) {
setgcrefr(cd->nextgc, root->gch.nextgc); setgcrefr(cd->nextgc, root->gch.nextgc);
setgcref(root->gch.nextgc, obj2gco(cd)); setgcref(root->gch.nextgc, obj2gco(cd));

View File

@ -34,8 +34,6 @@
/* Macros to set GCobj colors and flags. */ /* Macros to set GCobj colors and flags. */
#define white2gray(x) ((x)->gch.marked &= (uint8_t)~LJ_GC_WHITES) #define white2gray(x) ((x)->gch.marked &= (uint8_t)~LJ_GC_WHITES)
#define gray2black(x) ((x)->gch.marked |= LJ_GC_BLACK) #define gray2black(x) ((x)->gch.marked |= LJ_GC_BLACK)
#define makewhite(g, x) \
((x)->gch.marked = ((x)->gch.marked & (uint8_t)~LJ_GC_COLORS) | curwhite(g))
#define isfinalized(u) ((u)->marked & LJ_GC_FINALIZED) #define isfinalized(u) ((u)->marked & LJ_GC_FINALIZED)
#define markfinalized(u) ((u)->marked |= LJ_GC_FINALIZED) #define markfinalized(u) ((u)->marked |= LJ_GC_FINALIZED)
@ -500,7 +498,8 @@ static void gc_finalize(lua_State *L)
/* Add cdata back to the GC list and make it white. */ /* Add cdata back to the GC list and make it white. */
setgcrefr(o->gch.nextgc, g->gc.root); setgcrefr(o->gch.nextgc, g->gc.root);
setgcref(g->gc.root, o); setgcref(g->gc.root, o);
o->gch.marked = curwhite(g); makewhite(g, o);
o->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN;
/* Resolve finalizer. */ /* Resolve finalizer. */
setcdataV(L, &tmp, gco2cd(o)); setcdataV(L, &tmp, gco2cd(o));
tv = lj_tab_set(L, ctype_ctsG(g)->finalizer, &tmp); tv = lj_tab_set(L, ctype_ctsG(g)->finalizer, &tmp);
@ -544,7 +543,8 @@ void lj_gc_finalize_cdata(lua_State *L)
if (!tvisnil(&node[i].val) && tviscdata(&node[i].key)) { if (!tvisnil(&node[i].val) && tviscdata(&node[i].key)) {
GCobj *o = gcV(&node[i].key); GCobj *o = gcV(&node[i].key);
TValue tmp; TValue tmp;
o->gch.marked = curwhite(g); makewhite(g, o);
o->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN;
copyTV(L, &tmp, &node[i].val); copyTV(L, &tmp, &node[i].val);
setnilV(&node[i].val); setnilV(&node[i].val);
gc_call_finalizer(g, L, &tmp, o); gc_call_finalizer(g, L, &tmp, o);

View File

@ -38,6 +38,8 @@ enum {
#define curwhite(g) ((g)->gc.currentwhite & LJ_GC_WHITES) #define curwhite(g) ((g)->gc.currentwhite & LJ_GC_WHITES)
#define newwhite(g, x) (obj2gco(x)->gch.marked = (uint8_t)curwhite(g)) #define newwhite(g, x) (obj2gco(x)->gch.marked = (uint8_t)curwhite(g))
#define makewhite(g, x) \
((x)->gch.marked = ((x)->gch.marked & (uint8_t)~LJ_GC_COLORS) | curwhite(g))
#define flipwhite(x) ((x)->gch.marked ^= LJ_GC_WHITES) #define flipwhite(x) ((x)->gch.marked ^= LJ_GC_WHITES)
#define black2gray(x) ((x)->gch.marked &= (uint8_t)~LJ_GC_BLACK) #define black2gray(x) ((x)->gch.marked &= (uint8_t)~LJ_GC_BLACK)
#define fixstring(s) ((s)->marked |= LJ_GC_FIXED) #define fixstring(s) ((s)->marked |= LJ_GC_FIXED)