diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-10-14 15:46:58 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-10-14 15:46:58 -0300 |
commit | 52c86797608f1bf927be5bab1e9b97b7d35bdf2c (patch) | |
tree | 41165b997293675eeb2a40bffe8417939e76c95e /lgc.c | |
parent | 849b2ecbd28793408d21ebd734525ab56ae5ca1e (diff) | |
download | lua-52c86797608f1bf927be5bab1e9b97b7d35bdf2c.tar.gz lua-52c86797608f1bf927be5bab1e9b97b7d35bdf2c.tar.bz2 lua-52c86797608f1bf927be5bab1e9b97b7d35bdf2c.zip |
Fixed bug of keys removed from tables vs 'next'
Fixed the bug that a key removed from a table might not be found
again by 'next'. (This is needed to allow keys to be removed during a
traversal.) This bug was introduced in commit 73ec04fc.
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -161,18 +161,17 @@ static void linkgclist_ (GCObject *o, GCObject **pnext, GCObject **list) { | |||
161 | 161 | ||
162 | 162 | ||
163 | /* | 163 | /* |
164 | ** Clear keys for empty entries in tables. If entry is empty | 164 | ** Clear keys for empty entries in tables. If entry is empty, mark its |
165 | ** and its key is not marked, mark its entry as dead. This allows the | 165 | ** entry as dead. This allows the collection of the key, but keeps its |
166 | ** collection of the key, but keeps its entry in the table (its removal | 166 | ** entry in the table: its removal could break a chain and could break |
167 | ** could break a chain). The main feature of a dead key is that it must | 167 | ** a table traversal. Other places never manipulate dead keys, because |
168 | ** be different from any other value, to do not disturb searches. | 168 | ** its associated empty value is enough to signal that the entry is |
169 | ** Other places never manipulate dead keys, because its associated empty | 169 | ** logically empty. |
170 | ** value is enough to signal that the entry is logically empty. | ||
171 | */ | 170 | */ |
172 | static void clearkey (Node *n) { | 171 | static void clearkey (Node *n) { |
173 | lua_assert(isempty(gval(n))); | 172 | lua_assert(isempty(gval(n))); |
174 | if (keyiswhite(n)) | 173 | if (keyiscollectable(n)) |
175 | setdeadkey(n); /* unused and unmarked key; remove it */ | 174 | setdeadkey(n); /* unused key; remove it */ |
176 | } | 175 | } |
177 | 176 | ||
178 | 177 | ||