From e613105ca92fe25e7bd63031b409faa8c908ac35 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Fri, 20 Mar 2020 13:35:49 +0100 Subject: [PATCH] Fix write barrier for lua_setupvalue() and debug.setupvalue(). --- src/lj_api.c | 8 +++++--- src/lj_debug.c | 7 +++++-- src/lj_debug.h | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/lj_api.c b/src/lj_api.c index e2d7e533..1a34a774 100644 --- a/src/lj_api.c +++ b/src/lj_api.c @@ -841,7 +841,8 @@ LUA_API int lua_next(lua_State *L, int idx) LUA_API const char *lua_getupvalue(lua_State *L, int idx, int n) { TValue *val; - const char *name = lj_debug_uvnamev(index2adr(L, idx), (uint32_t)(n-1), &val); + GCobj *o; + const char *name = lj_debug_uvnamev(index2adr(L, idx), (uint32_t)(n-1), &val, &o); if (name) { copyTV(L, L->top, val); incr_top(L); @@ -1014,13 +1015,14 @@ LUA_API const char *lua_setupvalue(lua_State *L, int idx, int n) { cTValue *f = index2adr(L, idx); TValue *val; + GCobj *o; const char *name; api_checknelems(L, 1); - name = lj_debug_uvnamev(f, (uint32_t)(n-1), &val); + name = lj_debug_uvnamev(f, (uint32_t)(n-1), &val, &o); if (name) { L->top--; copyTV(L, val, L->top); - lj_gc_barrier(L, funcV(f), L->top); + lj_gc_barrier(L, o, L->top); } return name; } diff --git a/src/lj_debug.c b/src/lj_debug.c index 04fecfaf..1d73da7e 100644 --- a/src/lj_debug.c +++ b/src/lj_debug.c @@ -235,19 +235,22 @@ const char *lj_debug_uvname(GCproto *pt, uint32_t idx) } /* Get name and value of upvalue. */ -const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp) +const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp, GCobj **op) { if (tvisfunc(o)) { GCfunc *fn = funcV(o); if (isluafunc(fn)) { GCproto *pt = funcproto(fn); if (idx < pt->sizeuv) { - *tvp = uvval(&gcref(fn->l.uvptr[idx])->uv); + GCobj *uvo = gcref(fn->l.uvptr[idx]); + *tvp = uvval(&uvo->uv); + *op = uvo; return lj_debug_uvname(pt, idx); } } else { if (idx < fn->c.nupvalues) { *tvp = &fn->c.upvalue[idx]; + *op = obj2gco(fn); return ""; } } diff --git a/src/lj_debug.h b/src/lj_debug.h index 75ea927c..43fb9c19 100644 --- a/src/lj_debug.h +++ b/src/lj_debug.h @@ -29,7 +29,8 @@ typedef struct lj_Debug { LJ_FUNC cTValue *lj_debug_frame(lua_State *L, int level, int *size); LJ_FUNC BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc); LJ_FUNC const char *lj_debug_uvname(GCproto *pt, uint32_t idx); -LJ_FUNC const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp); +LJ_FUNC const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp, + GCobj **op); LJ_FUNC const char *lj_debug_slotname(GCproto *pt, const BCIns *pc, BCReg slot, const char **name); LJ_FUNC const char *lj_debug_funcname(lua_State *L, TValue *frame,