diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-22 09:41:10 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-22 09:41:10 -0300 |
commit | 9e6807c3c9d5036e999f636f936df07b72284442 (patch) | |
tree | 39100fb44792114905f00d1b638212f620d12a25 /lfunc.c | |
parent | 2f22c6bb79d209a55b3fc8e0b2d9c9f89f038174 (diff) | |
download | lua-9e6807c3c9d5036e999f636f936df07b72284442.tar.gz lua-9e6807c3c9d5036e999f636f936df07b72284442.tar.bz2 lua-9e6807c3c9d5036e999f636f936df07b72284442.zip |
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.)
Diffstat (limited to 'lfunc.c')
-rw-r--r-- | lfunc.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -83,21 +83,20 @@ static UpVal *newupval (lua_State *L, int tbc, StkId level, UpVal **prev) { | |||
83 | 83 | ||
84 | /* | 84 | /* |
85 | ** Find and reuse, or create if it does not exist, an upvalue | 85 | ** Find and reuse, or create if it does not exist, an upvalue |
86 | ** at the given level and set it to the given slot. | 86 | ** at the given level. |
87 | */ | 87 | */ |
88 | void luaF_setupval (lua_State *L, StkId level, UpVal **slot) { | 88 | UpVal *luaF_findupval (lua_State *L, StkId level) { |
89 | UpVal **pp = &L->openupval; | 89 | UpVal **pp = &L->openupval; |
90 | UpVal *p; | 90 | UpVal *p; |
91 | lua_assert(isintwups(L) || L->openupval == NULL); | 91 | lua_assert(isintwups(L) || L->openupval == NULL); |
92 | while ((p = *pp) != NULL && uplevel(p) >= level) { /* search for it */ | 92 | while ((p = *pp) != NULL && uplevel(p) >= level) { /* search for it */ |
93 | *slot = p; | 93 | lua_assert(!isdead(G(L), p)); |
94 | if (uplevel(p) == level && !isdead(G(L), p)) /* corresponding upvalue? */ | 94 | if (uplevel(p) == level) /* corresponding upvalue? */ |
95 | return; /* found it */ | 95 | return p; /* return it */ |
96 | pp = &p->u.open.next; | 96 | pp = &p->u.open.next; |
97 | } | 97 | } |
98 | /* not found: create a new upvalue after 'pp' (which is | 98 | /* not found: create a new upvalue after 'pp' */ |
99 | anchored in 'slot', in case of an emergency collection) */ | 99 | return newupval(L, 0, level, pp); |
100 | *slot = newupval(L, 0, level, pp); | ||
101 | } | 100 | } |
102 | 101 | ||
103 | 102 | ||