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 D58A86F153; Wed, 31 Aug 2022 13:02:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D58A86F153 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1661940177; bh=bud1Plshzu/TLVXRbg5xNlEcNydjk2+0ckzK1M8k6bM=; h=In-Reply-To:Date:Cc:References:To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=n1wdx64FWLCuD3wjvg3KkKCxevg0DEhsSZSDIPd6XjpVxEeh+8+DNCQs9XeKvlDGg fuUAsZr9RT7A2AveMm+gcphFe3l18Thh4N0f6bFV23jWOOIW+0m9HvhD0VCi6ebgJ1 07Abgup5Jx+Yix75do+ZyQZUhLVlyv7UNlW7OB+o= Received: from smtp35.i.mail.ru (smtp35.i.mail.ru [94.100.177.95]) (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 B7CAD6F153 for ; Wed, 31 Aug 2022 13:02:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B7CAD6F153 Received: by smtp35.i.mail.ru with esmtpa (envelope-from ) id 1oTKYi-00019D-4a; Wed, 31 Aug 2022 13:02:56 +0300 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) In-Reply-To: <20220823142741.2729-1-skaplun@tarantool.org> Date: Wed, 31 Aug 2022 13:02:55 +0300 Cc: Maxim Kokryashkin , tarantool-patches@dev.tarantool.org Content-Transfer-Encoding: quoted-printable Message-Id: <88EAAF33-E306-45F4-BA82-D807BD737385@tarantool.org> References: <20220823142741.2729-1-skaplun@tarantool.org> To: Sergey Kaplun X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Mailru-Src: smtp X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9BF9AC82A1D2D7237764588D9A076B23928781ED220B759C8182A05F538085040A6198FCED057AEE6B3285B48F673B3EC4D5C69DD85C815D4F0D588FF335DC18C X-C1DE0DAB: 9604B64F49C60606AD91A466A1DEF99B296C473AB1E142185AC9E3593CE4B31AB1881A6453793CE9274300E5CE05BD4401A9E91200F654B088C34A25C43C957B523897933F9F8387565F6DFC1E09452D0A69EAE1EEB7E4719C2B6934AE262D3EE7EAB7254005DCED8DA55E71E02F9FC08E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3475FE4AA98865E2359F442B16714F9FDCB24ED08632E218E969AC56556ABEEFA954226772FA55B6491D7E09C32AA3244CF95195C0E0463023D6B25730C1FD7176E3D93501275E802FFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojxzT94hBWypoZlxOdkPWfJw== X-Mailru-Sender: 11C2EC085EDE56FA38FD4C59F7EFE40761B55EDFF08B07ADA7B22CB891A3E7E1F143A866344D940919381EE24192DF5555834048F03EF5D4C9A814A92B2E3B1BA4250FC3964EA4964198E0F3ECE9B5443453F38A29522196 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: sergos via Tarantool-patches Reply-To: sergos Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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: >=20 > From: Mike Pall >=20 > Thanks to Egor Skriptunoff. >=20 > (cherry picked from commit cc4bbec483d3f3250b519ccb7cc22f1a8e6fe6f0) >=20 > 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=E2=80=99t explain the behavior - the default branch = leads to what? Neither it explains the expected behavior. >=20 > 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()`. >=20 > Sergey Kaplun: > * added the description and the test for the problem >=20 > Part of tarantool/tarantool#7230 > --- >=20 > Issue: https://github.com/tarantool/tarantool/issues/7230 > Branch: = https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-cdata-ll-conc= at-full-ci > PR: https://github.com/tarantool/tarantool/pull/7598 > ML: https://www.freelists.org/post/luajit/cdata-concatenation >=20 > 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 >=20 > 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 > @@ -265,7 +265,7 @@ int lj_carith_op(lua_State *L, MMS mm) > { > CTState *cts =3D ctype_cts(L); > CDArith ca; > - if (carith_checkarg(L, cts, &ca)) { > + if (carith_checkarg(L, cts, &ca) && mm !=3D MM_len && mm !=3D = MM_concat) { > if (carith_int64(L, cts, &ca, mm) || carith_ptr(L, cts, &ca, mm)) = { > copyTV(L, &G(L)->tmptv2, L->top-1); /* Remember for trace = recorder. */ > return 1; > @@ -347,7 +347,6 @@ uint64_t lj_carith_check64(lua_State *L, int narg, = CTypeID *id) > } > } >=20 > - > /* -- 64 bit integer arithmetic helpers = ----------------------------------- */ >=20 > #if LJ_32 && LJ_HASJIT > 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 > @@ -1546,8 +1546,10 @@ void LJ_FASTCALL recff_cdata_arith(jit_State = *J, RecordFFData *rd) > } > { > TRef tr; > - if (!(tr =3D crec_arith_int64(J, sp, s, (MMS)rd->data)) && > - !(tr =3D crec_arith_ptr(J, sp, s, (MMS)rd->data)) && > + MMS mm =3D (MMS)rd->data; > + if ((mm =3D=3D MM_len || mm =3D=3D MM_concat || > + (!(tr =3D crec_arith_int64(J, sp, s, mm)) && > + !(tr =3D crec_arith_ptr(J, sp, s, mm)))) && > !(tr =3D crec_arith_meta(J, sp, s, cts, rd))) > return; > J->base[0] =3D tr; > 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 =3D 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 =3D tap.test('cdata-concat') > +test:plan(1) > + > +local r, e =3D pcall(function() > + return 1LL .. 2LL > +end) > +test:ok(not r and e:match('attempt to concatenate'), 'cdata = concatenation') As with programmer=E2=80=99s joke about full and empty glass - let=E2=80=99= s have a second case for the existent metamethod?=20 > + > +os.exit(test:check() and 0 or 1) > --=20 > 2.34.1 >=20