FFI: Fix cdata finalization.

This commit is contained in:
Mike Pall
2011-04-13 21:37:54 +02:00
parent 1fa0cc09b3
commit 31e0774a9e
7 changed files with 43 additions and 23 deletions

View File

@@ -10,6 +10,7 @@
#include "lj_gc.h"
#include "lj_err.h"
#include "lj_str.h"
#include "lj_tab.h"
#include "lj_ctype.h"
#include "lj_cconv.h"
#include "lj_cdata.h"
@@ -74,6 +75,24 @@ void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd)
}
}
TValue * LJ_FASTCALL lj_cdata_setfin(lua_State *L, GCcdata *cd)
{
global_State *g = G(L);
GCtab *t = ctype_ctsG(g)->finalizer;
if (gcref(t->metatable)) {
/* Add cdata to finalizer table, if still enabled. */
TValue *tv, tmp;
setcdataV(L, &tmp, cd);
lj_gc_anybarriert(L, t);
tv = lj_tab_set(L, t, &tmp);
cd->marked |= LJ_GC_CDATA_FIN;
return tv;
} else {
/* Otherwise return dummy TValue. */
return &g->tmptv;
}
}
/* -- C data indexing ----------------------------------------------------- */
/* Index C data by a TValue. Return CType and pointer. */