aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-09-24 18:12:01 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-09-24 18:12:01 -0300
commit87912786af9125d062babe2497fc4cb664728eda (patch)
tree07cc2752b09679dfa8c61775cd54d01ea452e69d
parent5645a84368f2a515281da60f96e09d0fdeaf0470 (diff)
downloadlua-87912786af9125d062babe2497fc4cb664728eda.tar.gz
lua-87912786af9125d062babe2497fc4cb664728eda.tar.bz2
lua-87912786af9125d062babe2497fc4cb664728eda.zip
dead objects are not collectable.
-rw-r--r--lgc.c7
-rw-r--r--lobject.h8
-rw-r--r--ltable.c4
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);
100 100
101 101
102/* 102/*
103** mark a table entry as dead (therefore removing it from the table) 103** if key is not marked, mark its entry as dead (therefore removing it
104** from the table)
104*/ 105*/
105static void removeentry (Node *n) { 106static void removeentry (Node *n) {
106 lua_assert(ttisnil(gval(n))); 107 lua_assert(ttisnil(gval(n)));
107 if (iscollectable(gkey(n))) 108 if (valiswhite(gkey(n)))
108 setdeadvalue(gkey(n)); /* dead key; remove it */ 109 setdeadvalue(gkey(n)); /* unused and unmarked key; remove it */
109} 110}
110 111
111 112
diff --git a/lobject.h b/lobject.h
index 2e660b62..1f32e50f 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 2.60 2011/06/13 14:13:06 roberto Exp roberto $ 2** $Id: lobject.h,v 2.61 2011/07/04 20:29:02 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -132,7 +132,7 @@ typedef struct lua_TValue TValue;
132#define ttislcf(o) checktag((o), LUA_TLCF) 132#define ttislcf(o) checktag((o), LUA_TLCF)
133#define ttisuserdata(o) checktag((o), ctb(LUA_TUSERDATA)) 133#define ttisuserdata(o) checktag((o), ctb(LUA_TUSERDATA))
134#define ttisthread(o) checktag((o), ctb(LUA_TTHREAD)) 134#define ttisthread(o) checktag((o), ctb(LUA_TTHREAD))
135#define ttisdeadkey(o) checktag((o), ctb(LUA_TDEADKEY)) 135#define ttisdeadkey(o) checktag((o), LUA_TDEADKEY)
136 136
137#define ttisequal(o1,o2) (rttype(o1) == rttype(o2)) 137#define ttisequal(o1,o2) (rttype(o1) == rttype(o2))
138 138
@@ -151,6 +151,8 @@ typedef struct lua_TValue TValue;
151#define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h) 151#define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h)
152#define bvalue(o) check_exp(ttisboolean(o), val_(o).b) 152#define bvalue(o) check_exp(ttisboolean(o), val_(o).b)
153#define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th) 153#define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th)
154/* a dead value may get the 'gc' field, but cannot access its contents */
155#define deadvalue(o) check_exp(ttisdeadkey(o), cast(void *, val_(o).gc))
154 156
155#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) 157#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
156 158
@@ -224,7 +226,7 @@ typedef struct lua_TValue TValue;
224 val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TPROTO)); \ 226 val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TPROTO)); \
225 checkliveness(G(L),io); } 227 checkliveness(G(L),io); }
226 228
227#define setdeadvalue(obj) settt_(obj, ctb(LUA_TDEADKEY)) 229#define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY)
228 230
229 231
230 232
diff --git a/ltable.c b/ltable.c
index 2ac57a07..f6b765d4 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 2.62 2011/08/17 20:26:47 roberto Exp roberto $ 2** $Id: ltable.c,v 2.63 2011/09/15 17:09:02 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*/
@@ -152,7 +152,7 @@ static int findindex (lua_State *L, Table *t, StkId key) {
152 /* key may be dead already, but it is ok to use it in `next' */ 152 /* key may be dead already, but it is ok to use it in `next' */
153 if (luaV_rawequalobj(gkey(n), key) || 153 if (luaV_rawequalobj(gkey(n), key) ||
154 (ttisdeadkey(gkey(n)) && iscollectable(key) && 154 (ttisdeadkey(gkey(n)) && iscollectable(key) &&
155 gcvalue(gkey(n)) == gcvalue(key))) { 155 deadvalue(gkey(n)) == gcvalue(key))) {
156 i = cast_int(n - gnode(t, 0)); /* key index in hash table */ 156 i = cast_int(n - gnode(t, 0)); /* key index in hash table */
157 /* hash elements are numbered after array ones */ 157 /* hash elements are numbered after array ones */
158 return i + t->sizearray; 158 return i + t->sizearray;