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 8D1136ECE6; Mon, 6 Jun 2022 18:54:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8D1136ECE6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1654530869; bh=zNs9S+tedZXmSJvzRqwxrcy3Jy1Aq+Y4YYhuve1RtIg=; 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=HKXUqj4Cx+nl6OW6/lm5nny2F1GP2Fg6wa9A1DwWAjQaGjrln8Sr6fdp0HhrIqnMm LfQZfn77PMuwTztySzABm4kGnYnn/agNvtu+8rKYfqm4rYWNjunzSUUmdQClC8GLXH N8KeuupwDzunnFTpEVo7fERSajPsM74plxZJCt+Y= Received: from smtp30.i.mail.ru (smtp30.i.mail.ru [94.100.177.90]) (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 DA5766ECE6 for ; Mon, 6 Jun 2022 18:54:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DA5766ECE6 Received: by smtp30.i.mail.ru with esmtpa (envelope-from ) id 1nyF3k-0002W4-3s; Mon, 06 Jun 2022 18:54:28 +0300 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) In-Reply-To: <20211227102524.9410-1-skaplun@tarantool.org> Date: Mon, 6 Jun 2022 18:54:27 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <2F4277F1-B634-4CBD-ABB9-383EED9F5CD5@tarantool.org> References: <20211227102524.9410-1-skaplun@tarantool.org> To: Sergey Kaplun X-Mailer: Apple Mail (2.3696.80.82.1.1) X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9445BFF90255AB129A1FDFB55E6ABE22C5416DC1C980408AE182A05F538085040EEDAE54E5A3F011FDEF3F324453AC1D0A7281E8DB553FC8BA496A67A00CC8D74 X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: 0D63561A33F958A56863A49EE098D5AD05DB20E00375623ED9E10D0E60458516D59269BC5F550898D99A6476B3ADF6B4886A5961035A09600383DAD389E261318FB05168BE4CE3AF X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34EE19B6E2433CA0937EB930F4937069DC0F5DA7C38BD54F818F4818B6A43C872DDE9E9A068FE571251D7E09C32AA3244C78A21A4FE87912C6C04C1F9943BF41DAB018FE5BB746DCD1FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojw5CbW4eaNzLr1WwoDNdOmQ== X-Mailru-Sender: 11C2EC085EDE56FA38FD4C59F7EFE4078FA3DADEC2F886BE69352F535EBCDF695274F7791BB69DD319381EE24192DF5555834048F03EF5D4C9A814A92B2E3B1BA4250FC3964EA4964198E0F3ECE9B5443453F38A29522196 X-Mras: OK Subject: Re: [Tarantool-patches] [PATCH luajit] Add stricter check for print() vs. tostring() shortcut. 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! Just a very minor updates to the message, LGTM. Sergos > On 27 Dec 2021, at 13:25, Sergey Kaplun wrote: >=20 > From: Mike Pall >=20 > (cherry picked from 46a1b268eb0534182eda0447303c344a071632fe) >=20 > `print()` function uses tostring to convert all incoming values to the () ?^^^ > strings. So, if element to convert has `__tostring` metamethod it must an a=20 > be used. In LuaJIT `print()` base library function has a shortcut to the > detect fast path for strings and numbers. This shortcut doesn't check > metatable presence for numbers, so `__tostring` metamethod is ignored. a the >=20 > This patch adds the corresponding check for metatable on base number ^ ^ ^ the presence the > type, when the aforementioned shortcut is set. >=20 > Sergey Kaplun: > * added the description and the test for the problem >=20 > Part of tarantool/tarantool#6548 > --- >=20 > Issue: https://github.com/tarantool/tarantool/issues/6548 > Related issue: https://github.com/tarantool/tarantool/issues/6746 >=20 > Branch: = https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-print-tostrin= g-number-mt-full-ci > Tarantool branch: = https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-print-tost= ring-number-mt-full-ci >=20 > CI is red due to integration tests failes (same as on master) or due = to > connection errors. >=20 > src/lib_base.c | 3 +- > .../print-tostring-number.test.lua | 45 +++++++++++++++++++ > 2 files changed, 47 insertions(+), 1 deletion(-) > create mode 100644 test/tarantool-tests/print-tostring-number.test.lua >=20 > diff --git a/src/lib_base.c b/src/lib_base.c > index 3a757870..d58de10b 100644 > --- a/src/lib_base.c > +++ b/src/lib_base.c > @@ -493,7 +493,8 @@ LJLIB_CF(print) > lua_gettable(L, LUA_GLOBALSINDEX); > tv =3D L->top-1; > } > - shortcut =3D (tvisfunc(tv) && funcV(tv)->c.ffid =3D=3D = FF_tostring); > + shortcut =3D (tvisfunc(tv) && funcV(tv)->c.ffid =3D=3D FF_tostring) > + && !gcrefu(basemt_it(G(L), LJ_TNUMX)); > for (i =3D 0; i < nargs; i++) { > cTValue *o =3D &L->base[i]; > const char *str; > diff --git a/test/tarantool-tests/print-tostring-number.test.lua = b/test/tarantool-tests/print-tostring-number.test.lua > new file mode 100644 > index 00000000..862bd0f9 > --- /dev/null > +++ b/test/tarantool-tests/print-tostring-number.test.lua > @@ -0,0 +1,45 @@ > +local tap =3D require('tap') > + > +local test =3D tap.test('print-tostring-number') > + > +-- First field is type, second -- content of cmd. > +local test_data =3D { > + {'nil', 'nil'}, > + {'boolean', 'true'}, > + {'userdata', 'newproxy()'}, > + {'number', '42'}, > + -- FIXME: This test case is disabled, because __tostring > + -- metamethod isn't checked for string base metatable. > + -- See also https://github.com/tarantool/tarantool/issues/6746. > + -- {'string', '"teststr"'}, > + {'table', '{}'}, > + {'function', 'function() end'}, > + {'thread', 'coroutine.create(function() end)'}, > +} > + > +local NTEST =3D #test_data > +test:plan(NTEST) > + > +local i =3D 0 > +while arg[i] do i =3D i - 1 end > +local luabin =3D arg[i + 1] > + > +for j =3D 1, NTEST do > + local prefix =3D '__tostring reloaded for ' > + local datatype =3D test_data[j][1] > + local expected =3D prefix .. datatype > + > + local cmd =3D luabin .. ([[ -e ' > + local testvar =3D %s > + debug.setmetatable(testvar, {__tostring =3D function(a) > + return "%s" .. type(a) > + end}) > + print(testvar) > + ']]):format(test_data[j][2], prefix) > + > + local proc =3D io.popen(cmd) > + local res =3D proc:read('*all'):gsub('%s+$', '') > + test:ok(res =3D=3D expected, expected) > +end > + > +os.exit(test:check() and 0 or 1) > --=20 > 2.34.1 >=20