mirror of
https://github.com/lua/lua
synced 2026-09-27 00:28:25 +03:00
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 440a5ee78c, about upvalues in the list of open upvalues
being collected while others are being created. (That previous fix
may not be correct.)
This commit is contained in:
parent
2f22c6bb79
commit
9e6807c3c9
4 changed files with 11 additions and 14 deletions
15
lfunc.c
15
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue