Browse Source

FFI: Fix address calculation for refs.

Fixes bug introduced in commit 5032e6d8.
Mike Pall 13 years ago
parent
commit
e75561b70e
1 changed files with 10 additions and 8 deletions
  1. 10 8
      src/lj_crecord.c

+ 10 - 8
src/lj_crecord.c

@@ -417,21 +417,23 @@ static TRef crec_ct_tv(jit_State *J, CType *d, TRef dp, TRef sp, cTValue *sval)
     sid = argv2cdata(J, sp, sval)->typeid;
     s = ctype_raw(cts, sid);
     svisnz = cdataptr(cdataV(sval));
-    if (ctype_isref(s->info)) {
-      svisnz = *(void **)svisnz;
-      s = ctype_rawchild(cts, s);
-      sp = emitir(IRT(IR_FLOAD, IRT_PTR), sp, IRFL_CDATA_PTR);
-    }
     if (ctype_isenum(s->info)) s = ctype_child(cts, s);
     t = crec_ct2irt(s);
     if (ctype_isptr(s->info)) {
       sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_PTR);
-      goto doconv;
-    } else if (ctype_isinteger(s->info) && s->size == 8) {
+      if (ctype_isref(s->info)) {
+	svisnz = *(void **)svisnz;
+	s = ctype_rawchild(cts, s);
+	if (ctype_isenum(s->info)) s = ctype_child(cts, s);
+	t = crec_ct2irt(s);
+      } else {
+	goto doconv;
+      }
+    } else if (t == IRT_I64 || t == IRT_U64) {
       sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT64);
       lj_needsplit(J);
       goto doconv;
-    } else if (ctype_isinteger(s->info) && s->size == 4) {
+    } else if (t == IRT_INT || t == IRT_U32) {
       sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT);
       goto doconv;
     } else {