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 2D415716A45; Thu, 7 Nov 2024 17:37:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2D415716A45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1730990273; bh=dw/mF64AGDbfD/rZAOTSO+RjNxriM7P3sDVBDEqDY/c=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=neYKXyUwvDi62tCw4ocqH/18SEWziTS+iJ3HUe/93bHmafEhPRr8Ej+6H5XJlPA1p LYFKJvbCPLKVRGOpVQQp3q4NdnTV1CPzu4lW+RE/LJwFXLeAxmwkI+LbVEfYyD2s1O foSIT2PCINakGbAgtaX+NRfZ/CY0ovUUFKAcoS1g= Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [95.163.41.89]) (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 D5AC5716A45 for ; Thu, 7 Nov 2024 17:37:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D5AC5716A45 Received: by exim-smtp-56b4cdf556-k9q5l with esmtpa (envelope-from ) id 1t93du-00000000Bu6-3g85; Thu, 07 Nov 2024 17:37:51 +0300 Content-Type: multipart/alternative; boundary="------------6fIYKoas9MWA4bkJnRbbHoTv" Message-ID: <16ac85c3-a245-458f-86fd-e9d91b285bba@tarantool.org> Date: Thu, 7 Nov 2024 17:37:50 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Sergey Bronnikov , tarantool-patches@dev.tarantool.org, Sergey Kaplun , Maxim Kokryashkin References: <76c9c163c365aec70741162ab83fdfa6385a9118.1730976041.git.sergeyb@tarantool.org> Content-Language: en-US In-Reply-To: <76c9c163c365aec70741162ab83fdfa6385a9118.1730976041.git.sergeyb@tarantool.org> X-Mailru-Src: smtp X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9E150CDBF637219F0A7AB656614FA34B9301FDE5AD1036AE400894C459B0CD1B90726784207A2FEDF33594132A326AF8BC2FD3DE033EFE19A2EF68F2EB79C50C8ACCB5262BB601CA2 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE704BA85F3D5A9F85BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CDA089757FB31C668638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8DF7D90BEEFD66E2FEAD1279058B531680C65217AB55E2C9ECC7F00164DA146DAFE8445B8C89999728AA50765F79006370BDB19F53EE528DD389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8744B801E316CB65FF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947CF254576263B31EA9040F9FF01DFDA4A84AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3B1CCBFDB748CB1BDBA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166176DF2183F8FC7C0E4A630A5B664A4FF725E5C173C3A84C3F82DE84504A19E5E35872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A54D6FCC4FE25213605002B1117B3ED69643099C3AB0C61D71FB820E9FE7BD014C823CB91A9FED034534781492E4B8EEADCF86CE9B81855096 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF77DD89D51EBB7742D3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFD92FB079E30361C763D8233580A7B1032E3E53229A1888A8CDC484F04386C5C1744A43F78FC6FA90E32EED3DD60FC9D8E27BED27930B3D1111754F35ADB343C7B268A8D049953DD0C226CC413062362A913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj6BKzvXQeUkaolB4X8kxEbQ== X-Mailru-Sender: 520A125C2F17F0B1E52FEF5D219D61400726784207A2FEDF33594132A326AF8B2B96417C527D63B70152A3D17938EB451EB5A0BCEC6A560B3DDE9B364B0DF289BE2DA36745F2EEB5CEBA01FB949A1F1EEAB4BC95F72C04283CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix compilation of getmetatable() for UDTYPE_IO_FILE 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. --------------6fIYKoas9MWA4bkJnRbbHoTv Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Branch: https://github.com/tarantool/luajit/tree/ligurio/gh-1279-recording-getmetatable LJ issue: https://github.com/LuaJIT/LuaJIT/issues/1279 On 07.11.2024 13:51, Sergey Bronnikov wrote: > From: Sergey Bronnikov > > The patch fixes a problem with recording `getmetatable()` > for I/O object: recording of `getmetatable` call with a file > descriptors represented by userdata object `UDTYPE_IO_FILE` > (like `io.stdout`) leads to violation of assertion in > `rec_check_slots`. > > Note, the problem was fixed upstream in different manner, see > commit 5141cbc20c43 > ("Fix compiliation of getmetatable() for UDTYPE_IO_FILE."). > --- > src/lj_record.c | 2 +- > ...-incorrect-recording-getmetatable.test.lua | 21 +++++++++++++++++++ > 2 files changed, 22 insertions(+), 1 deletion(-) > create mode 100644 test/tarantool-tests/lj-1279-incorrect-recording-getmetatable.test.lua > > diff --git a/src/lj_record.c b/src/lj_record.c > index cc97bdf9..7181b72a 100644 > --- a/src/lj_record.c > +++ b/src/lj_record.c > @@ -990,7 +990,7 @@ int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm) > int udtype = udataV(&ix->tabv)->udtype; > mt = tabref(udataV(&ix->tabv)->metatable); > /* The metatables of special userdata objects are treated as immutable. */ > - if (udtype != UDTYPE_USERDATA) { > + if (udtype > UDTYPE_IO_FILE) { > cTValue *mo; > if (LJ_HASFFI && udtype == UDTYPE_FFI_CLIB) { > /* Specialize to the C library namespace object. */ > diff --git a/test/tarantool-tests/lj-1279-incorrect-recording-getmetatable.test.lua b/test/tarantool-tests/lj-1279-incorrect-recording-getmetatable.test.lua > new file mode 100644 > index 00000000..8bf22ca7 > --- /dev/null > +++ b/test/tarantool-tests/lj-1279-incorrect-recording-getmetatable.test.lua > @@ -0,0 +1,21 @@ > +local tap = require('tap') > + > +local test = tap.test('lj-1279-incorrect-recording-getmetatable') > +test:plan(1) > + > +-- A test file to demonstrate an incorrect recording of > +-- getmetatable() for I/O handlers. > +--https://github.com/LuaJIT/LuaJIT/issues/1279 > + > +jit.opt.start("hotloop=1") > + > +local obj = io.stdout > +local getmetatable = getmetatable > + > +for _ = 1, 4 do > + _ = getmetatable(obj) > +end > + > +test:ok(true, 'getmetatable() recording is correct') > + > +test:done(true) --------------6fIYKoas9MWA4bkJnRbbHoTv Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Branch: https://github.com/tarantool/luajit/tree/ligurio/gh-1279-recording-getmetatable

LJ issue: https://github.com/LuaJIT/LuaJIT/issues/1279


On 07.11.2024 13:51, Sergey Bronnikov wrote:
From: Sergey Bronnikov <sergeyb@tarantool.org>

The patch fixes a problem with recording `getmetatable()`
for I/O object: recording of `getmetatable` call with a file
descriptors represented by userdata object `UDTYPE_IO_FILE`
(like `io.stdout`) leads to violation of assertion in
`rec_check_slots`.

Note, the problem was fixed upstream in different manner, see
commit 5141cbc20c43
("Fix compiliation of getmetatable() for UDTYPE_IO_FILE.").
---
 src/lj_record.c                               |  2 +-
 ...-incorrect-recording-getmetatable.test.lua | 21 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 test/tarantool-tests/lj-1279-incorrect-recording-getmetatable.test.lua

diff --git a/src/lj_record.c b/src/lj_record.c
index cc97bdf9..7181b72a 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -990,7 +990,7 @@ int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm)
     int udtype = udataV(&ix->tabv)->udtype;
     mt = tabref(udataV(&ix->tabv)->metatable);
     /* The metatables of special userdata objects are treated as immutable. */
-    if (udtype != UDTYPE_USERDATA) {
+    if (udtype > UDTYPE_IO_FILE) {
       cTValue *mo;
       if (LJ_HASFFI && udtype == UDTYPE_FFI_CLIB) {
 	/* Specialize to the C library namespace object. */
diff --git a/test/tarantool-tests/lj-1279-incorrect-recording-getmetatable.test.lua b/test/tarantool-tests/lj-1279-incorrect-recording-getmetatable.test.lua
new file mode 100644
index 00000000..8bf22ca7
--- /dev/null
+++ b/test/tarantool-tests/lj-1279-incorrect-recording-getmetatable.test.lua
@@ -0,0 +1,21 @@
+local tap = require('tap')
+
+local test = tap.test('lj-1279-incorrect-recording-getmetatable')
+test:plan(1)
+
+-- A test file to demonstrate an incorrect recording of
+-- getmetatable() for I/O handlers.
+-- https://github.com/LuaJIT/LuaJIT/issues/1279
+
+jit.opt.start("hotloop=1")
+
+local obj = io.stdout
+local getmetatable = getmetatable
+
+for _ = 1, 4 do
+  _ = getmetatable(obj)
+end
+
+test:ok(true, 'getmetatable() recording is correct')
+
+test:done(true)
--------------6fIYKoas9MWA4bkJnRbbHoTv--