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 02D34128FED5; Wed, 12 Mar 2025 10:53:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 02D34128FED5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1741766037; bh=WDj0qz0Nkxl/FspUAaelo0LGOr5wvy7VDvW6T1RvYw4=; 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=vqef2J5L23UEepl0Y2gTVjruS0amOKC5VmbNf6vfSNkOCvR6R3YqHEsZR5O+O0V+L zPOs4rOwsvexBX4ppblJyYCpxQpXp0Iab/mbUc/5ihwjwDo2Be1j3o6tsNOqQc79g/ Eao28E1XabtDAdPpl4R/ChjkU6q0kMuBxvpylugA= Received: from send173.i.mail.ru (send173.i.mail.ru [95.163.59.12]) (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 58056128FECB for ; Wed, 12 Mar 2025 10:53:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 58056128FECB Received: by exim-smtp-69cc44787d-75dmx with esmtpa (envelope-from ) id 1tsGuY-00000000VlP-1KZs; Wed, 12 Mar 2025 10:53:54 +0300 Content-Type: multipart/alternative; boundary="------------iEqELhAIGnUfqeGV7wj0lmX0" Message-ID: <21c40859-1aeb-4152-a5d6-4f82a4c8f5fe@tarantool.org> Date: Wed, 12 Mar 2025 10:53:54 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org References: <47c0d447e3d2a49da2678bf065da1a55eae0e9c3.1741617766.git.skaplun@tarantool.org> In-Reply-To: <47c0d447e3d2a49da2678bf065da1a55eae0e9c3.1741617766.git.skaplun@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD96E8ECD36702C4DEF957F0DAD6594B9EF389ADCF0F8111D9C182A05F5380850401559CDCA9F5DB2B33DE06ABAFEAF670512DE54A0587BD3D558D5350A5789AE9D1AD6A186BD11839C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE736691C7D10565E03C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6759CC434672EE6371C2A783ECEC0211ADC4224003CC836476D5A39DEEDB180909611E41BBFE2FEB2B454B485BCA22F61C41BF0FA5DA927AC742D67C96820F3D0B118C0E3ECF93B5289FA2833FD35BB23D9E625A9149C048EE33AC447995A7AD18BDFBBEFFF4125B51D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B5FC25ED3FCEC3375A471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FCE31AAB7FF4261FD93AA81AA40904B5D9CF19DD082D7633A0C84D3B47A649675F3AA81AA40904B5D98AA50765F79006375A3BF3EE4266CDCED81D268191BDAD3D3666184CF4C3C14F3FC91FA280E0CE3D1A620F70A64A45A98AA50765F79006372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F616AD31D0D18CD5CCE5475246E174218B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A5606CCE5EF0C241A35002B1117B3ED69650A86B257AEF0BE4B91D2EB2DEE3878C823CB91A9FED034534781492E4B8EEAD85CCBA673D36D1A4BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF8BD6FF875D7ED42325B263082CACB2780CE20BF79936B13874C581D761DFF11A1EB2640544212C895FC880DB409560E6CBE1E6C483838D5E036984C909133F55FB4EE787A5C305F5111DC66A97D0BFE2913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVQiWK+2I7Y2sYCZl8QBpod4= X-Mailru-Sender: 520A125C2F17F0B1E52FEF5D219D6140BFFF3BAEA893667BB4227B83FC9362CB325E41A4B7E1CA3C0152A3D17938EB451EB5A0BCEC6A560B3DDE9B364B0DF289BE2DA36745F2EEB5CEBA01FB949A1F1EEAB4BC95F72C04283CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 3/3] Fix state restore when recording __concat metamethod. 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. --------------iEqELhAIGnUfqeGV7wj0lmX0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Sergey, thanks for the patch! LGTM wit ha minor comment. Sergey On 10.03.2025 17:51, Sergey Kaplun wrote: > From: Mike Pall > > Reported by Sergey Kaplun. > > (cherry picked from commit eee16efa77b542e99c8e546a3d52fc023925c7bc) > > This commit is a follow-up to the previous one. It fixes the case when > the `topslot` is adjusting for simple concatenation results. This patch > adds the update of the corresponding Lua stack slots to be restored. > > This fixes back the test. > > Sergey Kaplun: > * added the description and the test for the problem It is partially true actually :) s/and the test// > > Part of tarantool/tarantool#11055 > --- > src/lj_record.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/src/lj_record.c b/src/lj_record.c > index 7a481a51..92cf55e4 100644 > --- a/src/lj_record.c > +++ b/src/lj_record.c > @@ -1942,6 +1942,7 @@ static TRef rec_tnew(jit_State *J, uint32_t ah) > /* -- Concatenation ------------------------------------------------------- */ > > typedef struct RecCatDataCP { > + TValue savetv[5+LJ_FR2]; > jit_State *J; > BCReg baseslot, topslot; > TRef tr; > @@ -1982,7 +1983,9 @@ static TValue *rec_mm_concat_cp(lua_State *L, lua_CFunction dummy, void *ud) > return NULL; > } > /* Pass partial result. */ > - topslot = J->maxslot--; > + rcd->topslot = topslot = J->maxslot--; > + /* Save updated range of slots. */ > + memcpy(rcd->savetv, &L->base[topslot-1], sizeof(rcd->savetv)); > *xbase = tr; > top = xbase; > setstrV(J->L, &ix.keyv, &J2G(J)->strempty); /* Simulate string result. */ > @@ -2002,16 +2005,18 @@ static TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot) > { > lua_State *L = J->L; > ptrdiff_t delta = L->top - L->base; > - TValue savetv[5+LJ_FR2], errobj; > + TValue errobj; > RecCatDataCP rcd; > int errcode; > rcd.J = J; > rcd.baseslot = baseslot; > rcd.topslot = topslot; > - memcpy(savetv, &L->base[topslot-1], sizeof(savetv)); /* Save slots. */ > + /* Save slots. */ > + memcpy(rcd.savetv, &L->base[topslot-1], sizeof(rcd.savetv)); > errcode = lj_vm_cpcall(L, NULL, &rcd, rec_mm_concat_cp); > if (errcode) copyTV(L, &errobj, L->top-1); > - memcpy(&L->base[topslot-1], savetv, sizeof(savetv)); /* Restore slots. */ > + /* Restore slots. */ > + memcpy(&L->base[rcd.topslot-1], rcd.savetv, sizeof(rcd.savetv)); > if (errcode) { > L->top = L->base + delta; > copyTV(L, L->top++, &errobj); --------------iEqELhAIGnUfqeGV7wj0lmX0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hi, Sergey,

thanks for the patch! LGTM wit ha minor comment.

Sergey

On 10.03.2025 17:51, Sergey Kaplun wrote:
From: Mike Pall <mike>

Reported by Sergey Kaplun.

(cherry picked from commit eee16efa77b542e99c8e546a3d52fc023925c7bc)

This commit is a follow-up to the previous one. It fixes the case when
the `topslot` is adjusting for simple concatenation results. This patch
adds the update of the corresponding Lua stack slots to be restored.

This fixes back the <lj-839-concat-recording.test.lua> test.

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

It is partially true actually :)

s/and the test//


Part of tarantool/tarantool#11055
---
 src/lj_record.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/lj_record.c b/src/lj_record.c
index 7a481a51..92cf55e4 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -1942,6 +1942,7 @@ static TRef rec_tnew(jit_State *J, uint32_t ah)
 /* -- Concatenation ------------------------------------------------------- */
 
 typedef struct RecCatDataCP {
+  TValue savetv[5+LJ_FR2];
   jit_State *J;
   BCReg baseslot, topslot;
   TRef tr;
@@ -1982,7 +1983,9 @@ static TValue *rec_mm_concat_cp(lua_State *L, lua_CFunction dummy, void *ud)
       return NULL;
     }
     /* Pass partial result. */
-    topslot = J->maxslot--;
+    rcd->topslot = topslot = J->maxslot--;
+    /* Save updated range of slots. */
+    memcpy(rcd->savetv, &L->base[topslot-1], sizeof(rcd->savetv));
     *xbase = tr;
     top = xbase;
     setstrV(J->L, &ix.keyv, &J2G(J)->strempty);  /* Simulate string result. */
@@ -2002,16 +2005,18 @@ static TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot)
 {
   lua_State *L = J->L;
   ptrdiff_t delta = L->top - L->base;
-  TValue savetv[5+LJ_FR2], errobj;
+  TValue errobj;
   RecCatDataCP rcd;
   int errcode;
   rcd.J = J;
   rcd.baseslot = baseslot;
   rcd.topslot = topslot;
-  memcpy(savetv, &L->base[topslot-1], sizeof(savetv));  /* Save slots. */
+  /* Save slots. */
+  memcpy(rcd.savetv, &L->base[topslot-1], sizeof(rcd.savetv));
   errcode = lj_vm_cpcall(L, NULL, &rcd, rec_mm_concat_cp);
   if (errcode) copyTV(L, &errobj, L->top-1);
-  memcpy(&L->base[topslot-1], savetv, sizeof(savetv));  /* Restore slots. */
+  /* Restore slots. */
+  memcpy(&L->base[rcd.topslot-1], rcd.savetv, sizeof(rcd.savetv));
   if (errcode) {
     L->top = L->base + delta;
     copyTV(L, L->top++, &errobj);
--------------iEqELhAIGnUfqeGV7wj0lmX0--