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 5DCF8C16588; Mon, 3 Jun 2024 17:40:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5DCF8C16588 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1717425622; bh=ZztyTs053NKjA9sNSuIj3GjUhIQt3T0vaEMushoDUwU=; 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=LJwvdAS72xIC+CUx94qFpwH6IahPKGvnJgtu7hxhuyKFwVK+P9EEkyi5WIb3Ps4vH JIFJQkdBayahj98nODbPspsU+K/5ITey2VoFacRovj8Z0Mcqj/m+31h4QXZHUKTzF/ n+AZtuCqsWaodTUj6ecvBHTTzfnsWII6/j+/RbTw= 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 A7C02C16588 for ; Mon, 3 Jun 2024 17:38:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A7C02C16588 Received: by smtp44.i.mail.ru with esmtpa (envelope-from ) id 1sE8pJ-0000000F2Sb-2kZ6; Mon, 03 Jun 2024 17:38:22 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Mon, 3 Jun 2024 17:34:02 +0300 Message-ID: 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: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD98B114D81C723B2780F99F4C6D3448FA45A390B502CA9F95B182A05F5380850404C228DA9ACA6FE2791597FF045DB70CD411046492FDDF8067FC96051AE2AE76A141FDF0C5FD4DC6A955D7F540D105623 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E50EC9128971FD6EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637D58A1C8964E53F0E8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8B69FD64EB6B2AEF4262E5AE63C0E75AC64CF5D5E0471A168CC7F00164DA146DAFE8445B8C89999728AA50765F7900637BA939FD1B3BAB99B389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8989FD0BDF65E50FBF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947CDA532D2019E286A76136E347CC761E074AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3015E3C4E802C7FF8BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF17B107DEF921CE791DD303D21008E298D5E8D9A59859A8B6957A4DEDD2346B4275ECD9A6C639B01B78DA827A17800CE732FCE54C4D9A645443847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A59DE19D9384CA2C8B5002B1117B3ED696FE5F486B372D3D6F7E0012C66AE17B00823CB91A9FED034534781492E4B8EEAD9CFA8CFAC159CE19C79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF3A4607AFBAA99BC1D899194F00D6995907F86D30D7BF9C8FB3C7221D4FA807BCC150D9F1A63664455A25C67AD25077CD406CB5659668D6F3CAAF78F86E7D576259F6F7183223DD92C226CC413062362A913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojxO1G5pUKYoGTGXsv2JevBQ== X-Mailru-Sender: 520A125C2F17F0B1A9638AD358559B59CE3D856BB78FAB59411046492FDDF8067FC96051AE2AE76AB7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: [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 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 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) -- 2.45.1