From 3ab9f5a18da06b06ebf1e4487997c25e32210dfe Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Wed, 8 Mar 2017 22:03:17 +0100 Subject: Remove internal __mode = "K" and replace with safe check. --- src/lib_ffi.c | 2 +- src/lj_gc.c | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 6a93ce97..f2f2ede4 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c @@ -811,7 +811,7 @@ static GCtab *ffi_finalizer(lua_State *L) settabV(L, L->top++, t); setgcref(t->metatable, obj2gco(t)); setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")), - lj_str_newlit(L, "K")); + lj_str_newlit(L, "k")); t->nomm = (uint8_t)(~(1u< 0) { /* Weak tables are cleared in the atomic phase. */ - t->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak); - setgcrefr(t->gclist, g->gc.weak); - setgcref(g->gc.weak, obj2gco(t)); + if (weak) { /* Weak tables are cleared in the atomic phase. */ +#if LJ_HASFFI + CTState *cts = ctype_ctsG(g); + if (cts && cts->finalizer == t) { + weak = (int)(~0u & ~LJ_GC_WEAKVAL); + } else +#endif + { + t->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak); + setgcrefr(t->gclist, g->gc.weak); + setgcref(g->gc.weak, obj2gco(t)); + } } } if (weak == LJ_GC_WEAK) /* Nothing to mark if both keys/values are weak. */ -- cgit v1.2.3-55-g6feb