From 5141cbc20c43921778ff36be541c15888bee8ee3 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sun, 29 Sep 2024 16:03:37 +0200 Subject: [PATCH] Fix compiliation of getmetatable() for UDTYPE_IO_FILE. Reported by Sergey Bronnikov. #1279 --- src/lj_record.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lj_record.c b/src/lj_record.c index 207327b3..af12e256 100644 --- a/src/lj_record.c +++ b/src/lj_record.c @@ -821,6 +821,7 @@ int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm) } else if (tref_isudata(ix->tab)) { int udtype = udataV(&ix->tabv)->udtype; mt = tabref(udataV(&ix->tabv)->metatable); + mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_UDATA_META); /* The metatables of special userdata objects are treated as immutable. */ if (udtype != UDTYPE_USERDATA) { cTValue *mo; @@ -834,6 +835,8 @@ int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm) } immutable_mt: mo = lj_tab_getstr(mt, mmname_str(J2G(J), mm)); + ix->mt = mix.tab; + ix->mtv = mt; if (!mo || tvisnil(mo)) return 0; /* No metamethod. */ /* Treat metamethod or index table as immutable, too. */ @@ -841,11 +844,8 @@ int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm) lj_trace_err(J, LJ_TRERR_BADTYPE); copyTV(J->L, &ix->mobjv, mo); ix->mobj = lj_ir_kgc(J, gcV(mo), tvisfunc(mo) ? IRT_FUNC : IRT_TAB); - ix->mtv = mt; - ix->mt = TREF_NIL; /* Dummy value for comparison semantics. */ return 1; /* Got metamethod or index table. */ } - mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_UDATA_META); } else { /* Specialize to base metatable. Must flush mcode in lua_setmetatable(). */ mt = tabref(basemt_obj(J2G(J), &ix->tabv));