FFI: Always resolve metamethods for pointers to structs.

This commit is contained in:
Mike Pall 2012-09-08 21:03:40 +02:00
parent 0648fd47cb
commit 21cea85d92
2 changed files with 24 additions and 10 deletions

View File

@ -218,10 +218,18 @@ static int carith_int64(lua_State *L, CTState *cts, CDArith *ca, MMS mm)
static int lj_carith_meta(lua_State *L, CTState *cts, CDArith *ca, MMS mm)
{
cTValue *tv = NULL;
if (tviscdata(L->base))
tv = lj_ctype_meta(cts, cdataV(L->base)->ctypeid, mm);
if (!tv && L->base+1 < L->top && tviscdata(L->base+1))
tv = lj_ctype_meta(cts, cdataV(L->base+1)->ctypeid, mm);
if (tviscdata(L->base)) {
CTypeID id = cdataV(L->base)->ctypeid;
CType *ct = ctype_raw(cts, id);
if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);
tv = lj_ctype_meta(cts, id, mm);
}
if (!tv && L->base+1 < L->top && tviscdata(L->base+1)) {
CTypeID id = cdataV(L->base+1)->ctypeid;
CType *ct = ctype_raw(cts, id);
if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);
tv = lj_ctype_meta(cts, id, mm);
}
if (!tv) {
const char *repr[2];
int i, isenum = -1, isstr = -1;

View File

@ -1081,12 +1081,18 @@ static void crec_arith_meta(jit_State *J, CTState *cts, RecordFFData *rd)
{
cTValue *tv = NULL;
if (J->base[0]) {
if (tviscdata(&rd->argv[0]))
tv = lj_ctype_meta(cts, argv2cdata(J, J->base[0], &rd->argv[0])->ctypeid,
(MMS)rd->data);
if (!tv && J->base[1] && tviscdata(&rd->argv[1]))
tv = lj_ctype_meta(cts, argv2cdata(J, J->base[1], &rd->argv[1])->ctypeid,
(MMS)rd->data);
if (tviscdata(&rd->argv[0])) {
CTypeID id = argv2cdata(J, J->base[0], &rd->argv[0])->ctypeid;
CType *ct = ctype_raw(cts, id);
if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);
tv = lj_ctype_meta(cts, id, (MMS)rd->data);
}
if (!tv && J->base[1] && tviscdata(&rd->argv[1])) {
CTypeID id = argv2cdata(J, J->base[1], &rd->argv[1])->ctypeid;
CType *ct = ctype_raw(cts, id);
if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);
tv = lj_ctype_meta(cts, id, (MMS)rd->data);
}
}
if (tv) {
if (tvisfunc(tv)) {