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 9E7D519F8E7E; Mon, 30 Mar 2026 11:08:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9E7D519F8E7E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1774858112; bh=/fc4WabT4xlTqithpN8/0wGabPYHM6s3mtPfmkh8b1E=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=jBMuMKAxCX4Q3qwAovYnm6fF7UitJwOqikUuSg1IQR8SO4Z4CADp2TANrlSRddqFA g1NAjFSYK2btq5tL6dGB+iq+a6P97kbGmX5uqqoqXRiBe79WJ0jVE8+UmMZX38/xFb GS9fV0c+1ifHCUiSIVIVi4eK31htfkZLHbC3JH+E= Received: from send129.i.mail.ru (send129.i.mail.ru [89.221.237.224]) (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 BA57819F8E76 for ; Mon, 30 Mar 2026 11:08:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BA57819F8E76 Received: by exim-smtp-74865f89dd-8v62s with esmtpa (envelope-from ) id 1w77fi-00000000KPo-2wfk; Mon, 30 Mar 2026 11:08:31 +0300 Content-Type: multipart/alternative; boundary="------------Lz9DexvpBBBrm3lHGwuWsnnz" Message-ID: Date: Mon, 30 Mar 2026 11:08:29 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org References: <97ef9d8e0cbd59df6ef18a57dd44554f44c12129.1774711616.git.skaplun@tarantool.org> In-Reply-To: <97ef9d8e0cbd59df6ef18a57dd44554f44c12129.1774711616.git.skaplun@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9BB347BE606964F7AB0E609D9D3D1EE2546E160D0675A0FC0182A05F53808504071AACEDA77AF9CA53DE06ABAFEAF67053A829BEAF44430D7D6678086EE4F03ECB9E10611ADFA1AB1 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70312E9A300D47E3BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB55337566B07F865632A725849DCBB89448A8DC9B9003C0346D1AD0E7792D71E7316429D8389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0D9442B0B5983000E8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B652D31B9D28593E51CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB86D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE73349F3DFB73D9B11731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A5FEB17482EFC26B0D5002B1117B3ED696E69864298746981292B673A2F5DDD7E7823CB91A9FED034534781492E4B8EEAD3CCD70CEBBF18A22BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE191716CD42B3DD1D34CAB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D659AD5E8C4BFB48D7F81261E159D10CEF2529F3DB3B631FE7BABFB3FBFB17DACFB55E4EFECF0AB3A6ACB8341EE9D5BE9A0AD8EB195DB9781904AA285E3D0791854E287538D3F217A9088CD93680B12512CF4C41F94D744909CE2512F26BEC029E55448553D2254B8D95CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVdx/hWl0/CTm5otpQSKTPHI= X-Mailru-Sender: 689FA8AB762F7393520AF17B8A65FDE288EC87CDFCA5EE4FFE2A1D66BA07FB9E68E5EE0E27B1F7C4EF86D5F70DA33880E41E8EF7A07863ECB274557F927329BE2DDF8182D28ACDB545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 2/2] Fix VM event error handling for finalizers. 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. --------------Lz9DexvpBBBrm3lHGwuWsnnz Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Sergey! thanks for the patch! LGTM with a couple of comments below Sergey On 3/28/26 18:31, Sergey Kaplun wrote: > From: Mike Pall > > Reported by Sergey Kaplun. > > (cherry picked from commit fbb36bb6bfa88716a47c58bcf9ce9f2ef752abac) > > After the previous commit, the VM handler for the 'errfin' VM event > works incorrectly. The error object is taken not from the stack on which > the VM handler is invoked. Hence, it breaks the non-VM stack and returns > an incorrect error message. > > This patch fixes the issue by copying the object from the corresponding > Lua stack. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#12134 > --- > src/lj_gc.c | 6 +++-- > .../lj-1445-errfin-errmsg.test.lua | 27 +++++++++++++++++++ > 2 files changed, 31 insertions(+), 2 deletions(-) > create mode 100644 test/tarantool-tests/lj-1445-errfin-errmsg.test.lua > > diff --git a/src/lj_gc.c b/src/lj_gc.c > index 83ad9ee9..7e4f0a47 100644 > --- a/src/lj_gc.c > +++ b/src/lj_gc.c > @@ -519,10 +519,12 @@ static void gc_call_finalizer(global_State *g, lua_State *L, > if (LJ_HASPROFILE && (oldh & HOOK_PROFILE)) lj_dispatch_update(g); > g->gc.threshold = oldt; /* Restore GC threshold. */ > if (errcode) { > + TValue tmp; > + copyTV(VL, &tmp, VL->top-1); > + VL->top--; > lj_vmevent_send(g, ERRFIN, > - copyTV(V, V->top++, L->top-1); > + copyTV(V, V->top++, &tmp); > ); > - L->top--; > } > } > > diff --git a/test/tarantool-tests/lj-1445-errfin-errmsg.test.lua b/test/tarantool-tests/lj-1445-errfin-errmsg.test.lua > new file mode 100644 > index 00000000..def8b79c > --- /dev/null > +++ b/test/tarantool-tests/lj-1445-errfin-errmsg.test.lua > @@ -0,0 +1,27 @@ > +local tap = require('tap') > +local test = tap.test('lj-1445-errfin-errmsg') > + Usually you add a comment with test description and a link to the issue. But this time a comment is absent. Should we add it? > +test:plan(2) > + > +local EXPECTED_ERR = 'expected err' s/err/error/ feel free to ignore > +local function bad_fin() > + error(EXPECTED_ERR) > +end > +local EXPECTED_LOCATION = debug.getinfo(bad_fin).linedefined + 1 > + > +local match_err = false > +local match_line = false > +local function errfin_handler(errmsg) > + match_err =errmsg:match(EXPECTED_ERR) > + match_line =errmsg:match(EXPECTED_LOCATION) > +end > + > +jit.attach(errfin_handler, 'errfin') > + > +debug.getmetatable(newproxy(true)).__gc = bad_fin I would define userdata previously for clarity: local ud = newproxy(true) and then use it in getmetatable(). feel free to ignore > +collectgarbage() > + > +test:ok(match_err, 'correct error message in errfin handler') > +test:ok(match_line, 'correct source line in errfin handler') > + > +test:done(true) --------------Lz9DexvpBBBrm3lHGwuWsnnz Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hi, Sergey!

thanks for the patch! LGTM with a couple of comments below

Sergey

On 3/28/26 18:31, Sergey Kaplun wrote:
From: Mike Pall <mike>

Reported by Sergey Kaplun.

(cherry picked from commit fbb36bb6bfa88716a47c58bcf9ce9f2ef752abac)

After the previous commit, the VM handler for the 'errfin' VM event
works incorrectly. The error object is taken not from the stack on which
the VM handler is invoked. Hence, it breaks the non-VM stack and returns
an incorrect error message.

This patch fixes the issue by copying the object from the corresponding
Lua stack.

Sergey Kaplun:
* added the description and the test for the problem

Part of tarantool/tarantool#12134
---
 src/lj_gc.c                                   |  6 +++--
 .../lj-1445-errfin-errmsg.test.lua            | 27 +++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 test/tarantool-tests/lj-1445-errfin-errmsg.test.lua

diff --git a/src/lj_gc.c b/src/lj_gc.c
index 83ad9ee9..7e4f0a47 100644
--- a/src/lj_gc.c
+++ b/src/lj_gc.c
@@ -519,10 +519,12 @@ static void gc_call_finalizer(global_State *g, lua_State *L,
   if (LJ_HASPROFILE && (oldh & HOOK_PROFILE)) lj_dispatch_update(g);
   g->gc.threshold = oldt;  /* Restore GC threshold. */
   if (errcode) {
+    TValue tmp;
+    copyTV(VL, &tmp, VL->top-1);
+    VL->top--;
     lj_vmevent_send(g, ERRFIN,
-      copyTV(V, V->top++, L->top-1);
+      copyTV(V, V->top++, &tmp);
     );
-    L->top--;
   }
 }
 
diff --git a/test/tarantool-tests/lj-1445-errfin-errmsg.test.lua b/test/tarantool-tests/lj-1445-errfin-errmsg.test.lua
new file mode 100644
index 00000000..def8b79c
--- /dev/null
+++ b/test/tarantool-tests/lj-1445-errfin-errmsg.test.lua
@@ -0,0 +1,27 @@
+local tap = require('tap')
+local test = tap.test('lj-1445-errfin-errmsg')
+

Usually you add a comment with test description and a link to the issue.

But this time a comment is absent. Should we add it?

+test:plan(2)
+
+local EXPECTED_ERR = 'expected err'

s/err/error/

feel free to ignore

+local function bad_fin()
+  error(EXPECTED_ERR)
+end
+local EXPECTED_LOCATION = debug.getinfo(bad_fin).linedefined + 1
+
+local match_err = false
+local match_line = false
+local function errfin_handler(errmsg)
+  match_err = errmsg:match(EXPECTED_ERR)
+  match_line = errmsg:match(EXPECTED_LOCATION)
+end
+
+jit.attach(errfin_handler, 'errfin')
+
+debug.getmetatable(newproxy(true)).__gc = bad_fin

I would define userdata previously for clarity:

local ud = newproxy(true)

and then use it in getmetatable().

feel free to ignore


+collectgarbage()
+
+test:ok(match_err, 'correct error message in errfin handler')
+test:ok(match_line, 'correct source line in errfin handler')
+
+test:done(true)
--------------Lz9DexvpBBBrm3lHGwuWsnnz--