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 06600C16586; Mon, 3 Jun 2024 17:39:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 06600C16586 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1717425593; bh=BgkUbtnzAsCRKooPxLQZeL538RQgjQBNUU6k1Y3IB80=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=avqceFfUOmBEcVMYXv2KIto4KL/2J7E76NEsRy2PkwFFjdjAlSKZlP5CjP8Jk59ZH ij2K4Ey7IQDwFDhwjiy0BQ1QdMyyLT4AVyCrpnYjPmOF5Vo+pnXMLVUguh++/8hueF jY0NiWtiN74a5Zz4fiZos2DdfPPDrBXasNpM322Y= Received: from smtp44.i.mail.ru (smtp44.i.mail.ru [95.163.41.82]) (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 1B500C16586 for ; Mon, 3 Jun 2024 17:38:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1B500C16586 Received: by smtp44.i.mail.ru with esmtpa (envelope-from ) id 1sE8pI-0000000F2Sb-3s1R; Mon, 03 Jun 2024 17:38:21 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Mon, 3 Jun 2024 17:34:01 +0300 Message-ID: <034b0afe429e672809ec8192ff1fb41a7bfd2937.1717424008.git.skaplun@tarantool.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9F634E6C4921FF12DE67FB2CFD1D320ED62F032EB0E50ECA500894C459B0CD1B913A6C98E7EDF3D246C36CA141FC789AE11FD6361AD5FEC75B1117BCBF30E9EA1BC2FBDE9E7577831 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE76D34FAA3D8B31588C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE714773D61402E8DE9EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38B043BF0FB74779F36DB6F0D16B16A72244A58D1703E0020F85C700650A381628FA471835C12D1D9774AD6D5ED66289B5278DA827A17800CE7A6779F98BF527B7A9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C34C82C86BFC697D19117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF8A2765277F08B644BA3038C0950A5D36C8A9BA7A39EFB766D91E3A1F190DE8FDBA3038C0950A5D36D5E8D9A59859A8B6F99AF4D8A163DCE876E601842F6C81A1F004C906525384303E02D724532EE2C3F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB33AC447995A7AD1857739F23D657EF2BD5E8D9A59859A8B67393CE827C55B5F775ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A52152F62B202049835002B1117B3ED69666AA92A31120AB81BFF4097FFC9E796F823CB91A9FED034534781492E4B8EEADA2D5570B22232E1EC79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF5AB6EA6EE51056D35193E584E748A473CCBC3C33FCE4AE0F7243878B60CBA175AFE07996864E0BE25A25C67AD25077CD47FE17C307AC1F58CAAF78F86E7D576210548D36827D0DECC226CC413062362A913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojxO1G5pUKYoFgLoh3Vx8EGw== X-Mailru-Sender: 520A125C2F17F0B1A9638AD358559B59CB83DEB9D8EC3F6B411046492FDDF806E70A1C5F5E058B3BB7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: [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 Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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 `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) -- 2.45.1