Skip to content

Commit 3ab9f5a

Browse files
author
Mike Pall
committed
Remove internal __mode = "K" and replace with safe check.
1 parent eef77a6 commit 3ab9f5a

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/lib_ffi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ static GCtab *ffi_finalizer(lua_State *L)
811811
settabV(L, L->top++, t);
812812
setgcref(t->metatable, obj2gco(t));
813813
setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")),
814-
lj_str_newlit(L, "K"));
814+
lj_str_newlit(L, "k"));
815815
t->nomm = (uint8_t)(~(1u<<MM_mode));
816816
return t;
817817
}

src/lj_gc.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,19 @@ static int gc_traverse_tab(global_State *g, GCtab *t)
168168
while ((c = *modestr++)) {
169169
if (c == 'k') weak |= LJ_GC_WEAKKEY;
170170
else if (c == 'v') weak |= LJ_GC_WEAKVAL;
171-
else if (c == 'K') weak = (int)(~0u & ~LJ_GC_WEAKVAL);
172171
}
173-
if (weak > 0) { /* Weak tables are cleared in the atomic phase. */
174-
t->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak);
175-
setgcrefr(t->gclist, g->gc.weak);
176-
setgcref(g->gc.weak, obj2gco(t));
172+
if (weak) { /* Weak tables are cleared in the atomic phase. */
173+
#if LJ_HASFFI
174+
CTState *cts = ctype_ctsG(g);
175+
if (cts && cts->finalizer == t) {
176+
weak = (int)(~0u & ~LJ_GC_WEAKVAL);
177+
} else
178+
#endif
179+
{
180+
t->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak);
181+
setgcrefr(t->gclist, g->gc.weak);
182+
setgcref(g->gc.weak, obj2gco(t));
183+
}
177184
}
178185
}
179186
if (weak == LJ_GC_WEAK) /* Nothing to mark if both keys/values are weak. */

0 commit comments

Comments
 (0)