summaryrefslogtreecommitdiff
path: root/src/lj_crecord.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_crecord.c')
-rw-r--r--src/lj_crecord.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/lj_crecord.c b/src/lj_crecord.c
index f9220322..9d361a7a 100644
--- a/src/lj_crecord.c
+++ b/src/lj_crecord.c
@@ -862,6 +862,25 @@ again:
862 } 862 }
863} 863}
864 864
865/* Record setting a finalizer. */
866static void crec_finalizer(jit_State *J, TRef trcd, cTValue *fin)
867{
868 TRef trlo = lj_ir_call(J, IRCALL_lj_cdata_setfin, trcd);
869 TRef trhi = emitir(IRT(IR_ADD, IRT_P32), trlo, lj_ir_kint(J, 4));
870 if (LJ_BE) { TRef tmp = trlo; trlo = trhi; trhi = tmp; }
871 if (tvisfunc(fin)) {
872 emitir(IRT(IR_XSTORE, IRT_P32), trlo, lj_ir_kfunc(J, funcV(fin)));
873 emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TFUNC));
874 } else if (tviscdata(fin)) {
875 emitir(IRT(IR_XSTORE, IRT_P32), trlo,
876 lj_ir_kgc(J, obj2gco(cdataV(fin)), IRT_CDATA));
877 emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TCDATA));
878 } else {
879 lj_trace_err(J, LJ_TRERR_BADTYPE);
880 }
881 J->needsnap = 1;
882}
883
865/* Record cdata allocation. */ 884/* Record cdata allocation. */
866static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id) 885static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id)
867{ 886{
@@ -955,22 +974,8 @@ static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id)
955 } 974 }
956 /* Handle __gc metamethod. */ 975 /* Handle __gc metamethod. */
957 fin = lj_ctype_meta(cts, id, MM_gc); 976 fin = lj_ctype_meta(cts, id, MM_gc);
958 if (fin) { 977 if (fin)
959 TRef trlo = lj_ir_call(J, IRCALL_lj_cdata_setfin, trcd); 978 crec_finalizer(J, trcd, fin);
960 TRef trhi = emitir(IRT(IR_ADD, IRT_P32), trlo, lj_ir_kint(J, 4));
961 if (LJ_BE) { TRef tmp = trlo; trlo = trhi; trhi = tmp; }
962 if (tvisfunc(fin)) {
963 emitir(IRT(IR_XSTORE, IRT_P32), trlo, lj_ir_kfunc(J, funcV(fin)));
964 emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TFUNC));
965 } else if (tviscdata(fin)) {
966 emitir(IRT(IR_XSTORE, IRT_P32), trlo,
967 lj_ir_kgc(J, obj2gco(cdataV(fin)), IRT_CDATA));
968 emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TCDATA));
969 } else {
970 lj_trace_err(J, LJ_TRERR_BADTYPE);
971 }
972 J->needsnap = 1;
973 }
974 } 979 }
975} 980}
976 981
@@ -1611,6 +1616,12 @@ void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd)
1611 J->base[0] = J->base[1] = J->base[2] = TREF_NIL; 1616 J->base[0] = J->base[1] = J->base[2] = TREF_NIL;
1612} 1617}
1613 1618
1619void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd)
1620{
1621 argv2cdata(J, J->base[0], &rd->argv[0]);
1622 crec_finalizer(J, J->base[0], &rd->argv[1]);
1623}
1624
1614/* -- Miscellaneous library functions ------------------------------------- */ 1625/* -- Miscellaneous library functions ------------------------------------- */
1615 1626
1616void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd) 1627void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd)