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 C9C426F3C8; Thu, 22 Sep 2022 12:39:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C9C426F3C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1663839571; bh=IH9u6MBAi/S1NcA6bMSVOwTEgbYmQqIhtGKjaRrOWeo=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=yAeWyNVV+pF2ttBu8K+Ld6+UOjWsOq81lnIJ8RQrvcP0/DLalHyo5Pxb5gp54xT23 scW8UwS8cftwiKrcyHoQBsac474S4eWW3UUTPK8OSufNNwT3+LIX6RpKsdbpD0tK2Q A17KqfMpfD3k45x4Tq8/lsAtC4x9CsPmhYgRRcL0= Received: from smtp49.i.mail.ru (smtp49.i.mail.ru [94.100.177.109]) (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 B58C26F3C8 for ; Thu, 22 Sep 2022 12:39:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B58C26F3C8 Received: by smtp49.i.mail.ru with esmtpa (envelope-from ) id 1obIg4-0005b4-SV; Thu, 22 Sep 2022 12:39:29 +0300 Date: Thu, 22 Sep 2022 12:36:44 +0300 To: sergos Cc: Maxim Kokryashkin , tarantool-patches@dev.tarantool.org Message-ID: References: <20220823142741.2729-1-skaplun@tarantool.org> <88EAAF33-E306-45F4-BA82-D807BD737385@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <88EAAF33-E306-45F4-BA82-D807BD737385@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD97DCA401AFF23C13EF79B072DB1AED29260C68B3C55FD27DD182A05F5380850404C228DA9ACA6FE277042101B16D60F46E2FC6CB3DB766202901D413FB9A41F86EFCCDDBCF94F76F0 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D4EF26BAC91EEE7FEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637225475490A77DC518638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8FC7749DF7350C1A0C7AB5F46E1F564B7117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC5F0C88D684269EDEA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18F04B652EEC242312D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE902A1BE408319B291AD9CA79AA6DBBDDD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE3CF7CD7A0D5AA5F25C0837EA9F3D19764C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BB9CEE4F2B4A90F8475ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 9604B64F49C60606AD91A466A1DEF99B296C473AB1E142185AC9E3593CE4B31AB1881A6453793CE9274300E5CE05BD4401A9E91200F654B06604ACF793451CC55036A336AC3467B45DDF58C3A18C9555F15F861D546BD66B9C2B6934AE262D3EE7EAB7254005DCED8DA55E71E02F9FC08E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D71B56C992F8AF1942B04D7119C40197842450F4C0B4E697E422C56F886F1B58B7DA53854CE171D71D7E09C32AA3244C00CE0B767D990BD10D3793403A6AC612F2F5F14F68F1805BFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojS8Mlo6Y3xQmaK/0oRS8C/g== X-Mailru-Sender: F16D9CAFEEA6770E7B6EAD4ADB3BCAF09926EA961D2CB0BDB283E78A816999C8BD00C29C97ADC1B3F2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A84198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] FFI: Always fall back to metamethods for cdata length/concat. 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: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergos! Thanks for the review! On 31.08.22, sergos wrote: > Hi! > Thanks for the patch! > > Just a minor message update and a test extension - otherwise LGTM. > > Sergos > > > On 23 Aug 2022, at 17:27, Sergey Kaplun wrote: > > > > From: Mike Pall > > > > Thanks to Egor Skriptunoff. > > > > (cherry picked from commit cc4bbec483d3f3250b519ccb7cc22f1a8e6fe6f0) > > > > When user tries to concatenate 2 cdata objects without declared > > metamethod, the assertion is raised in `carith_int64()`, due to > > concatenation operation is not specified and default (assert) branch is > > taken. > > The above doesn’t explain the behavior - the default branch leads to what? > Neither it explains the expected behavior. Fixed. The new commit message is the following: | FFI: Always fall back to metamethods for cdata length/concat. | | Thanks to Egor Skriptunoff. | | (cherry picked from commit cc4bbec483d3f3250b519ccb7cc22f1a8e6fe6f0) | | When user tries to concatenate 2 cdata objects without declared | metamethod, the assertion is raised in `carith_int64()`, due to | concatenation operation is not specified and default (assert) branch is | taken. In non debug mode this leads to returning of new cdata with | unfilled `cdataptr` content (i.e. random value from memory). | | It is not possible to predict, what behavior the user expects in case of | concatenation of 2 cdata objects. So, the error should be rased, when | user tries to concatenate these cdata objects without metamethod | declared. | | This patch forcifies usage of metamethod for concatenation on cdata | objects. Also, as far as the behaviour for length operation is the same, | the `lj_carith_len()` routine is removed, its call is replaced with | `ffi_arith()`. | | Sergey Kaplun: | * added the description and the test for the problem | | Part of tarantool/tarantool#7230 > > > > > This patch forcifies usage of metamethod for concatenation on cdata > > objects. Also, as far as the behaviour for length operation is the same, > > the `lj_carith_len()` routine is removed, its call is replaced with > > `ffi_arith()`. > > > > Sergey Kaplun: > > * added the description and the test for the problem > > > > Part of tarantool/tarantool#7230 > > --- > > > > Issue: https://github.com/tarantool/tarantool/issues/7230 > > Branch: https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-cdata-ll-concat-full-ci > > PR: https://github.com/tarantool/tarantool/pull/7598 > > ML: https://www.freelists.org/post/luajit/cdata-concatenation > > > > src/lj_carith.c | 3 +-- > > src/lj_crecord.c | 6 ++++-- > > test/tarantool-tests/fix-cdata-concat.test.lua | 15 +++++++++++++++ > > 3 files changed, 20 insertions(+), 4 deletions(-) > > create mode 100644 test/tarantool-tests/fix-cdata-concat.test.lua > > > > diff --git a/src/lj_carith.c b/src/lj_carith.c > > index 218abd26..04c18054 100644 > > --- a/src/lj_carith.c > > +++ b/src/lj_carith.c > > diff --git a/src/lj_crecord.c b/src/lj_crecord.c > > index 0d7b71f0..3d562d9a 100644 > > --- a/src/lj_crecord.c > > +++ b/src/lj_crecord.c > > diff --git a/test/tarantool-tests/fix-cdata-concat.test.lua b/test/tarantool-tests/fix-cdata-concat.test.lua > > new file mode 100644 > > index 00000000..aaeb36fa > > --- /dev/null > > +++ b/test/tarantool-tests/fix-cdata-concat.test.lua > > @@ -0,0 +1,15 @@ > > +local tap = require('tap') > > + > > +-- Test file to demonstrate incorrect behaviour of cdata > > +-- concatenation in LuaJIT. > > +-- See also > > +-- https://www.freelists.org/post/luajit/cdata-concatenation. > > +local test = tap.test('cdata-concat') > > +test:plan(1) > > + > > +local r, e = pcall(function() > > + return 1LL .. 2LL > > +end) > > +test:ok(not r and e:match('attempt to concatenate'), 'cdata concatenation') > > As with programmer’s joke about full and empty glass - let’s have a second case > for the existent metamethod? Added with the following patch: =================================================================== diff --git a/test/tarantool-tests/fix-cdata-concat.test.lua b/test/tarantool-tests/fix-cdata-concat.test.lua index aaeb36fa..df069e58 100644 --- a/test/tarantool-tests/fix-cdata-concat.test.lua +++ b/test/tarantool-tests/fix-cdata-concat.test.lua @@ -5,11 +5,17 @@ local tap = require('tap') -- See also -- https://www.freelists.org/post/luajit/cdata-concatenation. local test = tap.test('cdata-concat') -test:plan(1) +test:plan(2) local r, e = pcall(function() return 1LL .. 2LL end) test:ok(not r and e:match('attempt to concatenate'), 'cdata concatenation') +-- Check, that concatenation work, when metamethod is defined. +debug.getmetatable(1LL).__concat = function(a, b) + return tostring(a) .. tostring(b) +end +test:ok(1LL .. 2LL == '1LL2LL', 'cdata concatenation with defined metamethod') + os.exit(test:check() and 0 or 1) =================================================================== Branch is force-pushed. > > > + > > +os.exit(test:check() and 0 or 1) > > -- > > 2.34.1 > > > -- Best regards, Sergey Kaplun