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 08C99BA86C1; Tue, 11 Jun 2024 18:48:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 08C99BA86C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1718120885; bh=IzoSmcMV+jhT1t6CVg1tAOTRDUaAiIQCcjpa2RNN6Mo=; 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=doYxt7MnSjLkZU6kM2Gi3nx+y76Ft3KrABAwG3YrQpOgYqSr9Dh47Lb4wE2P0mrD4 HrOoUnhmiDrghF/oA690YGbny/jGjmjBsooWnT40mlGuO6d93Z5pVavowyYSJZ66Yk 4Rr4+u2M8a1M/f6sJ/QcHMPB+dAjJ05Y4AGhmH7c= Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [95.163.41.85]) (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 523D6BA86C0 for ; Tue, 11 Jun 2024 18:48:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 523D6BA86C0 Received: by smtp47.i.mail.ru with esmtpa (envelope-from ) id 1sH3j8-0000000EK1I-1dUJ; Tue, 11 Jun 2024 18:48:02 +0300 Content-Type: multipart/alternative; boundary="------------ogtiAeIdcyLa08hxaFH94jTE" Message-ID: Date: Tue, 11 Jun 2024 18:48:01 +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: <034b0afe429e672809ec8192ff1fb41a7bfd2937.1717424008.git.skaplun@tarantool.org> In-Reply-To: <034b0afe429e672809ec8192ff1fb41a7bfd2937.1717424008.git.skaplun@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9AC8CA0B4439200FA2E41D1825D8172A0E0E393E23BEE614B00894C459B0CD1B9FF2A9AB572FEADB1D74F96B4FC2E8485473F45F2718BED8EB283DC6CA4AD10FD35AA1534FA60CA86 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE721D130CF676D2164EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F78F3D6E0D6791938638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D871BB45BD7C8ABD4A7175589AC794BB6C772CA91BE55C1158CC7F00164DA146DAFE8445B8C89999728AA50765F7900637DCE3DBD6F8E38AFD389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8ED96AA85C75E140D117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF2F36E1858E9CF555BA3038C0950A5D36C8A9BA7A39EFB766D91E3A1F190DE8FDBA3038C0950A5D36D5E8D9A59859A8B66E72AA9E7D514E7076E601842F6C81A1F004C906525384303E02D724532EE2C3F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7CA1D607EB49F9BFEF43847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A5EF32CEEA679DD09E5002B1117B3ED696CC0BBE63575D094C72305013E4AE841E823CB91A9FED034534781492E4B8EEAD21D4E6D365FE45D1BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF69AF3F645CCF92052590C8DCEA68C2696EE661B06143B07DAE8589102148E19235D9E4C97941E9B104A26A3878DC1330E9959D183562D7631AD772740C78B5CE628F0F24EE5486BC5F4332CA8FE04980913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj7p5wIdCuWKNPo2Ruth62EQ== X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F2588458DAAB5FD100EDBFCD77EA6416FFE467E15331F3F7E59EB73925C4B44B058F942B645D15D82EE4B272BD6E4642A116CA93524AA66B5ACBE6721EF430B9A63E2A504198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 3/4] FFI: Allow ffi.metatype() for typedefs with attributes. 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. --------------ogtiAeIdcyLa08hxaFH94jTE Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Sergey thanks for the patch! LGTM with a nit below. On 03.06.2024 17:34, Sergey Kaplun wrote: > From: Mike Pall > > Reported by Eric Gouyer. > > (cherry picked from commit 27a6fee82e91319bbed8c3aa443aa2b0f1b0a470) > > Before the patch, `ffi.metatype()` raises an error when calling it on > ctype with attributes. This patch fixes the behaviour by using extra whitespace above > `ctype_raw()` instead of `ctype_get()` to follow child ctypes unless > there are no attributes on the ctype. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#9924 > --- > src/lib_ffi.c | 2 +- > test/tarantool-tests/lj-861-ctype-attributes.test.lua | 10 +++++++--- > 2 files changed, 8 insertions(+), 4 deletions(-) > > diff --git a/src/lib_ffi.c b/src/lib_ffi.c > index 2bfca25a..dfb01658 100644 > --- a/src/lib_ffi.c > +++ b/src/lib_ffi.c > @@ -770,7 +770,7 @@ LJLIB_CF(ffi_metatype) > CTypeID id = ffi_checkctype(L, cts, NULL); > GCtab *mt = lj_lib_checktab(L, 2); > GCtab *t = cts->miscmap; > - CType *ct = ctype_get(cts, id); /* Only allow raw types. */ > + CType *ct = ctype_raw(cts, id); > TValue *tv; > GCcdata *cd; > if (!(ctype_isstruct(ct->info) || ctype_iscomplex(ct->info) || > diff --git a/test/tarantool-tests/lj-861-ctype-attributes.test.lua b/test/tarantool-tests/lj-861-ctype-attributes.test.lua > index e8b29d67..a407fae0 100644 > --- a/test/tarantool-tests/lj-861-ctype-attributes.test.lua > +++ b/test/tarantool-tests/lj-861-ctype-attributes.test.lua > @@ -7,14 +7,14 @@ local tap = require('tap') > local test = tap.test('lj-861-ctype-attributes') > local ffi = require('ffi') > > -test:plan(4) > +test:plan(5) > > local EXPECTED_ALIGN = 4 > > ffi.cdef([[ > -struct __attribute__((aligned($))) s_aligned { > +typedef struct __attribute__((aligned($))) s_aligned { > uint8_t a; > -}; > +} s_aligned; > > struct test_parsing_sizeof { > char a[sizeof(struct s_aligned &)]; > @@ -37,4 +37,8 @@ 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', {}) > + > +test:ok(ok, 'ffi.metatype is called at the structure with attributes') > + > test:done(true) --------------ogtiAeIdcyLa08hxaFH94jTE Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hi, Sergey

thanks for the patch! LGTM with a nit below.

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

Reported by Eric Gouyer.

(cherry picked from commit 27a6fee82e91319bbed8c3aa443aa2b0f1b0a470)

Before the patch, `ffi.metatype()` raises an error when calling it on
ctype with attributes.  This patch fixes the behaviour by using
extra whitespace above
`ctype_raw()` instead of `ctype_get()` to follow child ctypes unless
there are no attributes on the ctype.

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

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

diff --git a/src/lib_ffi.c b/src/lib_ffi.c
index 2bfca25a..dfb01658 100644
--- a/src/lib_ffi.c
+++ b/src/lib_ffi.c
@@ -770,7 +770,7 @@ LJLIB_CF(ffi_metatype)
   CTypeID id = ffi_checkctype(L, cts, NULL);
   GCtab *mt = lj_lib_checktab(L, 2);
   GCtab *t = cts->miscmap;
-  CType *ct = ctype_get(cts, id);  /* Only allow raw types. */
+  CType *ct = ctype_raw(cts, id);
   TValue *tv;
   GCcdata *cd;
   if (!(ctype_isstruct(ct->info) || ctype_iscomplex(ct->info) ||
diff --git a/test/tarantool-tests/lj-861-ctype-attributes.test.lua b/test/tarantool-tests/lj-861-ctype-attributes.test.lua
index e8b29d67..a407fae0 100644
--- a/test/tarantool-tests/lj-861-ctype-attributes.test.lua
+++ b/test/tarantool-tests/lj-861-ctype-attributes.test.lua
@@ -7,14 +7,14 @@ local tap = require('tap')
 local test = tap.test('lj-861-ctype-attributes')
 local ffi = require('ffi')
 
-test:plan(4)
+test:plan(5)
 
 local EXPECTED_ALIGN = 4
 
 ffi.cdef([[
-struct __attribute__((aligned($))) s_aligned {
+typedef struct __attribute__((aligned($))) s_aligned {
   uint8_t a;
-};
+} s_aligned;
 
 struct test_parsing_sizeof {
   char a[sizeof(struct s_aligned &)];
@@ -37,4 +37,8 @@ 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', {})
+
+test:ok(ok, 'ffi.metatype is called at the structure with attributes')
+
 test:done(true)
--------------ogtiAeIdcyLa08hxaFH94jTE--