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 81C41E22E80; Tue, 10 Dec 2024 12:33:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 81C41E22E80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1733823205; bh=vVQ0dedPK2Edo33QB6GIoG0JwpClduosqH6QXoTV4F8=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=zjYk7sQLxCMXioH3j6tlLvN8bVCObeWnU1z9Hx3yAzJPJEIyUyaZHtcpKhV3DyLsL 5OMv517OdVAI3SgK46aukKyk1Vr8xIZaNDa5glIJ6/xxd4mes76UumZwF+gpZYPg67 hbJDpm6UXBKP97TB2PKO+M82JRR1WZm+2/C8I7Vs= Received: from send196.i.mail.ru (send196.i.mail.ru [95.163.59.35]) (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 C112FE22E80 for ; Tue, 10 Dec 2024 12:33:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C112FE22E80 Received: by exim-smtp-5c4b5c69d5-2shp7 with esmtpa (envelope-from ) id 1tKwcN-00000000Fx7-2EDp; Tue, 10 Dec 2024 12:33:23 +0300 Date: Tue, 10 Dec 2024 12:32:28 +0300 To: Sergey Bronnikov Message-ID: References: <76c9c163c365aec70741162ab83fdfa6385a9118.1730976041.git.sergeyb@tarantool.org> <19c0c442-68a9-4181-8424-7d3e202289f9@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <19c0c442-68a9-4181-8424-7d3e202289f9@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9A2BFDE4DD2630CDA5C8AB80D2BA15CF2757296B8134AEA3D182A05F5380850404C228DA9ACA6FE276D3501D7288608153DE06ABAFEAF67051C97C27AE5C5CBFC5548549583E8E03CB6BD4AB1FA1FD0A3 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74162CA13069782AFEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063750AD27396E031BA88638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8BF07052AFD01A6425A2F10ED37C5FCAAA0B87CC5E8490792CC7F00164DA146DAFE8445B8C89999728AA50765F7900637712AAB6D9D366D8A389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC886A7C529F68B8E5CF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE33AC447995A7AD182BEBFE083D3B9BA73A03B725D353964B2FFDA4F57982C5F435872C767BF85DA227C277FBC8AE2E8B9149C560DC76099D75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A5B4D8175776050A225002B1117B3ED6966B58C1369024C4678D59E407A97E9958823CB91A9FED034534781492E4B8EEAD8D8BB953E4894305BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFB58BC97A07E26194147142211A6C42C6C425F752BDF22E8E34FACEA8233557440F85117B495E935B5C69F0120C2109DF6530D1256AC936B899139351986DDEEBA64874FEE5CE2B50C226CC413062362A913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojwdtfQel0s3mk/7d9PjD5EQ== X-DA7885C5: 0CCE1E8B031F2985F255D290C0D534F948A08A3A2E74301CC1D47984BA7625EF48CE2183E60664FA5B1A4C17EAA7BC4BEF2421ABFA55128DAF83EF9164C44C7E X-Mailru-Sender: 689FA8AB762F739381B31377CF4CA219A1A2E8D02C0AE5AAB5616A04957600F34EC7226B1ECD29DCE49D44BB4BD9522A059A1ED8796F048DB274557F927329BE89D5A3BC2B10C37545BD1C3CC395C826B4A721A3011E896F 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 Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: Sergey Bronnikov , tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the fixes! LGTM, after fixing a bunch of comments below. > 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..dc01307e > --- /dev/null > +++ b/test/tarantool-tests/lj-1279-incorrect-recording-getmetatable.test.lua > @@ -0,0 +1,74 @@ > +local tap = require('tap') > +-- A test file to demonstrate an incorrect recording of > +-- `getmetatable()` for I/O handlers. > +-- https://github.com/LuaJIT/LuaJIT/issues/1279 > +local test = tap.test('lj-1279-incorrect-recording-getmetatable'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +test:plan(6) > + > +jit.opt.start('hotloop=1') > + > +local ud_io_file = io.stdout > +local getmetatable = getmetatable > + > +local function rec_getmetatable(obj) > + local res > + for _ = 1, 4 do > + res = getmetatable(obj) > + end > + return res > +end > + > +-- The testcase to demonstrate a problem by comparing metatable Typo: s/metatable/the metatable/ > +-- returned by two versions of `getmetatable()`: compiled and not. > + > +local mt_orig = debug.getmetatable(ud_io_file) > +assert(type(mt_orig) == 'table') > + > +local mt_rec = {} > +for i = 1, 4 do > + mt_rec[i] = getmetatable(ud_io_file) > +end > +mt_rec[5] = mt_orig > + > +test:ok(true, 'getmetatable() recording is correct') > +test:samevalues(mt_rec, 'metatables are the same') > + > +-- Restore metatable. > +debug.setmetatable(ud_io_file, mt_orig) > +assert(type(mt_orig) == 'table') This restoring is excess since we don't change the metatable yet. > + > +-- The testcase to demonstrate a problem by setting metatable for Typo: s/metatable/the metatable/ > +-- `io.stdout` to a string. > + > +-- Compile `getmetatable()`, it is expected metatable has > +-- a `table` type. > +rec_getmetatable(ud_io_file) > +-- Set a custom metatable to a string. Minor: I would rephrase this like the following: | Set IO metatable to a string. "Custom" isn't clear for me. > +local mt = 'IO metatable' > +getmetatable(ud_io_file).__metatable = mt > +test:is(getmetatable(ud_io_file), mt, 'getmetatable() is correct') > +test:is(rec_getmetatable(ud_io_file), mt, 'compiled getmetatable() is correct') > + > +-- Restore metatable. > +debug.setmetatable(ud_io_file, mt_orig) > +assert(type(mt_orig) == 'table') It is better also to restore the JIT state here, ie. call `jit.flush()` and reset hotcounters via `jit.opt.start('hotloop=1')` to be in sync with the code (we want to compile a trace again). > + > +-- The testcase to demonstrate a problem by removing metatable for Typo: s/metatable/the metatable/ > +-- `io.stdout` and calling garbage collector. Typo: s/garbage collector/the garbage collector/ > + > +-- Compile `getmetatable()`, it is expected metatable has > +-- a `table` type. > +rec_getmetatable(ud_io_file) > +-- Delete metatable. > +debug.setmetatable(ud_io_file, nil) > +collectgarbage() > +test:is(getmetatable(ud_io_file), nil, 'getmetatable() is correct') > +test:is(rec_getmetatable(ud_io_file), nil, 'compiled getmetatable() is correct') > + > +-- Restore metatable. > +debug.setmetatable(ud_io_file, mt_orig) > + > +test:done(true) On 22.11.24, Sergey Bronnikov wrote: > Hi, Sergey, > > please see below. > > Updated version has been force-pushed. > > Sergey > > >> > > [1]:https://github.com/LuaJIT/LuaJIT/issues/1279#issuecomment-2382392847 > > -- Best regards, Sergey Kaplun