diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-09-02 16:54:49 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-09-02 16:54:49 -0300 |
| commit | 4964e7c8a0284a75a57cf591c3b3c77febaf40e6 (patch) | |
| tree | d47c75cc6c36b87b8c837fe9487161c375d76d1c /lgc.c | |
| parent | 2c670baf24115d9c59b5869b89873b93af8b779d (diff) | |
| download | lua-4964e7c8a0284a75a57cf591c3b3c77febaf40e6.tar.gz lua-4964e7c8a0284a75a57cf591c3b3c77febaf40e6.tar.bz2 lua-4964e7c8a0284a75a57cf591c3b3c77febaf40e6.zip | |
details
Diffstat (limited to 'lgc.c')
| -rw-r--r-- | lgc.c | 24 |
1 files changed, 13 insertions, 11 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 1.147 2002/08/16 20:00:28 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.148 2002/08/30 19:09:21 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 | */ |
| @@ -48,10 +48,15 @@ typedef struct GCState { | |||
| 48 | 48 | ||
| 49 | static void reallymarkobject (GCState *st, GCObject *o); | 49 | static void reallymarkobject (GCState *st, GCObject *o); |
| 50 | 50 | ||
| 51 | #define markobject(st,o) \ | 51 | #define markobject(st,o) { checkconsistency(o); \ |
| 52 | if (iscollectable(o)) reallymarkobject(st,(o)->value.gc) | 52 | if (iscollectable(o) && !ismarked(gcvalue(o))) reallymarkobject(st,gcvalue(o)); } |
| 53 | 53 | ||
| 54 | #define marktable(st,t) reallymarkobject(st, cast(GCObject *, (t))) | 54 | #define condmarkobject(st,o,c) { checkconsistency(o); \ |
| 55 | if (iscollectable(o) && !ismarked(gcvalue(o)) && (c)) \ | ||
| 56 | reallymarkobject(st,gcvalue(o)); } | ||
| 57 | |||
| 58 | #define marktable(st,t) { if (!ismarked(cast(GCObject *, t))) \ | ||
| 59 | reallymarkobject(st, cast(GCObject *, (t))); } | ||
| 55 | 60 | ||
| 56 | 61 | ||
| 57 | static void markproto (Proto *f) { | 62 | static void markproto (Proto *f) { |
| @@ -96,7 +101,6 @@ static void markclosure (GCState *st, Closure *cl) { | |||
| 96 | 101 | ||
| 97 | 102 | ||
| 98 | static void reallymarkobject (GCState *st, GCObject *o) { | 103 | static void reallymarkobject (GCState *st, GCObject *o) { |
| 99 | if (ismarked(o)) return; | ||
| 100 | mark(o); | 104 | mark(o); |
| 101 | switch (o->gch.tt) { | 105 | switch (o->gch.tt) { |
| 102 | case LUA_TFUNCTION: { | 106 | case LUA_TFUNCTION: { |
| @@ -157,10 +161,8 @@ static void traversestacks (GCState *st) { | |||
| 157 | 161 | ||
| 158 | static void marktmu (GCState *st) { | 162 | static void marktmu (GCState *st) { |
| 159 | GCObject *u; | 163 | GCObject *u; |
| 160 | for (u = G(st->L)->tmudata; u; u = u->uv.next) { | 164 | for (u = G(st->L)->tmudata; u; u = u->uv.next) |
| 161 | mark(u); | 165 | reallymarkobject(st, u); |
| 162 | marktable(st, (&u->u)->uv.metatable); | ||
| 163 | } | ||
| 164 | } | 166 | } |
| 165 | 167 | ||
| 166 | 168 | ||
| @@ -221,8 +223,8 @@ static void traversetable (GCState *st, Table *h) { | |||
| 221 | Node *n = node(h, i); | 223 | Node *n = node(h, i); |
| 222 | if (!ttisnil(val(n))) { | 224 | if (!ttisnil(val(n))) { |
| 223 | lua_assert(!ttisnil(key(n))); | 225 | lua_assert(!ttisnil(key(n))); |
| 224 | if (!weakkey) markobject(st, key(n)); | 226 | condmarkobject(st, key(n), !weakkey); |
| 225 | if (!weakvalue) markobject(st, val(n)); | 227 | condmarkobject(st, val(n), !weakvalue); |
| 226 | } | 228 | } |
| 227 | } | 229 | } |
| 228 | } | 230 | } |
