From: sergos via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Sergey Kaplun <skaplun@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH luajit 2/2] Fix tonumber("-0") in dual-number mode. Date: Mon, 27 Jun 2022 18:51:09 +0300 [thread overview] Message-ID: <31CBDDDA-21AE-41CD-88BA-8E4D0F8B7230@tarantool.org> (raw) In-Reply-To: <6ab9d085d486a481362259063598825a14f6876b.1643199076.git.skaplun@tarantool.org> Hi! Thanks for the patch, jut nits in the changelog. LGTM Sergos > On 26 Jan 2022, at 15:19, Sergey Kaplun <skaplun@tarantool.org> wrote: > > From: Mike Pall <mike> > > Reported by Sergey Kaplun. > > For DUALNUM build `tonumber("-0x0")` or `tonumber("-0")` returns 0 the a call to to > instead -0 due to the STRSCAN_OPT_TOINT option of `lj_strscan_scan()` of the > and cast value to integer with losing information about its sign. a of the > > This patch adds special checks for these corner cases during strscan. The > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#6548 > --- > src/lj_strscan.c | 8 ++++++-- > test/tarantool-tests/lj-528-tonumber-0.test.lua | 10 ++-------- > 2 files changed, 8 insertions(+), 10 deletions(-) > > diff --git a/src/lj_strscan.c b/src/lj_strscan.c > index 4e4ef6d3..11d341ee 100644 > --- a/src/lj_strscan.c > +++ b/src/lj_strscan.c > @@ -121,7 +121,8 @@ static StrScanFmt strscan_hex(const uint8_t *p, TValue *o, > /* Format-specific handling. */ > switch (fmt) { > case STRSCAN_INT: > - if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { > + if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg && > + !(x == 0 && neg)) { > o->i = neg ? -(int32_t)x : (int32_t)x; > return STRSCAN_INT; /* Fast path for 32 bit integers. */ > } > @@ -498,6 +499,9 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, > if ((opt & STRSCAN_OPT_TONUM)) { > o->n = neg ? -(double)x : (double)x; > return STRSCAN_NUM; > + } else if (x == 0 && neg) { > + o->n = -0.0; > + return STRSCAN_NUM; > } else { > o->i = neg ? -(int32_t)x : (int32_t)x; > return STRSCAN_INT; > @@ -515,7 +519,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, > fmt = strscan_dec(sp, o, fmt, opt, ex, neg, dig); > > /* Try to convert number to integer, if requested. */ > - if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT)) { > + if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT) && !tvismzero(o)) { > double n = o->n; > int32_t i = lj_num2int(n); > if (n == (lua_Number)i) { o->i = i; return STRSCAN_INT; } > diff --git a/test/tarantool-tests/lj-528-tonumber-0.test.lua b/test/tarantool-tests/lj-528-tonumber-0.test.lua > index 03ba2aff..f3ad53d3 100644 > --- a/test/tarantool-tests/lj-528-tonumber-0.test.lua > +++ b/test/tarantool-tests/lj-528-tonumber-0.test.lua > @@ -1,15 +1,9 @@ > local tap = require('tap') > > --- Test disabled for DUALNUM mode default for some arches. > --- See also https://github.com/LuaJIT/LuaJIT/pull/787. > -require("utils").skipcond( > - jit.arch ~= "x86" and jit.arch ~= "x64", > - jit.arch.." in DUALNUM mode is clumsy for now" > -) > - > -- Test file to demonstrate LuaJIT `tonumber('-0')` incorrect > -- behaviour. > --- See also https://github.com/LuaJIT/LuaJIT/issues/528. > +-- See also https://github.com/LuaJIT/LuaJIT/issues/528, > +-- https://github.com/LuaJIT/LuaJIT/pull/787. > local test = tap.test('lj-528-tonumber-0') > test:plan(1) > > -- > 2.34.1 >
next prev parent reply other threads:[~2022-06-27 15:51 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-01-26 12:19 [Tarantool-patches] [PATCH luajit 0/2] Fix tonumber("-0") inconsistencies Sergey Kaplun via Tarantool-patches 2022-01-26 12:19 ` [Tarantool-patches] [PATCH luajit 1/2] Fix tonumber("-0") Sergey Kaplun via Tarantool-patches 2022-06-27 13:47 ` Igor Munkin via Tarantool-patches 2022-06-27 20:29 ` sergos via Tarantool-patches 2022-01-26 12:19 ` [Tarantool-patches] [PATCH luajit 2/2] Fix tonumber("-0") in dual-number mode Sergey Kaplun via Tarantool-patches 2022-01-27 9:50 ` Sergey Kaplun via Tarantool-patches 2022-06-27 13:48 ` Igor Munkin via Tarantool-patches 2022-06-27 15:51 ` sergos via Tarantool-patches [this message] 2022-06-30 12:09 ` [Tarantool-patches] [PATCH luajit 0/2] Fix tonumber("-0") inconsistencies Igor Munkin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=31CBDDDA-21AE-41CD-88BA-8E4D0F8B7230@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=sergos@tarantool.org \ --cc=skaplun@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH luajit 2/2] Fix tonumber("-0") in dual-number mode.' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox