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 | |
| parent | 2c670baf24115d9c59b5869b89873b93af8b779d (diff) | |
| download | lua-4964e7c8a0284a75a57cf591c3b3c77febaf40e6.tar.gz lua-4964e7c8a0284a75a57cf591c3b3c77febaf40e6.tar.bz2 lua-4964e7c8a0284a75a57cf591c3b3c77febaf40e6.zip | |
details
| -rw-r--r-- | lgc.c | 24 | ||||
| -rw-r--r-- | lobject.c | 18 | ||||
| -rw-r--r-- | lobject.h | 6 | ||||
| -rw-r--r-- | ltable.c | 10 |
4 files changed, 26 insertions, 32 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 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 1.85 2002/07/17 16:25:13 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.86 2002/08/07 14:35:55 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -58,25 +58,17 @@ int luaO_log2 (unsigned int x) { | |||
| 58 | int luaO_rawequalObj (const TObject *t1, const TObject *t2) { | 58 | int luaO_rawequalObj (const TObject *t1, const TObject *t2) { |
| 59 | if (ttype(t1) != ttype(t2)) return 0; | 59 | if (ttype(t1) != ttype(t2)) return 0; |
| 60 | switch (ttype(t1)) { | 60 | switch (ttype(t1)) { |
| 61 | case LUA_TNUMBER: | ||
| 62 | return nvalue(t1) == nvalue(t2); | ||
| 63 | case LUA_TNIL: | 61 | case LUA_TNIL: |
| 64 | return 1; | 62 | return 1; |
| 65 | case LUA_TSTRING: | ||
| 66 | return tsvalue(t1) == tsvalue(t2); | ||
| 67 | case LUA_TBOOLEAN: | 63 | case LUA_TBOOLEAN: |
| 68 | return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ | 64 | return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ |
| 69 | case LUA_TLIGHTUSERDATA: | 65 | case LUA_TLIGHTUSERDATA: |
| 70 | return pvalue(t1) == pvalue(t2); | 66 | return pvalue(t1) == pvalue(t2); |
| 71 | case LUA_TUSERDATA: | 67 | case LUA_TNUMBER: |
| 72 | return uvalue(t1) == uvalue(t2); | 68 | return nvalue(t1) == nvalue(t2); |
| 73 | case LUA_TTABLE: | 69 | default: |
| 74 | return hvalue(t1) == hvalue(t2); | 70 | return gcvalue(t1) == gcvalue(t2); |
| 75 | case LUA_TFUNCTION: | ||
| 76 | return clvalue(t1) == clvalue(t2); | ||
| 77 | } | 71 | } |
| 78 | lua_assert(0); | ||
| 79 | return 0; /* to avoid warnings */ | ||
| 80 | } | 72 | } |
| 81 | 73 | ||
| 82 | 74 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 1.143 2002/08/16 14:45:55 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.144 2002/08/30 19:09:21 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 | */ |
| @@ -67,6 +67,7 @@ typedef struct lua_TObject { | |||
| 67 | 67 | ||
| 68 | /* Macros to access values */ | 68 | /* Macros to access values */ |
| 69 | #define ttype(o) ((o)->tt) | 69 | #define ttype(o) ((o)->tt) |
| 70 | #define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) | ||
| 70 | #define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) | 71 | #define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) |
| 71 | #define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) | 72 | #define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) |
| 72 | #define tsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) | 73 | #define tsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) |
| @@ -113,6 +114,9 @@ typedef struct lua_TObject { | |||
| 113 | #define setnilvalue(obj) ((obj)->tt=LUA_TNIL) | 114 | #define setnilvalue(obj) ((obj)->tt=LUA_TNIL) |
| 114 | 115 | ||
| 115 | 116 | ||
| 117 | /* | ||
| 118 | ** for internal debug only | ||
| 119 | */ | ||
| 116 | #define checkconsistency(obj) \ | 120 | #define checkconsistency(obj) \ |
| 117 | lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) | 121 | lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) |
| 118 | 122 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 1.117 2002/08/16 14:45:55 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.118 2002/08/30 19:09:21 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 | */ |
| @@ -83,12 +83,8 @@ Node *luaH_mainposition (const Table *t, const TObject *key) { | |||
| 83 | return hashboolean(t, bvalue(key)); | 83 | return hashboolean(t, bvalue(key)); |
| 84 | case LUA_TLIGHTUSERDATA: | 84 | case LUA_TLIGHTUSERDATA: |
| 85 | return hashpointer(t, pvalue(key)); | 85 | return hashpointer(t, pvalue(key)); |
| 86 | case LUA_TUSERDATA: | 86 | default: |
| 87 | return hashpointer(t, uvalue(key)); | 87 | return hashpointer(t, gcvalue(key)); |
| 88 | case LUA_TFUNCTION: | ||
| 89 | return hashpointer(t, clvalue(key)); | ||
| 90 | case LUA_TTABLE: | ||
| 91 | return hashpointer(t, hvalue(key)); | ||
| 92 | } | 88 | } |
| 93 | lua_assert(0); | 89 | lua_assert(0); |
| 94 | return 0; /* to avoid warnings */ | 90 | return 0; /* to avoid warnings */ |
