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 84FEEBA86C2; Tue, 11 Jun 2024 18:50:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 84FEEBA86C2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1718121025; bh=MpBOZUwTqkKS7tLp2Ezn4LmjDfED00nRCzQFB8EO6QM=; 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=CXc9PqoPSzJ6ruqtrTMOl+sS3b/I6cMeSe3TgaKWg6gw9TCtEOY04rJ9BotXEscSS 0S2EFyySrz0iEKuBU3f/9OWxVsbtFDHIwY1a5rd/pPaJZ59sRv5PqdRHDLAl54AP3q OzPcXvInKvg+0fy1hZ6cA8yp6AGSAPfdeH1bsu6E= Received: from smtp31.i.mail.ru (smtp31.i.mail.ru [95.163.41.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id DE880BA86C8 for ; Tue, 11 Jun 2024 18:50:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DE880BA86C8 Received: by smtp31.i.mail.ru with esmtpa (envelope-from ) id 1sH3lP-0000000BcVv-2j6l; Tue, 11 Jun 2024 18:50:24 +0300 Content-Type: multipart/alternative; boundary="------------V5yioMZ0u1cIrIVKRfBVsvt9" Message-ID: Date: Tue, 11 Jun 2024 18:50:23 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun , Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org References: In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9AC8CA0B4439200FA2E41D1825D8172A0E0E393E23BEE614B00894C459B0CD1B9F6518CF3E8E2D57EEECDF1AB4C3BB1AAD4D610681BE5D0561F9E9BAB29AE205BF8D9167951636B18 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F544D30F1A6FA191EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063725D748B084CAA27D8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D84E683AA5E5BF16D032DAAAFEBBF2A2EAFB533B9AF45BD046CC7F00164DA146DAFE8445B8C89999728AA50765F7900637D0FEED2715E18529389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8A9FF340AA05FB58CF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C2A336C65186350912D242C3BD2E3F4C64AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C39A1C9D3BA3303E89BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE7AEA1580DED4E70E3731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A54FF1EFFBB987B9AE5002B1117B3ED69638850ABAE5CA8DCAD57BAD45EC4C5DE1823CB91A9FED034534781492E4B8EEADD0953842B444AAC3BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFD244DBF72CB7E901FF8EACF85784592E467ABDCFDC0393870806C960B00921ECB268D298D11CBB1A04A26A3878DC1330EEE1B73FE3C7DE1ADCEF733D31CF2B6539FCFCB67D4650A05F4332CA8FE04980913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj7p5wIdCuWKNh151A8oQy4A== X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F2588458F94964D5C4ED3CE8E9E07FF329DA7D473ED4BB89B3CB682A9C6B1C9ACA2D5C7D645D15D82EE4B272BD6E4642A116CA93524AA66B5ACBE6721EF430B9A63E2A504198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 4/4] FFI: Fix ffi.metatype() for non-raw types. 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This is a multi-part message in MIME format. --------------V5yioMZ0u1cIrIVKRfBVsvt9 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Sergey thanks for the patch! LGTM On 03.06.2024 17:34, Sergey Kaplun wrote: > From: Mike Pall > > Reported by 999pingGG. > > (cherry picked from commit 4c35a42d9cd3b8be98fa419c68e4724ccdf4f2cf) > > This patch is a follow-up to the previous commit. Since the child id is > used for the index in the lookup table, it has no effect, and metatype > methods are not overloaded. This patch fixes the behaviour by using the > correct index. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#9924 > --- > src/lib_ffi.c | 2 +- > .../lj-861-ctype-attributes.test.lua | 15 ++++++++++++--- > 2 files changed, 13 insertions(+), 4 deletions(-) > > diff --git a/src/lib_ffi.c b/src/lib_ffi.c > index dfb01658..7ed6fc78 100644 > --- a/src/lib_ffi.c > +++ b/src/lib_ffi.c > @@ -776,7 +776,7 @@ LJLIB_CF(ffi_metatype) > if (!(ctype_isstruct(ct->info) || ctype_iscomplex(ct->info) || > ctype_isvector(ct->info))) > lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE); > - tv = lj_tab_setinth(L, t, -(int32_t)id); > + tv = lj_tab_setinth(L, t, -(int32_t)ctype_typeid(cts, ct)); > if (!tvisnil(tv)) > lj_err_caller(L, LJ_ERR_PROTMT); > settabV(L, tv, mt); > diff --git a/test/tarantool-tests/lj-861-ctype-attributes.test.lua b/test/tarantool-tests/lj-861-ctype-attributes.test.lua > index a407fae0..79121cdb 100644 > --- a/test/tarantool-tests/lj-861-ctype-attributes.test.lua > +++ b/test/tarantool-tests/lj-861-ctype-attributes.test.lua > @@ -2,12 +2,14 @@ local tap = require('tap') > > -- Test file to demonstrate LuaJIT incorrect behaviour during > -- parsing and working with ctypes with attributes. > --- See also:https://github.com/LuaJIT/LuaJIT/issues/861. > +-- See also: > +-- *https://github.com/LuaJIT/LuaJIT/issues/861, > +-- *https://github.com/LuaJIT/LuaJIT/issues/1005. > > local test = tap.test('lj-861-ctype-attributes') > local ffi = require('ffi') > > -test:plan(5) > +test:plan(6) > > local EXPECTED_ALIGN = 4 > > @@ -37,8 +39,15 @@ test:is(ffi.sizeof('struct test_parsing_sizeof'), EXPECTED_ALIGN, > test:is(ffi.sizeof('struct test_parsing_alignof'), EXPECTED_ALIGN, > 'correct alignof during C parsing') > > -local ok, _ = pcall(ffi.metatype, 's_aligned', {}) > +local EXPECTED_TOSTR = '__tostring overloaded' > +local ok, obj = pcall(ffi.metatype, 's_aligned', { > + __tostring = function() > + return EXPECTED_TOSTR > + end, > +}) > > test:ok(ok, 'ffi.metatype is called at the structure with attributes') > +test:is(tostring(obj()), EXPECTED_TOSTR, > + '__tostring is overloaded for the structure with attributes') > > test:done(true) --------------V5yioMZ0u1cIrIVKRfBVsvt9 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hi, Sergey


thanks for the patch! LGTM

On 03.06.2024 17:34, Sergey Kaplun wrote:
From: Mike Pall <mike>

Reported by 999pingGG.

(cherry picked from commit 4c35a42d9cd3b8be98fa419c68e4724ccdf4f2cf)

This patch is a follow-up to the previous commit. Since the child id is
used for the index in the lookup table, it has no effect, and metatype
methods are not overloaded. This patch fixes the behaviour by using the
correct index.

Sergey Kaplun:
* added the description and the test for the problem

Part of tarantool/tarantool#9924
---
 src/lib_ffi.c                                     |  2 +-
 .../lj-861-ctype-attributes.test.lua              | 15 ++++++++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/lib_ffi.c b/src/lib_ffi.c
index dfb01658..7ed6fc78 100644
--- a/src/lib_ffi.c
+++ b/src/lib_ffi.c
@@ -776,7 +776,7 @@ LJLIB_CF(ffi_metatype)
   if (!(ctype_isstruct(ct->info) || ctype_iscomplex(ct->info) ||
 	ctype_isvector(ct->info)))
     lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);
-  tv = lj_tab_setinth(L, t, -(int32_t)id);
+  tv = lj_tab_setinth(L, t, -(int32_t)ctype_typeid(cts, ct));
   if (!tvisnil(tv))
     lj_err_caller(L, LJ_ERR_PROTMT);
   settabV(L, tv, mt);
diff --git a/test/tarantool-tests/lj-861-ctype-attributes.test.lua b/test/tarantool-tests/lj-861-ctype-attributes.test.lua
index a407fae0..79121cdb 100644
--- a/test/tarantool-tests/lj-861-ctype-attributes.test.lua
+++ b/test/tarantool-tests/lj-861-ctype-attributes.test.lua
@@ -2,12 +2,14 @@ local tap = require('tap')
 
 -- Test file to demonstrate LuaJIT incorrect behaviour during
 -- parsing and working with ctypes with attributes.
--- See also: https://github.com/LuaJIT/LuaJIT/issues/861.
+-- See also:
+-- * https://github.com/LuaJIT/LuaJIT/issues/861,
+-- * https://github.com/LuaJIT/LuaJIT/issues/1005.
 
 local test = tap.test('lj-861-ctype-attributes')
 local ffi = require('ffi')
 
-test:plan(5)
+test:plan(6)
 
 local EXPECTED_ALIGN = 4
 
@@ -37,8 +39,15 @@ test:is(ffi.sizeof('struct test_parsing_sizeof'), EXPECTED_ALIGN,
 test:is(ffi.sizeof('struct test_parsing_alignof'), EXPECTED_ALIGN,
         'correct alignof during C parsing')
 
-local ok, _ = pcall(ffi.metatype, 's_aligned', {})
+local EXPECTED_TOSTR = '__tostring overloaded'
+local ok, obj = pcall(ffi.metatype, 's_aligned', {
+  __tostring = function()
+    return EXPECTED_TOSTR
+  end,
+})
 
 test:ok(ok, 'ffi.metatype is called at the structure with attributes')
+test:is(tostring(obj()), EXPECTED_TOSTR,
+        '__tostring is overloaded for the structure with attributes')
 
 test:done(true)
--------------V5yioMZ0u1cIrIVKRfBVsvt9--