mirror of
https://github.com/lua/lua
synced 2024-11-26 14:51:21 +03:00
added comment and assert about dead keys
This commit is contained in:
parent
46de77b219
commit
7485512384
11
lgc.c
11
lgc.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lgc.c,v 2.208 2015/11/02 16:19:29 roberto Exp roberto $
|
** $Id: lgc.c,v 2.209 2015/11/02 18:48:07 roberto Exp roberto $
|
||||||
** Garbage Collector
|
** Garbage Collector
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -114,8 +114,13 @@ static void reallymarkobject (global_State *g, GCObject *o);
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** if key is not marked, mark its entry as dead (therefore removing it
|
** If key is not marked, mark its entry as dead. This allows key to be
|
||||||
** from the table)
|
** collected, but keeps its entry in the table. A dead node is needed
|
||||||
|
** when Lua looks up for a key (it may be part of a chain) and when
|
||||||
|
** traversing a weak table (key might be removed from the table during
|
||||||
|
** traversal). Other places never manipulate dead keys, because its
|
||||||
|
** associated nil value is enough to signal that the entry is logically
|
||||||
|
** empty.
|
||||||
*/
|
*/
|
||||||
static void removeentry (Node *n) {
|
static void removeentry (Node *n) {
|
||||||
lua_assert(ttisnil(gval(n)));
|
lua_assert(ttisnil(gval(n)));
|
||||||
|
5
ltable.c
5
ltable.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ltable.c,v 2.113 2015/07/04 16:32:34 roberto Exp roberto $
|
** $Id: ltable.c,v 2.114 2015/11/03 15:47:30 roberto Exp roberto $
|
||||||
** Lua tables (hash)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -133,6 +133,7 @@ static Node *mainposition (const Table *t, const TValue *key) {
|
|||||||
case LUA_TLCF:
|
case LUA_TLCF:
|
||||||
return hashpointer(t, fvalue(key));
|
return hashpointer(t, fvalue(key));
|
||||||
default:
|
default:
|
||||||
|
lua_assert(!ttisdeadkey(key));
|
||||||
return hashpointer(t, gcvalue(key));
|
return hashpointer(t, gcvalue(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -457,7 +458,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
|
|||||||
Node *f = getfreepos(t); /* get a free place */
|
Node *f = getfreepos(t); /* get a free place */
|
||||||
if (f == NULL) { /* cannot find a free place? */
|
if (f == NULL) { /* cannot find a free place? */
|
||||||
rehash(L, t, key); /* grow table */
|
rehash(L, t, key); /* grow table */
|
||||||
/* whatever called 'newkey' takes care of TM cache and GC barrier */
|
/* whatever called 'newkey' takes care of TM cache */
|
||||||
return luaH_set(L, t, key); /* insert key into grown table */
|
return luaH_set(L, t, key); /* insert key into grown table */
|
||||||
}
|
}
|
||||||
lua_assert(!isdummy(f));
|
lua_assert(!isdummy(f));
|
||||||
|
Loading…
Reference in New Issue
Block a user