From 87912786af9125d062babe2497fc4cb664728eda Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Sat, 24 Sep 2011 18:12:01 -0300 Subject: [PATCH] dead objects are not collectable. --- lgc.c | 7 ++++--- lobject.h | 8 +++++--- ltable.c | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lgc.c b/lgc.c index 89cdd2c5..1c741a4a 100644 --- a/lgc.c +++ b/lgc.c @@ -100,12 +100,13 @@ static void reallymarkobject (global_State *g, GCObject *o); /* -** mark a table entry as dead (therefore removing it from the table) +** if key is not marked, mark its entry as dead (therefore removing it +** from the table) */ static void removeentry (Node *n) { lua_assert(ttisnil(gval(n))); - if (iscollectable(gkey(n))) - setdeadvalue(gkey(n)); /* dead key; remove it */ + if (valiswhite(gkey(n))) + setdeadvalue(gkey(n)); /* unused and unmarked key; remove it */ } diff --git a/lobject.h b/lobject.h index 2e660b62..1f32e50f 100644 --- a/lobject.h +++ b/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 2.60 2011/06/13 14:13:06 roberto Exp roberto $ +** $Id: lobject.h,v 2.61 2011/07/04 20:29:02 roberto Exp roberto $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ @@ -132,7 +132,7 @@ typedef struct lua_TValue TValue; #define ttislcf(o) checktag((o), LUA_TLCF) #define ttisuserdata(o) checktag((o), ctb(LUA_TUSERDATA)) #define ttisthread(o) checktag((o), ctb(LUA_TTHREAD)) -#define ttisdeadkey(o) checktag((o), ctb(LUA_TDEADKEY)) +#define ttisdeadkey(o) checktag((o), LUA_TDEADKEY) #define ttisequal(o1,o2) (rttype(o1) == rttype(o2)) @@ -151,6 +151,8 @@ typedef struct lua_TValue TValue; #define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h) #define bvalue(o) check_exp(ttisboolean(o), val_(o).b) #define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th) +/* a dead value may get the 'gc' field, but cannot access its contents */ +#define deadvalue(o) check_exp(ttisdeadkey(o), cast(void *, val_(o).gc)) #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) @@ -224,7 +226,7 @@ typedef struct lua_TValue TValue; val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TPROTO)); \ checkliveness(G(L),io); } -#define setdeadvalue(obj) settt_(obj, ctb(LUA_TDEADKEY)) +#define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY) diff --git a/ltable.c b/ltable.c index 2ac57a07..f6b765d4 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 2.62 2011/08/17 20:26:47 roberto Exp roberto $ +** $Id: ltable.c,v 2.63 2011/09/15 17:09:02 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -152,7 +152,7 @@ static int findindex (lua_State *L, Table *t, StkId key) { /* key may be dead already, but it is ok to use it in `next' */ if (luaV_rawequalobj(gkey(n), key) || (ttisdeadkey(gkey(n)) && iscollectable(key) && - gcvalue(gkey(n)) == gcvalue(key))) { + deadvalue(gkey(n)) == gcvalue(key))) { i = cast_int(n - gnode(t, 0)); /* key index in hash table */ /* hash elements are numbered after array ones */ return i + t->sizearray;