FFI: Turn FFI finalizer table into a proper GC root.

Reported by Sergey Bronnikov. #1168
This commit is contained in:
Mike Pall
2024-04-19 01:33:19 +02:00
parent 7110b93567
commit f5affaa6c4
7 changed files with 39 additions and 44 deletions

View File

@@ -643,6 +643,18 @@ CTState *lj_ctype_init(lua_State *L)
return cts;
}
/* Create special weak-keyed finalizer table. */
void lj_ctype_initfin(lua_State *L)
{
/* NOBARRIER: The table is new (marked white). */
GCtab *t = lj_tab_new(L, 0, 1);
setgcref(t->metatable, obj2gco(t));
setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")),
lj_str_newlit(L, "k"));
t->nomm = (uint8_t)(~(1u<<MM_mode));
setgcref(G(L)->gcroot[GCROOT_FFI_FIN], obj2gco(t));
}
/* Free C type table and state. */
void lj_ctype_freestate(global_State *g)
{