From fa2572da6c45a6dc18cec8cf9ecc80869b6ac04e Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 29 May 2012 12:08:21 +0200 Subject: FFI: Convert io.* file handle to FILE * pointer (but as a void *). --- src/lj_cconv.c | 5 ++++- src/lj_crecord.c | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lj_cconv.c b/src/lj_cconv.c index 240a8d10..b09c0abe 100644 --- a/src/lj_cconv.c +++ b/src/lj_cconv.c @@ -603,7 +603,10 @@ void lj_cconv_ct_tv(CTState *cts, CType *d, tmpptr = (void *)0; flags |= CCF_FROMTV; } else if (tvisudata(o)) { - tmpptr = uddata(udataV(o)); + GCudata *ud = udataV(o); + tmpptr = uddata(ud); + if (ud->udtype == UDTYPE_IO_FILE) + tmpptr = *(void **)tmpptr; } else if (tvislightud(o)) { tmpptr = lightudV(o); } else if (tvisfunc(o)) { diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 74d62d6c..268800e4 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c @@ -385,7 +385,14 @@ static TRef crec_ct_tv(jit_State *J, CType *d, TRef dp, TRef sp, cTValue *sval) } else if (tref_isnil(sp)) { sp = lj_ir_kptr(J, NULL); } else if (tref_isudata(sp)) { - sp = emitir(IRT(IR_ADD, IRT_P32), sp, lj_ir_kint(J, sizeof(GCudata))); + GCudata *ud = udataV(sval); + if (ud->udtype == UDTYPE_IO_FILE) { + TRef tr = emitir(IRT(IR_FLOAD, IRT_U8), sp, IRFL_UDATA_UDTYPE); + emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, UDTYPE_IO_FILE)); + sp = emitir(IRT(IR_FLOAD, IRT_PTR), sp, IRFL_UDATA_FILE); + } else { + sp = emitir(IRT(IR_ADD, IRT_P32), sp, lj_ir_kint(J, sizeof(GCudata))); + } } else if (tref_isstr(sp)) { if (ctype_isenum(d->info)) { /* Match string against enum constant. */ GCstr *str = strV(sval); -- cgit v1.2.3-55-g6feb