diff options
| author | Mike Pall <mike> | 2025-11-27 17:45:17 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2025-11-27 17:45:17 +0100 |
| commit | f80b349d5490aa289b2925d297f3f3c618977570 (patch) | |
| tree | 8d8fb0d2beb3e863592139d603ada63e5aa6ce77 /src/lj_record.c | |
| parent | 3215838aa744d148e79a8ea0bd7c014e984302cb (diff) | |
| download | luajit-f80b349d5490aa289b2925d297f3f3c618977570.tar.gz luajit-f80b349d5490aa289b2925d297f3f3c618977570.tar.bz2 luajit-f80b349d5490aa289b2925d297f3f3c618977570.zip | |
Unify Lua number to FFI integer conversions.
Phew. #1411
Diffstat (limited to 'src/lj_record.c')
| -rw-r--r-- | src/lj_record.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/lj_record.c b/src/lj_record.c index 6543f274..536d7171 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
| @@ -351,9 +351,14 @@ static TRef find_kinit(jit_State *J, const BCIns *endpc, BCReg slot, IRType t) | |||
| 351 | } else { | 351 | } else { |
| 352 | cTValue *tv = proto_knumtv(J->pt, bc_d(ins)); | 352 | cTValue *tv = proto_knumtv(J->pt, bc_d(ins)); |
| 353 | if (t == IRT_INT) { | 353 | if (t == IRT_INT) { |
| 354 | int32_t k = numberVint(tv); | 354 | if (tvisint(tv)) { |
| 355 | if (tvisint(tv) || numV(tv) == (lua_Number)k) /* -0 is ok here. */ | 355 | return lj_ir_kint(J, intV(tv)); |
| 356 | return lj_ir_kint(J, k); | 356 | } else { |
| 357 | int64_t i64; | ||
| 358 | int32_t k; | ||
| 359 | if (lj_num2int_check(numV(tv), i64, k)) /* -0 is ok here. */ | ||
| 360 | return lj_ir_kint(J, k); | ||
| 361 | } | ||
| 357 | return 0; /* Type mismatch. */ | 362 | return 0; /* Type mismatch. */ |
| 358 | } else { | 363 | } else { |
| 359 | return lj_ir_knum(J, numberVnum(tv)); | 364 | return lj_ir_knum(J, numberVnum(tv)); |
| @@ -1426,9 +1431,13 @@ static TRef rec_idx_key(jit_State *J, RecordIndex *ix, IRRef *rbref, | |||
| 1426 | /* Integer keys are looked up in the array part first. */ | 1431 | /* Integer keys are looked up in the array part first. */ |
| 1427 | key = ix->key; | 1432 | key = ix->key; |
| 1428 | if (tref_isnumber(key)) { | 1433 | if (tref_isnumber(key)) { |
| 1429 | int32_t k = numberVint(&ix->keyv); | 1434 | int32_t k; |
| 1430 | if (!tvisint(&ix->keyv) && numV(&ix->keyv) != (lua_Number)k) | 1435 | if (tvisint(&ix->keyv)) { |
| 1431 | k = LJ_MAX_ASIZE; | 1436 | k = intV(&ix->keyv); |
| 1437 | } else { | ||
| 1438 | int64_t i64; | ||
| 1439 | if (!lj_num2int_check(numV(&ix->keyv), i64, k)) k = LJ_MAX_ASIZE; | ||
| 1440 | } | ||
| 1432 | if ((MSize)k < LJ_MAX_ASIZE) { /* Potential array key? */ | 1441 | if ((MSize)k < LJ_MAX_ASIZE) { /* Potential array key? */ |
| 1433 | TRef ikey = lj_opt_narrow_index(J, key); | 1442 | TRef ikey = lj_opt_narrow_index(J, key); |
| 1434 | TRef asizeref = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_ASIZE); | 1443 | TRef asizeref = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_ASIZE); |
