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 906DF6ECE3; Mon, 27 Jun 2022 23:29:03 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 906DF6ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1656361743; bh=5QpRfQz4tpNyICRnZkbmA5DMciZVDohr+4aoTMqKg3M=; 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=Js6ehRn2ucBZZlwJwI4R1cW8ZCoo3zTBg9dKopUrc4ufycdxP2z98aqx4u32dDANg 8kIMRgmr7dhNBcQQi2v4vz8HxhfiNVwTXO9UfJmY32zBb52DJK5UWvSEs/BsjMrx0X 6ehgKykXIBwvfWu50WTS26ISYOo1es1Rjd/9SZso= Received: from smtp17.mail.ru (smtp17.mail.ru [94.100.176.154]) (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 DB50A6ECE3 for ; Mon, 27 Jun 2022 23:29:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DB50A6ECE3 Received: by smtp17.mail.ru with esmtpa (envelope-from ) id 1o5vLx-0006hE-0t; Mon, 27 Jun 2022 23:29:01 +0300 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) In-Reply-To: Date: Mon, 27 Jun 2022 23:29:00 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Sergey Kaplun X-Mailer: Apple Mail (2.3696.100.31) X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD921FF253C2DCA643281118965E48D7E4D06C6C4839B6ACAB000894C459B0CD1B99E550D5DC968B6D21CB9CA8FF64BF71CAACADB8CF3D7C871C518DC9AAFF1970F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A72B1EA4C8D5AD81EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063727BBC20C3D5F36038638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D89B94FAE35502284C54E09BD3D50F66A2117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD182CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE4B6963042765DA4BB78CF848AE20165DD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE3724336BCC0EE1BA86136E347CC761E07C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F790063723E6C16DD8DD76DAEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: 0D63561A33F958A530A3C8CBAC51FCDED6C3DCD109D233F0AD639258B582DF9FD59269BC5F550898D99A6476B3ADF6B4886A5961035A09600383DAD389E261318FB05168BE4CE3AF X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F1257DC9690AEBA11FA77004E3DC5B09D274DC8E93A5B2732640137966FEA7E30530965EA2AA825B1D7E09C32AA3244C0A864771E881C7D315647B0035C4EBF6BBA718C7E6A9E042FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj8L65zF8kk4dBdbHYzC0IcQ== X-Mailru-Sender: 5AA3D5B9D8C486460F131602D6A791BC6B2B888D5AA63384D2FFDC557952AF1B46EB8B20CC5C2CB719381EE24192DF5555834048F03EF5D4C9A814A92B2E3B1BA4250FC3964EA4964198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] Fix tonumber("-0"). 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, LGTM. Sergos > On 26 Jan 2022, at 15:19, Sergey Kaplun wrote: >=20 > From: Mike Pall >=20 > Reported by bluecheetah001. >=20 > (cherry picked from 45a7e5073ce0a59465fef0b80bb08bd4e76b7979) >=20 > Common case for scanning a string containing a number is a string with = a > decimal number. For this case, a decimal number first casts to int32_t > and later to double (lua_Number) if necessary. Information about sign = of > 0 is lost during the cast to int32_t. So resulting TValue contains = `0.` > instead of `-0.`. >=20 > This patch removes cast to int32_t for the case when resulting TValue > contains double value. >=20 > Sergey Kaplun: > * added the description and the test for the problem >=20 > Part of tarantool/tarantool#6548 > --- > src/lj_strscan.c | 5 ++--- > .../lj-528-tonumber-0.test.lua | 19 +++++++++++++++++++ > 2 files changed, 21 insertions(+), 3 deletions(-) > create mode 100644 test/tarantool-tests/lj-528-tonumber-0.test.lua >=20 > diff --git a/src/lj_strscan.c b/src/lj_strscan.c > index 08f41f19..4e4ef6d3 100644 > --- a/src/lj_strscan.c > +++ b/src/lj_strscan.c > @@ -495,12 +495,11 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, = MSize len, TValue *o, > /* Fast path for decimal 32 bit integers. */ > if (fmt =3D=3D STRSCAN_INT && base =3D=3D 10 && > (dig < 10 || (dig =3D=3D 10 && *sp <=3D '2' && x < = 0x80000000u+neg))) { > - int32_t y =3D neg ? -(int32_t)x : (int32_t)x; > if ((opt & STRSCAN_OPT_TONUM)) { > - o->n =3D (double)y; > + o->n =3D neg ? -(double)x : (double)x; > return STRSCAN_NUM; > } else { > - o->i =3D y; > + o->i =3D neg ? -(int32_t)x : (int32_t)x; > 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 > new file mode 100644 > index 00000000..03ba2aff > --- /dev/null > +++ b/test/tarantool-tests/lj-528-tonumber-0.test.lua > @@ -0,0 +1,19 @@ > +local tap =3D 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 ~=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. > +local test =3D tap.test('lj-528-tonumber-0') > +test:plan(1) > + > +-- As numbers `-0 =3D=3D 0`, so convert it back to string. > +test:ok(tostring(tonumber('-0')) =3D=3D '-0', 'correct "-0" string = parsing') > + > +os.exit(test:check() and 0 or 1) > --=20 > 2.34.1 >=20