From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Sergey Kaplun <skaplun@tarantool.org>, Maxim Kokryashkin <m.kokryashkin@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH luajit] Restore state when recording __concat metamethod throws an error. Date: Fri, 13 Sep 2024 16:07:03 +0300 [thread overview] Message-ID: <695c49d0-f2f0-4cfb-b5d3-e4ac52d1f455@tarantool.org> (raw) In-Reply-To: <20240821082316.4880-1-skaplun@tarantool.org> [-- Attachment #1: Type: text/plain, Size: 1796 bytes --] Hi, Sergey, thanks for the patch! LGTM with a minor comment. See below. On 21.08.2024 11:23, Sergey Kaplun wrote: <snipped> > diff --git a/test/tarantool-tests/lj-1234-err-in-record-concat.test.lua b/test/tarantool-tests/lj-1234-err-in-record-concat.test.lua > new file mode 100644 > index 00000000..9abaeba5 > --- /dev/null > +++ b/test/tarantool-tests/lj-1234-err-in-record-concat.test.lua > @@ -0,0 +1,43 @@ > +local tap = require('tap') > + > +-- Test file to demonstrate the crash during the concat recording > +-- if it throws an error. > +-- See also:https://github.com/LuaJIT/LuaJIT/issues/1234. > + > +local test = tap.test('lj-1234-err-in-record-concat'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +test:plan(2) > + > +jit.opt.start('hotloop=1') > + > +local __concat = function(v1, v2) > + return tostring(v1) .. tostring(v2) > +end > + > +-- Need to use metamethod call in the concat recording. > +debug.setmetatable(nil, { I propose to add a comment that explain why `nil` is used here. > + __concat = __concat, > +}) > + > +local function test_concat_p() > + local counter = 0 > + while counter < 1 do > + counter = counter + 1 > + -- The first result is placed on the Lua stack before the > + -- error is raised. When the error is raised, it is handled by > + -- the trace recorder, but since neither `rec_cat()` nor > + -- `lj_record_ret()` restore the Lua stack (before the patch), > + -- it becomes unbalanced after the instruction recording > + -- attempt. > + local _ = {} .. (nil .. nil) > + end > +end > + > +local result, errmsg = pcall(test_concat_p) > + > +test:ok(not result, 'the error is raised') > +test:like(errmsg, 'attempt to concatenate a table value', 'correct error') > + > +test:done(true) [-- Attachment #2: Type: text/html, Size: 2467 bytes --]
next prev parent reply other threads:[~2024-09-13 13:07 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-08-21 8:23 Sergey Kaplun via Tarantool-patches 2024-09-13 13:07 ` Sergey Bronnikov via Tarantool-patches [this message] 2024-09-13 15:27 ` Sergey Kaplun via Tarantool-patches 2024-09-13 15:48 ` Sergey Kaplun via Tarantool-patches 2024-09-17 6:33 ` Sergey Bronnikov via Tarantool-patches 2024-09-23 6:30 ` Maxim Kokryashkin via Tarantool-patches 2024-10-18 15:14 ` Sergey Kaplun via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=695c49d0-f2f0-4cfb-b5d3-e4ac52d1f455@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=m.kokryashkin@tarantool.org \ --cc=sergeyb@tarantool.org \ --cc=skaplun@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH luajit] Restore state when recording __concat metamethod throws an error.' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox