From d001d7b7ce0126558e4b442aa1d0cd88fee43570 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sat, 23 Jul 2011 16:29:47 +0200 Subject: [PATCH] FFI: Treat function ctypes like pointers in comparisons. --- src/lj_carith.c | 7 ++++++- src/lj_crecord.c | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lj_carith.c b/src/lj_carith.c index 8f644d83..b0f4c65a 100644 --- a/src/lj_carith.c +++ b/src/lj_carith.c @@ -35,11 +35,16 @@ static int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca) for (i = 0; i < 2; i++, o++) { if (tviscdata(o)) { GCcdata *cd = cdataV(o); - CType *ct = ctype_raw(cts, (CTypeID)cd->typeid); + CTypeID id = (CTypeID)cd->typeid; + CType *ct = ctype_raw(cts, id); uint8_t *p = (uint8_t *)cdataptr(cd); if (ctype_isptr(ct->info)) { p = (uint8_t *)cdata_getptr(p, ct->size); if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct); + } else if (ctype_isfunc(ct->info)) { + p = (uint8_t *)*(void **)p; + ct = ctype_get(cts, + lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR)); } ca->ct[i] = ct; ca->p[i] = p; diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 743137de..180f255c 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c @@ -969,6 +969,10 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_INT64); lj_needsplit(J); goto ok; + } else if (ctype_isfunc(ct->info)) { + tr = emitir(IRT(IR_FLOAD, IRT_PTR), tr, IRFL_CDATA_PTR); + ct = ctype_get(cts, + lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR)); } else { tr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCcdata))); } -- 2.11.4.GIT