diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lj_carith.c | 5 | ||||
| -rw-r--r-- | src/lj_ccall.c | 2 | ||||
| -rw-r--r-- | src/lj_cconv.c | 37 | ||||
| -rw-r--r-- | src/lj_cdata.c | 11 | ||||
| -rw-r--r-- | src/lj_clib.c | 4 |
5 files changed, 42 insertions, 17 deletions
diff --git a/src/lj_carith.c b/src/lj_carith.c index f1435e1e..a59665d8 100644 --- a/src/lj_carith.c +++ b/src/lj_carith.c | |||
| @@ -41,6 +41,9 @@ static int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca) | |||
| 41 | } | 41 | } |
| 42 | ca->ct[i] = ct; | 42 | ca->ct[i] = ct; |
| 43 | ca->p[i] = p; | 43 | ca->p[i] = p; |
| 44 | } else if (tvisint(o)) { | ||
| 45 | ca->ct[i] = ctype_get(cts, CTID_INT32); | ||
| 46 | ca->p[i] = (uint8_t *)&o->i; | ||
| 44 | } else if (tvisnum(o)) { | 47 | } else if (tvisnum(o)) { |
| 45 | ca->ct[i] = ctype_get(cts, CTID_DOUBLE); | 48 | ca->ct[i] = ctype_get(cts, CTID_DOUBLE); |
| 46 | ca->p[i] = (uint8_t *)&o->n; | 49 | ca->p[i] = (uint8_t *)&o->n; |
| @@ -84,7 +87,7 @@ static int carith_ptr(lua_State *L, CTState *cts, CDArith *ca, MMS mm) | |||
| 84 | /* All valid pointer differences on x64 are in (-2^47, +2^47), | 87 | /* All valid pointer differences on x64 are in (-2^47, +2^47), |
| 85 | ** which fits into a double without loss of precision. | 88 | ** which fits into a double without loss of precision. |
| 86 | */ | 89 | */ |
| 87 | setnumV(L->top-1, (lua_Number)diff); | 90 | setintptrV(L->top-1, (int32_t)diff); |
| 88 | return 1; | 91 | return 1; |
| 89 | } else if (mm == MM_lt) { /* Pointer comparison (unsigned). */ | 92 | } else if (mm == MM_lt) { /* Pointer comparison (unsigned). */ |
| 90 | setboolV(L->top-1, ((uintptr_t)pp < (uintptr_t)pp2)); | 93 | setboolV(L->top-1, ((uintptr_t)pp < (uintptr_t)pp2)); |
diff --git a/src/lj_ccall.c b/src/lj_ccall.c index 3f548c30..a3908e50 100644 --- a/src/lj_ccall.c +++ b/src/lj_ccall.c | |||
| @@ -315,7 +315,7 @@ static void ccall_struct_ret(CCallState *cc, int *rcl, uint8_t *dp, CTSize sz) | |||
| 315 | /* Infer the destination CTypeID for a vararg argument. */ | 315 | /* Infer the destination CTypeID for a vararg argument. */ |
| 316 | static CTypeID ccall_ctid_vararg(CTState *cts, cTValue *o) | 316 | static CTypeID ccall_ctid_vararg(CTState *cts, cTValue *o) |
| 317 | { | 317 | { |
| 318 | if (tvisnum(o)) { | 318 | if (tvisnumber(o)) { |
| 319 | return CTID_DOUBLE; | 319 | return CTID_DOUBLE; |
| 320 | } else if (tviscdata(o)) { | 320 | } else if (tviscdata(o)) { |
| 321 | CTypeID id = cdataV(o)->typeid; | 321 | CTypeID id = cdataV(o)->typeid; |
diff --git a/src/lj_cconv.c b/src/lj_cconv.c index 94a9895f..884edef1 100644 --- a/src/lj_cconv.c +++ b/src/lj_cconv.c | |||
| @@ -375,10 +375,20 @@ int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid, | |||
| 375 | if (ctype_isnum(sinfo)) { | 375 | if (ctype_isnum(sinfo)) { |
| 376 | if (!ctype_isbool(sinfo)) { | 376 | if (!ctype_isbool(sinfo)) { |
| 377 | if (ctype_isinteger(sinfo) && s->size > 4) goto copyval; | 377 | if (ctype_isinteger(sinfo) && s->size > 4) goto copyval; |
| 378 | lj_cconv_ct_ct(cts, ctype_get(cts, CTID_DOUBLE), s, | 378 | if (LJ_DUALNUM && ctype_isinteger(sinfo)) { |
| 379 | (uint8_t *)&o->n, sp, 0); | 379 | int32_t i; |
| 380 | /* Numbers are NOT canonicalized here! Beware of uninitialized data. */ | 380 | lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT32), s, |
| 381 | lua_assert(tvisnum(o)); | 381 | (uint8_t *)&i, sp, 0); |
| 382 | if ((sinfo & CTF_UNSIGNED) && i < 0) | ||
| 383 | setnumV(o, (lua_Number)(uint32_t)i); | ||
| 384 | else | ||
| 385 | setintV(o, i); | ||
| 386 | } else { | ||
| 387 | lj_cconv_ct_ct(cts, ctype_get(cts, CTID_DOUBLE), s, | ||
| 388 | (uint8_t *)&o->n, sp, 0); | ||
| 389 | /* Numbers are NOT canonicalized here! Beware of uninitialized data. */ | ||
| 390 | lua_assert(tvisnum(o)); | ||
| 391 | } | ||
| 382 | } else { | 392 | } else { |
| 383 | uint32_t b = ((*sp) & 1); | 393 | uint32_t b = ((*sp) & 1); |
| 384 | setboolV(o, b); | 394 | setboolV(o, b); |
| @@ -426,10 +436,15 @@ int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp) | |||
| 426 | lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT); | 436 | lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT); |
| 427 | if (!(info & CTF_BOOL)) { | 437 | if (!(info & CTF_BOOL)) { |
| 428 | CTSize shift = 32 - bsz; | 438 | CTSize shift = 32 - bsz; |
| 429 | if (!(info & CTF_UNSIGNED)) | 439 | if (!(info & CTF_UNSIGNED)) { |
| 430 | setnumV(o, (lua_Number)((int32_t)(val << (shift-pos)) >> shift)); | 440 | setintV(o, (int32_t)(val << (shift-pos)) >> shift); |
| 431 | else | 441 | } else { |
| 432 | setnumV(o, (lua_Number)((val << (shift-pos)) >> shift)); | 442 | val = (val << (shift-pos)) >> shift; |
| 443 | if (!LJ_DUALNUM || (int32_t)val < 0) | ||
| 444 | setnumV(o, (lua_Number)(uint32_t)val); | ||
| 445 | else | ||
| 446 | setintV(o, (int32_t)val); | ||
| 447 | } | ||
| 433 | } else { | 448 | } else { |
| 434 | lua_assert(bsz == 1); | 449 | lua_assert(bsz == 1); |
| 435 | setboolV(o, (val >> pos) & 1); | 450 | setboolV(o, (val >> pos) & 1); |
| @@ -519,7 +534,11 @@ void lj_cconv_ct_tv(CTState *cts, CType *d, | |||
| 519 | CType *s; | 534 | CType *s; |
| 520 | void *tmpptr; | 535 | void *tmpptr; |
| 521 | uint8_t tmpbool, *sp = (uint8_t *)&tmpptr; | 536 | uint8_t tmpbool, *sp = (uint8_t *)&tmpptr; |
| 522 | if (LJ_LIKELY(tvisnum(o))) { | 537 | if (LJ_LIKELY(tvisint(o))) { |
| 538 | sp = (uint8_t *)&o->i; | ||
| 539 | sid = CTID_INT32; | ||
| 540 | flags |= CCF_FROMTV; | ||
| 541 | } else if (LJ_LIKELY(tvisnum(o))) { | ||
| 523 | sp = (uint8_t *)&o->n; | 542 | sp = (uint8_t *)&o->n; |
| 524 | sid = CTID_DOUBLE; | 543 | sid = CTID_DOUBLE; |
| 525 | flags |= CCF_FROMTV; | 544 | flags |= CCF_FROMTV; |
diff --git a/src/lj_cdata.c b/src/lj_cdata.c index af78d05e..ae66b4b5 100644 --- a/src/lj_cdata.c +++ b/src/lj_cdata.c | |||
| @@ -88,7 +88,10 @@ collect_attrib: | |||
| 88 | } | 88 | } |
| 89 | lua_assert(!ctype_isref(ct->info)); /* Interning rejects refs to refs. */ | 89 | lua_assert(!ctype_isref(ct->info)); /* Interning rejects refs to refs. */ |
| 90 | 90 | ||
| 91 | if (tvisnum(key)) { /* Numeric key. */ | 91 | if (tvisint(key)) { |
| 92 | idx = (ptrdiff_t)intV(key); | ||
| 93 | goto integer_key; | ||
| 94 | } else if (tvisnum(key)) { /* Numeric key. */ | ||
| 92 | idx = LJ_64 ? (ptrdiff_t)numV(key) : (ptrdiff_t)lj_num2int(numV(key)); | 95 | idx = LJ_64 ? (ptrdiff_t)numV(key) : (ptrdiff_t)lj_num2int(numV(key)); |
| 93 | integer_key: | 96 | integer_key: |
| 94 | if (ctype_ispointer(ct->info)) { | 97 | if (ctype_ispointer(ct->info)) { |
| @@ -171,10 +174,10 @@ static void cdata_getconst(CTState *cts, TValue *o, CType *ct) | |||
| 171 | CType *ctt = ctype_child(cts, ct); | 174 | CType *ctt = ctype_child(cts, ct); |
| 172 | lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4); | 175 | lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4); |
| 173 | /* Constants are already zero-extended/sign-extended to 32 bits. */ | 176 | /* Constants are already zero-extended/sign-extended to 32 bits. */ |
| 174 | if (!(ctt->info & CTF_UNSIGNED)) | 177 | if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0) |
| 175 | setintV(o, (int32_t)ct->size); | ||
| 176 | else | ||
| 177 | setnumV(o, (lua_Number)(uint32_t)ct->size); | 178 | setnumV(o, (lua_Number)(uint32_t)ct->size); |
| 179 | else | ||
| 180 | setintV(o, (int32_t)ct->size); | ||
| 178 | } | 181 | } |
| 179 | 182 | ||
| 180 | /* Get C data value and convert to TValue. */ | 183 | /* Get C data value and convert to TValue. */ |
diff --git a/src/lj_clib.c b/src/lj_clib.c index 98d74cde..d7721860 100644 --- a/src/lj_clib.c +++ b/src/lj_clib.c | |||
| @@ -266,10 +266,10 @@ TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name) | |||
| 266 | if (ctype_isconstval(ct->info)) { | 266 | if (ctype_isconstval(ct->info)) { |
| 267 | CType *ctt = ctype_child(cts, ct); | 267 | CType *ctt = ctype_child(cts, ct); |
| 268 | lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4); | 268 | lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4); |
| 269 | if ((ctt->info & CTF_UNSIGNED) && ctt->size == 4) | 269 | if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0) |
| 270 | setnumV(tv, (lua_Number)(uint32_t)ct->size); | 270 | setnumV(tv, (lua_Number)(uint32_t)ct->size); |
| 271 | else | 271 | else |
| 272 | setnumV(tv, (lua_Number)(int32_t)ct->size); | 272 | setintV(tv, (int32_t)ct->size); |
| 273 | } else { | 273 | } else { |
| 274 | const char *sym = clib_extsym(cts, ct, name); | 274 | const char *sym = clib_extsym(cts, ct, name); |
| 275 | void *p = clib_getsym(cl, sym); | 275 | void *p = clib_getsym(cl, sym); |
