Roberto Ierusalimschy 23 年之前
父节点
当前提交
4964e7c8a0
共有 4 个文件被更改,包括 26 次插入32 次删除
  1. 13 11
      lgc.c
  2. 5 13
      lobject.c
  3. 5 1
      lobject.h
  4. 3 7
      ltable.c

+ 13 - 11
lgc.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lgc.c,v 1.147 2002/08/16 20:00:28 roberto Exp roberto $
+** $Id: lgc.c,v 1.148 2002/08/30 19:09:21 roberto Exp roberto $
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 */
@@ -48,10 +48,15 @@ typedef struct GCState {
 
 static void reallymarkobject (GCState *st, GCObject *o);
 
-#define markobject(st,o) \
-	if (iscollectable(o)) reallymarkobject(st,(o)->value.gc)
+#define markobject(st,o) { checkconsistency(o); \
+  if (iscollectable(o) && !ismarked(gcvalue(o))) reallymarkobject(st,gcvalue(o)); }
 
-#define marktable(st,t) reallymarkobject(st, cast(GCObject *, (t)))
+#define condmarkobject(st,o,c) { checkconsistency(o); \
+  if (iscollectable(o) && !ismarked(gcvalue(o)) && (c)) \
+    reallymarkobject(st,gcvalue(o)); }
+
+#define marktable(st,t) { if (!ismarked(cast(GCObject *, t))) \
+		reallymarkobject(st, cast(GCObject *, (t))); }
 
 
 static void markproto (Proto *f) {
@@ -96,7 +101,6 @@ static void markclosure (GCState *st, Closure *cl) {
 
 
 static void reallymarkobject (GCState *st, GCObject *o) {
-  if (ismarked(o)) return;
   mark(o);
   switch (o->gch.tt) {
     case LUA_TFUNCTION: {
@@ -157,10 +161,8 @@ static void traversestacks (GCState *st) {
 
 static void marktmu (GCState *st) {
   GCObject *u;
-  for (u = G(st->L)->tmudata; u; u = u->uv.next) {
-    mark(u);
-    marktable(st, (&u->u)->uv.metatable);
-  }
+  for (u = G(st->L)->tmudata; u; u = u->uv.next)
+    reallymarkobject(st, u);
 }
 
 
@@ -221,8 +223,8 @@ static void traversetable (GCState *st, Table *h) {
     Node *n = node(h, i);
     if (!ttisnil(val(n))) {
       lua_assert(!ttisnil(key(n)));
-      if (!weakkey) markobject(st, key(n));
-      if (!weakvalue) markobject(st, val(n));
+      condmarkobject(st, key(n), !weakkey);
+      condmarkobject(st, val(n), !weakvalue);
     }
   }
 }

+ 5 - 13
lobject.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.c,v 1.85 2002/07/17 16:25:13 roberto Exp roberto $
+** $Id: lobject.c,v 1.86 2002/08/07 14:35:55 roberto Exp roberto $
 ** Some generic functions over Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -58,25 +58,17 @@ int luaO_log2 (unsigned int x) {
 int luaO_rawequalObj (const TObject *t1, const TObject *t2) {
   if (ttype(t1) != ttype(t2)) return 0;
   switch (ttype(t1)) {
-    case LUA_TNUMBER:
-      return nvalue(t1) == nvalue(t2);
     case LUA_TNIL:
       return 1;
-    case LUA_TSTRING:
-      return tsvalue(t1) == tsvalue(t2);
     case LUA_TBOOLEAN:
       return bvalue(t1) == bvalue(t2);  /* boolean true must be 1 !! */
     case LUA_TLIGHTUSERDATA:
       return pvalue(t1) == pvalue(t2);
-    case LUA_TUSERDATA:
-      return uvalue(t1) == uvalue(t2);
-    case LUA_TTABLE:
-      return hvalue(t1) == hvalue(t2);
-    case LUA_TFUNCTION:
-      return clvalue(t1) == clvalue(t2);
+    case LUA_TNUMBER:
+      return nvalue(t1) == nvalue(t2);
+    default:
+      return gcvalue(t1) == gcvalue(t2);
   }
-  lua_assert(0);
-  return 0;  /* to avoid warnings */
 }
 
 

+ 5 - 1
lobject.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.h,v 1.143 2002/08/16 14:45:55 roberto Exp roberto $
+** $Id: lobject.h,v 1.144 2002/08/30 19:09:21 roberto Exp roberto $
 ** Type definitions for Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -67,6 +67,7 @@ typedef struct lua_TObject {
 
 /* Macros to access values */
 #define ttype(o)	((o)->tt)
+#define gcvalue(o)	check_exp(iscollectable(o), (o)->value.gc)
 #define pvalue(o)	check_exp(ttislightuserdata(o), (o)->value.p)
 #define nvalue(o)	check_exp(ttisnumber(o), (o)->value.n)
 #define tsvalue(o)	check_exp(ttisstring(o), &(o)->value.gc->ts)
@@ -113,6 +114,9 @@ typedef struct lua_TObject {
 #define setnilvalue(obj) ((obj)->tt=LUA_TNIL)
 
 
+/*
+** for internal debug only
+*/
 #define checkconsistency(obj) \
   lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt))
 

+ 3 - 7
ltable.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltable.c,v 1.117 2002/08/16 14:45:55 roberto Exp roberto $
+** $Id: ltable.c,v 1.118 2002/08/30 19:09:21 roberto Exp roberto $
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 */
@@ -83,12 +83,8 @@ Node *luaH_mainposition (const Table *t, const TObject *key) {
       return hashboolean(t, bvalue(key));
     case LUA_TLIGHTUSERDATA:
       return hashpointer(t, pvalue(key));
-    case LUA_TUSERDATA:
-      return hashpointer(t, uvalue(key));
-    case LUA_TFUNCTION:
-      return hashpointer(t, clvalue(key));
-    case LUA_TTABLE:
-      return hashpointer(t, hvalue(key));
+    default:
+      return hashpointer(t, gcvalue(key));
   }
   lua_assert(0);
   return 0;  /* to avoid warnings */