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 C18ED67396F; Mon, 23 Oct 2023 12:28:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C18ED67396F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1698053288; bh=kEVXKitRFqtlv4DJVSOA4w5Ua/0MTj8n5gSmvdmeQHQ=; 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=qW9x+EvTNhZdSS0cb1K7lCUi+u3qjkDGmkmvTCUgERWDE6WN9U1lcCLeTm7k6yjGi JEXvIoGvLnJ89UnsixhyFkws/xfyLKQCCq8DKKOaBbQykLzIzoubTtlss3SAhmrGK5 +QSV1zvSZ8dKHb9XnvZNso4C2+cz0pRmN5LXuynQ= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 10C82673966 for ; Mon, 23 Oct 2023 12:26:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 10C82673966 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1qurCo-0007cl-0o; Mon, 23 Oct 2023 12:26:38 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Mon, 23 Oct 2023 12:22:03 +0300 Message-ID: <78ee203fe7832fde6d2f1dfb40591b8f191e59a5.1698049570.git.skaplun@tarantool.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9C197A170B57C5E43D146E4833C4DCA15B3520AC3C534702000894C459B0CD1B90459070DCA3F9A8E4DC2930754DD900808F89D8EC0FEE90F37AD88C62730AFDD X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7FBB2043146276655EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637A9E1EE47BE02EAD28638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8109CB4A9ECA890D1D3FCE2EA82071F2A117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3733B5EC72352B9FA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751F2CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269176DF2183F8FC7C0E9CA1980FA7BB05068655334FD4449CB33AC447995A7AD1857739F23D657EF2BD5E8D9A59859A8B679E85A9FDE02C04A75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A5F5268E34638856D4F5A1C08BD931AD5FCAE5EE17E875C088F87CCE6106E1FC07E67D4AC08A07B9B0A816C540FC8EEC309C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF7BBB37DA0FD93FBD1A9FF085B95FD1063B8A093A450F5BD1C30D88B386EE4180A30287D0F4871F18A8B50B9382ADB12A3CD50BAAC0663068EB64AF529D7E6A3CA74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojqlVu258LHAFEe/t5Bc7qcQ== X-DA7885C5: C0F4263FF7231FEB7C62A0077695275C50CC65EFF09649E17860B839719A6EB0262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73930F533AC2B33E986BE3D72FC17DA170CCF32CB513B5EF7A130FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 3/6] FFI: Ensure returned string is alive in ffi.typeinfo(). 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 zhuizhuhaomeng. (cherry-picked from commit 94a40bb238092e73f3dc0c3626911a7efa997c22) `ffi.typeinfo()` doesn't check that the string containing the name type is alive when it sets this string to the returned table. This leads to the corresponding assertion failure in `checklivetv()`. This patch flips the white colour of the stored string to resurrect it. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#9145 --- src/lib_ffi.c | 1 + .../lj-745-ffi-typeinfo-dead-names.test.lua | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/tarantool-tests/lj-745-ffi-typeinfo-dead-names.test.lua diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 62af54c1..e60e7b19 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c @@ -573,6 +573,7 @@ LJLIB_CF(ffi_typeinfo) setintV(lj_tab_setstr(L, t, lj_str_newlit(L, "sib")), (int32_t)ct->sib); if (gcref(ct->name)) { GCstr *s = gco2str(gcref(ct->name)); + if (isdead(G(L), obj2gco(s))) flipwhite(obj2gco(s)); setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "name")), s); } lj_gc_check(L); diff --git a/test/tarantool-tests/lj-745-ffi-typeinfo-dead-names.test.lua b/test/tarantool-tests/lj-745-ffi-typeinfo-dead-names.test.lua new file mode 100644 index 00000000..02e13759 --- /dev/null +++ b/test/tarantool-tests/lj-745-ffi-typeinfo-dead-names.test.lua @@ -0,0 +1,28 @@ +local tap = require('tap') +local ffi = require('ffi') +local test = tap.test('lj-745-ffi-typeinfo-dead-names') + +test:plan(1) + +-- Start from the beginning of the GC cycle. +collectgarbage() + +local function ctypes_iteration() + local i = 1 + -- Test `checklivetv()` assertion in `setstrV()` inside + -- `ffi.typeinfo()`. + while ffi.typeinfo(i) do i = i + 1 end +end + +-- Call `ffi.typeinfo()` much enough to be sure that strings with +-- names of types become dead. The number of iterations is big +-- enough (more than x2 of the required value) to see assertion +-- failure guaranteed under Tarantool too (it has much more alive +-- objects on start). +for _ = 1, 100 do + ctypes_iteration() +end + +test:ok(true, 'no assertion failure inside ffi.typeinfo()') + +test:done(true) -- 2.42.0