[Tarantool-patches] [PATCH luajit 3/3] Fix state restore when recording __concat metamethod.

Sergey Bronnikov sergeyb at tarantool.org
Wed Mar 12 10:53:54 MSK 2025


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);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.tarantool.org/pipermail/tarantool-patches/attachments/20250312/0bcb894e/attachment.htm>


More information about the Tarantool-patches mailing list