From f80b349d5490aa289b2925d297f3f3c618977570 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 27 Nov 2025 17:45:17 +0100 Subject: Unify Lua number to FFI integer conversions. Phew. #1411 --- src/lj_bcwrite.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/lj_bcwrite.c') diff --git a/src/lj_bcwrite.c b/src/lj_bcwrite.c index ec6f13c8..cd7ae942 100644 --- a/src/lj_bcwrite.c +++ b/src/lj_bcwrite.c @@ -59,9 +59,9 @@ static void bcwrite_ktabk(BCWriteCtx *ctx, cTValue *o, int narrow) p = lj_strfmt_wuleb128(p, intV(o)); } else if (tvisnum(o)) { if (!LJ_DUALNUM && narrow) { /* Narrow number constants to integers. */ - lua_Number num = numV(o); - int32_t k = lj_num2int(num); - if (num == (lua_Number)k) { /* -0 is never a constant. */ + int64_t i64; + int32_t k; + if (lj_num2int_check(numV(o), i64, k)) { /* -0 is never a constant. */ *p++ = BCDUMP_KTAB_INT; p = lj_strfmt_wuleb128(p, k); ctx->sb.w = p; @@ -270,9 +270,8 @@ static void bcwrite_knum(BCWriteCtx *ctx, GCproto *pt) /* Write a 33 bit ULEB128 for the int (lsb=0) or loword (lsb=1). */ if (!LJ_DUALNUM && o->u32.hi != LJ_KEYINDEX) { /* Narrow number constants to integers. */ - lua_Number num = numV(o); - k = lj_num2int(num); - if (num == (lua_Number)k) { /* -0 is never a constant. */ + int64_t i64; + if (lj_num2int_check(numV(o), i64, k)) { /* -0 is never a constant. */ save_int: p = lj_strfmt_wuleb128(p, 2*(uint32_t)k | ((uint32_t)k&0x80000000u)); if (k < 0) -- cgit v1.2.3-55-g6feb