mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
FFI: Compile ffi.gc().
This commit is contained in:
parent
1c626112a0
commit
0b55e05d06
@ -762,7 +762,7 @@ LJLIB_CF(ffi_metatype)
|
|||||||
|
|
||||||
LJLIB_PUSH(top-7) LJLIB_SET(!) /* Store reference to finalizer table. */
|
LJLIB_PUSH(top-7) LJLIB_SET(!) /* Store reference to finalizer table. */
|
||||||
|
|
||||||
LJLIB_CF(ffi_gc)
|
LJLIB_CF(ffi_gc) LJLIB_REC(.)
|
||||||
{
|
{
|
||||||
GCcdata *cd = ffi_checkcdata(L, 1);
|
GCcdata *cd = ffi_checkcdata(L, 1);
|
||||||
TValue *fin = lj_lib_checkany(L, 2);
|
TValue *fin = lj_lib_checkany(L, 2);
|
||||||
|
@ -862,6 +862,25 @@ again:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Record setting a finalizer. */
|
||||||
|
static void crec_finalizer(jit_State *J, TRef trcd, cTValue *fin)
|
||||||
|
{
|
||||||
|
TRef trlo = lj_ir_call(J, IRCALL_lj_cdata_setfin, trcd);
|
||||||
|
TRef trhi = emitir(IRT(IR_ADD, IRT_P32), trlo, lj_ir_kint(J, 4));
|
||||||
|
if (LJ_BE) { TRef tmp = trlo; trlo = trhi; trhi = tmp; }
|
||||||
|
if (tvisfunc(fin)) {
|
||||||
|
emitir(IRT(IR_XSTORE, IRT_P32), trlo, lj_ir_kfunc(J, funcV(fin)));
|
||||||
|
emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TFUNC));
|
||||||
|
} else if (tviscdata(fin)) {
|
||||||
|
emitir(IRT(IR_XSTORE, IRT_P32), trlo,
|
||||||
|
lj_ir_kgc(J, obj2gco(cdataV(fin)), IRT_CDATA));
|
||||||
|
emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TCDATA));
|
||||||
|
} else {
|
||||||
|
lj_trace_err(J, LJ_TRERR_BADTYPE);
|
||||||
|
}
|
||||||
|
J->needsnap = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Record cdata allocation. */
|
/* Record cdata allocation. */
|
||||||
static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id)
|
static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id)
|
||||||
{
|
{
|
||||||
@ -955,22 +974,8 @@ static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id)
|
|||||||
}
|
}
|
||||||
/* Handle __gc metamethod. */
|
/* Handle __gc metamethod. */
|
||||||
fin = lj_ctype_meta(cts, id, MM_gc);
|
fin = lj_ctype_meta(cts, id, MM_gc);
|
||||||
if (fin) {
|
if (fin)
|
||||||
TRef trlo = lj_ir_call(J, IRCALL_lj_cdata_setfin, trcd);
|
crec_finalizer(J, trcd, fin);
|
||||||
TRef trhi = emitir(IRT(IR_ADD, IRT_P32), trlo, lj_ir_kint(J, 4));
|
|
||||||
if (LJ_BE) { TRef tmp = trlo; trlo = trhi; trhi = tmp; }
|
|
||||||
if (tvisfunc(fin)) {
|
|
||||||
emitir(IRT(IR_XSTORE, IRT_P32), trlo, lj_ir_kfunc(J, funcV(fin)));
|
|
||||||
emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TFUNC));
|
|
||||||
} else if (tviscdata(fin)) {
|
|
||||||
emitir(IRT(IR_XSTORE, IRT_P32), trlo,
|
|
||||||
lj_ir_kgc(J, obj2gco(cdataV(fin)), IRT_CDATA));
|
|
||||||
emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TCDATA));
|
|
||||||
} else {
|
|
||||||
lj_trace_err(J, LJ_TRERR_BADTYPE);
|
|
||||||
}
|
|
||||||
J->needsnap = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1611,6 +1616,12 @@ void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd)
|
|||||||
J->base[0] = J->base[1] = J->base[2] = TREF_NIL;
|
J->base[0] = J->base[1] = J->base[2] = TREF_NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd)
|
||||||
|
{
|
||||||
|
argv2cdata(J, J->base[0], &rd->argv[0]);
|
||||||
|
crec_finalizer(J, J->base[0], &rd->argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
/* -- Miscellaneous library functions ------------------------------------- */
|
/* -- Miscellaneous library functions ------------------------------------- */
|
||||||
|
|
||||||
void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd)
|
void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd)
|
||||||
|
@ -24,6 +24,7 @@ LJ_FUNC void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd);
|
|||||||
LJ_FUNC void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd);
|
LJ_FUNC void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd);
|
||||||
LJ_FUNC void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd);
|
LJ_FUNC void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd);
|
||||||
LJ_FUNC void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd);
|
LJ_FUNC void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd);
|
||||||
|
LJ_FUNC void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd);
|
||||||
LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd);
|
LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user