diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-11-03 16:10:44 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-11-03 16:10:44 -0200 |
commit | 748551238451acf36a245fb2f883293149e2f0ca (patch) | |
tree | 54ddfebfa1ebc31392a210b50baa64a042d09223 | |
parent | 46de77b219e381ff8553fdba0f52b319c00ea1e1 (diff) | |
download | lua-748551238451acf36a245fb2f883293149e2f0ca.tar.gz lua-748551238451acf36a245fb2f883293149e2f0ca.tar.bz2 lua-748551238451acf36a245fb2f883293149e2f0ca.zip |
added comment and assert about dead keys
-rw-r--r-- | lgc.c | 11 | ||||
-rw-r--r-- | ltable.c | 5 |
2 files changed, 11 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.208 2015/11/02 16:19:29 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.209 2015/11/02 18:48:07 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -114,8 +114,13 @@ static void reallymarkobject (global_State *g, GCObject *o); | |||
114 | 114 | ||
115 | 115 | ||
116 | /* | 116 | /* |
117 | ** if key is not marked, mark its entry as dead (therefore removing it | 117 | ** If key is not marked, mark its entry as dead. This allows key to be |
118 | ** from the table) | 118 | ** collected, but keeps its entry in the table. A dead node is needed |
119 | ** when Lua looks up for a key (it may be part of a chain) and when | ||
120 | ** traversing a weak table (key might be removed from the table during | ||
121 | ** traversal). Other places never manipulate dead keys, because its | ||
122 | ** associated nil value is enough to signal that the entry is logically | ||
123 | ** empty. | ||
119 | */ | 124 | */ |
120 | static void removeentry (Node *n) { | 125 | static void removeentry (Node *n) { |
121 | lua_assert(ttisnil(gval(n))); | 126 | lua_assert(ttisnil(gval(n))); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 2.113 2015/07/04 16:32:34 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.114 2015/11/03 15:47:30 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -133,6 +133,7 @@ static Node *mainposition (const Table *t, const TValue *key) { | |||
133 | case LUA_TLCF: | 133 | case LUA_TLCF: |
134 | return hashpointer(t, fvalue(key)); | 134 | return hashpointer(t, fvalue(key)); |
135 | default: | 135 | default: |
136 | lua_assert(!ttisdeadkey(key)); | ||
136 | return hashpointer(t, gcvalue(key)); | 137 | return hashpointer(t, gcvalue(key)); |
137 | } | 138 | } |
138 | } | 139 | } |
@@ -457,7 +458,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { | |||
457 | Node *f = getfreepos(t); /* get a free place */ | 458 | Node *f = getfreepos(t); /* get a free place */ |
458 | if (f == NULL) { /* cannot find a free place? */ | 459 | if (f == NULL) { /* cannot find a free place? */ |
459 | rehash(L, t, key); /* grow table */ | 460 | rehash(L, t, key); /* grow table */ |
460 | /* whatever called 'newkey' takes care of TM cache and GC barrier */ | 461 | /* whatever called 'newkey' takes care of TM cache */ |
461 | return luaH_set(L, t, key); /* insert key into grown table */ | 462 | return luaH_set(L, t, key); /* insert key into grown table */ |
462 | } | 463 | } |
463 | lua_assert(!isdummy(f)); | 464 | lua_assert(!isdummy(f)); |