From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 564E36ECE3; Mon, 27 Jun 2022 18:51:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 564E36ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1656345072; bh=hCbWb2ejvs/l7JnKa5N0U/QKXS8d1Bg1U/qqKl7utFk=; h=In-Reply-To:Date:References:To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=FJTAqmWDEqKqiMq23J3XlGMJg0tfbChyUEFFzap/+LhwtzJfcBR09fotQYpfp3rSE 9si813IpsscG0thDu9yXMWW2xQe9jb02KvH2ShrZQtxlMNMYf380hYT5leHz05NkDh lUGsbQEV1EZd8AqYgs4htydFl9vseBzBa7IU36cA= Received: from smtp3.mail.ru (smtp3.mail.ru [94.100.179.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id CFD346ECE3 for ; Mon, 27 Jun 2022 18:51:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CFD346ECE3 Received: by smtp3.mail.ru with esmtpa (envelope-from ) id 1o5r14-0000qu-3q; Mon, 27 Jun 2022 18:51:10 +0300 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) In-Reply-To: <6ab9d085d486a481362259063598825a14f6876b.1643199076.git.skaplun@tarantool.org> Date: Mon, 27 Jun 2022 18:51:09 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <31CBDDDA-21AE-41CD-88BA-8E4D0F8B7230@tarantool.org> References: <6ab9d085d486a481362259063598825a14f6876b.1643199076.git.skaplun@tarantool.org> To: Sergey Kaplun X-Mailer: Apple Mail (2.3696.100.31) X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9E4569123069BF29B4F697401C164954A41C13D2DC6C7B3F5182A05F5380850404C228DA9ACA6FE27266B6203B4BC09DC5863BD1B766321DC04EBB62783AF9D48CC038A667424392C X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: 0D63561A33F958A55C2CF5EE88EF1E2FEAECBD8DBD89F1826727899F3CE54231D59269BC5F550898D99A6476B3ADF6B4886A5961035A09600383DAD389E261318FB05168BE4CE3AF X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34FD9114F69CA58D1E4BFAB005A7CDE39177E08DB46F154297DAF36BCDB2C122DA76E6F8468BA6E5981D7E09C32AA3244C05E4E8737A4C6E0D6A9C35532D0BA979435BF7150578642FFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj8L65zF8kk4f2q3qyL7Iw9A== X-Mailru-Sender: 11C2EC085EDE56FA38FD4C59F7EFE407E463CD380FA47C825FF971B473F0B9286C3A023FAE6A0A3619381EE24192DF5555834048F03EF5D4C9A814A92B2E3B1BA4250FC3964EA4964198E0F3ECE9B5443453F38A29522196 X-Mras: OK Subject: Re: [Tarantool-patches] [PATCH luajit 2/2] Fix tonumber("-0") in dual-number mode. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: sergos via Tarantool-patches Reply-To: sergos Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thanks for the patch, jut nits in the changelog. LGTM Sergos > On 26 Jan 2022, at 15:19, Sergey Kaplun wrote: >=20 > From: Mike Pall >=20 > Reported by Sergey Kaplun. >=20 > 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 >=20 > This patch adds special checks for these corner cases during strscan. The >=20 > Sergey Kaplun: > * added the description and the test for the problem >=20 > 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(-) >=20 > 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 =3D=3D 0 && neg)) { > o->i =3D 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 =3D neg ? -(double)x : (double)x; > return STRSCAN_NUM; > + } else if (x =3D=3D 0 && neg) { > + o->n =3D -0.0; > + return STRSCAN_NUM; > } else { > o->i =3D 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 =3D strscan_dec(sp, o, fmt, opt, ex, neg, dig); >=20 > /* Try to convert number to integer, if requested. */ > - if (fmt =3D=3D STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT)) { > + if (fmt =3D=3D STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT) && = !tvismzero(o)) { > double n =3D o->n; > int32_t i =3D lj_num2int(n); > if (n =3D=3D (lua_Number)i) { o->i =3D 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 =3D require('tap') >=20 > --- Test disabled for DUALNUM mode default for some arches. > --- See also https://github.com/LuaJIT/LuaJIT/pull/787. > -require("utils").skipcond( > - jit.arch ~=3D "x86" and jit.arch ~=3D "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 =3D tap.test('lj-528-tonumber-0') > test:plan(1) >=20 > --=20 > 2.34.1 >=20