From 9e6807c3c9d5036e999f636f936df07b72284442 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 22 Jul 2019 09:41:10 -0300 Subject: Do not collect open upvalues Open upvalues are kept alive together with their corresponding stack. This change makes a simpler and safer fix to the issue in commit 440a5ee78c8, about upvalues in the list of open upvalues being collected while others are being created. (That previous fix may not be correct.) --- lfunc.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'lfunc.c') diff --git a/lfunc.c b/lfunc.c index f7edf56b..6f2f897f 100644 --- a/lfunc.c +++ b/lfunc.c @@ -83,21 +83,20 @@ static UpVal *newupval (lua_State *L, int tbc, StkId level, UpVal **prev) { /* ** Find and reuse, or create if it does not exist, an upvalue -** at the given level and set it to the given slot. +** at the given level. */ -void luaF_setupval (lua_State *L, StkId level, UpVal **slot) { +UpVal *luaF_findupval (lua_State *L, StkId level) { UpVal **pp = &L->openupval; UpVal *p; lua_assert(isintwups(L) || L->openupval == NULL); while ((p = *pp) != NULL && uplevel(p) >= level) { /* search for it */ - *slot = p; - if (uplevel(p) == level && !isdead(G(L), p)) /* corresponding upvalue? */ - return; /* found it */ + lua_assert(!isdead(G(L), p)); + if (uplevel(p) == level) /* corresponding upvalue? */ + return p; /* return it */ pp = &p->u.open.next; } - /* not found: create a new upvalue after 'pp' (which is - anchored in 'slot', in case of an emergency collection) */ - *slot = newupval(L, 0, level, pp); + /* not found: create a new upvalue after 'pp' */ + return newupval(L, 0, level, pp); } -- cgit v1.2.3-55-g6feb