aboutsummaryrefslogtreecommitdiff
path: root/src/lib_ffi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib_ffi.c')
-rw-r--r--src/lib_ffi.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/lib_ffi.c b/src/lib_ffi.c
index e789ad6c..2d942b23 100644
--- a/src/lib_ffi.c
+++ b/src/lib_ffi.c
@@ -29,6 +29,7 @@
29#include "lj_ccall.h" 29#include "lj_ccall.h"
30#include "lj_ccallback.h" 30#include "lj_ccallback.h"
31#include "lj_clib.h" 31#include "lj_clib.h"
32#include "lj_strfmt.h"
32#include "lj_ff.h" 33#include "lj_ff.h"
33#include "lj_lib.h" 34#include "lj_lib.h"
34 35
@@ -317,7 +318,7 @@ LJLIB_CF(ffi_meta___tostring)
317 } 318 }
318 } 319 }
319 } 320 }
320 lj_str_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), p); 321 lj_strfmt_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), p);
321checkgc: 322checkgc:
322 lj_gc_check(L); 323 lj_gc_check(L);
323 return 1; 324 return 1;
@@ -506,7 +507,7 @@ LJLIB_CF(ffi_new) LJLIB_REC(.)
506 if (!(info & CTF_VLA) && ctype_align(info) <= CT_MEMALIGN) 507 if (!(info & CTF_VLA) && ctype_align(info) <= CT_MEMALIGN)
507 cd = lj_cdata_new(cts, id, sz); 508 cd = lj_cdata_new(cts, id, sz);
508 else 509 else
509 cd = lj_cdata_newv(cts, id, sz, ctype_align(info)); 510 cd = lj_cdata_newv(L, id, sz, ctype_align(info));
510 setcdataV(L, o-1, cd); /* Anchor the uninitialized cdata. */ 511 setcdataV(L, o-1, cd); /* Anchor the uninitialized cdata. */
511 lj_cconv_ct_init(cts, ct, sz, cdataptr(cd), 512 lj_cconv_ct_init(cts, ct, sz, cdataptr(cd),
512 o, (MSize)(L->top - o)); /* Initialize cdata. */ 513 o, (MSize)(L->top - o)); /* Initialize cdata. */
@@ -767,19 +768,11 @@ LJLIB_CF(ffi_gc) LJLIB_REC(.)
767 GCcdata *cd = ffi_checkcdata(L, 1); 768 GCcdata *cd = ffi_checkcdata(L, 1);
768 TValue *fin = lj_lib_checkany(L, 2); 769 TValue *fin = lj_lib_checkany(L, 2);
769 CTState *cts = ctype_cts(L); 770 CTState *cts = ctype_cts(L);
770 GCtab *t = cts->finalizer;
771 CType *ct = ctype_raw(cts, cd->ctypeid); 771 CType *ct = ctype_raw(cts, cd->ctypeid);
772 if (!(ctype_isptr(ct->info) || ctype_isstruct(ct->info) || 772 if (!(ctype_isptr(ct->info) || ctype_isstruct(ct->info) ||
773 ctype_isrefarray(ct->info))) 773 ctype_isrefarray(ct->info)))
774 lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE); 774 lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);
775 if (gcref(t->metatable)) { /* Update finalizer table, if still enabled. */ 775 lj_cdata_setfin(L, cd, gcval(fin), itype(fin));
776 copyTV(L, lj_tab_set(L, t, L->base), fin);
777 lj_gc_anybarriert(L, t);
778 if (!tvisnil(fin))
779 cd->marked |= LJ_GC_CDATA_FIN;
780 else
781 cd->marked &= ~LJ_GC_CDATA_FIN;
782 }
783 L->top = L->base+1; /* Pass through the cdata object. */ 776 L->top = L->base+1; /* Pass through the cdata object. */
784 return 1; 777 return 1;
785} 778}