Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Bronnikov <sergeyb@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH luajit 3/3] Fix state restore when recording __concat metamethod.
Date: Mon, 10 Mar 2025 17:51:37 +0300	[thread overview]
Message-ID: <47c0d447e3d2a49da2678bf065da1a55eae0e9c3.1741617766.git.skaplun@tarantool.org> (raw)
In-Reply-To: <cover.1741617766.git.skaplun@tarantool.org>

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

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);
-- 
2.48.1


  parent reply	other threads:[~2025-03-10 14:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-10 14:51 [Tarantool-patches] [PATCH luajit 0/3] Fixes for the concat metamethod Sergey Kaplun via Tarantool-patches
2025-03-10 14:51 ` [Tarantool-patches] [PATCH luajit 1/3] test: unify helpers for a custom allocator setting Sergey Kaplun via Tarantool-patches
2025-03-11 11:32   ` Sergey Bronnikov via Tarantool-patches
2025-03-11 12:38     ` Sergey Kaplun via Tarantool-patches
2025-03-11 14:45       ` Sergey Bronnikov via Tarantool-patches
2025-03-10 14:51 ` [Tarantool-patches] [PATCH luajit 2/3] Restore state when recording __concat metamethod throws OOM Sergey Kaplun via Tarantool-patches
2025-03-11 12:01   ` Sergey Bronnikov via Tarantool-patches
2025-03-11 12:37     ` Sergey Kaplun via Tarantool-patches
2025-03-11 14:46       ` Sergey Bronnikov via Tarantool-patches
2025-03-10 14:51 ` Sergey Kaplun via Tarantool-patches [this message]
2025-03-12  7:53   ` [Tarantool-patches] [PATCH luajit 3/3] Fix state restore when recording __concat metamethod Sergey Bronnikov via Tarantool-patches
2025-03-13 10:28     ` Sergey Kaplun via Tarantool-patches
2025-03-14 10:53       ` Sergey Bronnikov via Tarantool-patches
2025-03-26  8:55 ` [Tarantool-patches] [PATCH luajit 0/3] Fixes for the concat metamethod 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=47c0d447e3d2a49da2678bf065da1a55eae0e9c3.1741617766.git.skaplun@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=sergeyb@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 3/3] Fix state restore when recording __concat metamethod.' \
    /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