Browse Source

"global" version of a nil object.

Roberto Ierusalimschy 28 years ago
parent
commit
7135803cc8
4 changed files with 13 additions and 16 deletions
  1. 3 12
      lgc.c
  2. 5 1
      lobject.c
  3. 3 1
      lobject.h
  4. 2 2
      ltm.c

+ 3 - 12
lgc.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lgc.c,v 1.5 1997/10/23 16:26:37 roberto Exp roberto $
+** $Id: lgc.c,v 1.6 1997/10/24 17:17:24 roberto Exp roberto $
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 */
@@ -66,9 +66,8 @@ void lua_unref (int ref)
 
 TObject* luaC_getref (int ref)
 {
-  static TObject nul = {LUA_T_NIL, {0}};
   if (ref == -1)
-    return &nul;
+    return &luaO_nilobject;
   if (ref >= 0 && ref < refSize &&
       (refArray[ref].status == LOCK || refArray[ref].status == HOLD))
     return &refArray[ref].o;
@@ -240,14 +239,6 @@ static int markobject (TObject *o)
 }
 
 
-static void call_nilIM (void)
-{ /* signals end of garbage collection */
-  TObject t;
-  ttype(&t) = LUA_T_NIL;
-  luaD_gcIM(&t);  /* end of list */
-}
-
-
 
 #define GARBAGE_BLOCK 150
 
@@ -279,7 +270,7 @@ long lua_collectgarbage (long limit)
   luaC_threshold *= 4;  /* to avoid GC during GC */
   hashcallIM(freetable);  /* GC tag methods for tables */
   strcallIM(freestr);  /* GC tag methods for userdata */
-  call_nilIM();  /* GC tag method for nil (signal end of GC) */
+  luaD_gcIM(&luaO_nilobject);  /* GC tag method for nil (signal end of GC) */
   luaH_free(freetable);
   luaS_free(freestr);
   luaF_freeproto(freefunc);

+ 5 - 1
lobject.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.c,v 1.4 1997/10/23 16:26:37 roberto Exp roberto $
+** $Id: lobject.c,v 1.5 1997/10/24 17:17:24 roberto Exp roberto $
 ** Some generic functions over Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -17,6 +17,10 @@ char *luaO_typenames[] = { /* ORDER LUA_T */
 };
 
 
+TObject luaO_nilobject = {LUA_T_NIL, {NULL}};
+
+
+
 unsigned long luaO_nblocks = 0;
 
 

+ 3 - 1
lobject.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.h,v 1.6 1997/10/23 16:26:37 roberto Exp roberto $
+** $Id: lobject.h,v 1.7 1997/10/24 17:17:24 roberto Exp roberto $
 ** Type definitions for Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -166,6 +166,8 @@ extern unsigned long luaO_nblocks;
 
 extern char *luaO_typenames[];
 
+extern TObject luaO_nilobject;
+
 int luaO_equalObj (TObject *t1, TObject *t2);
 int luaO_redimension (int oldsize);
 int luaO_findstring (char *name, char *list[]);

+ 2 - 2
ltm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltm.c,v 1.3 1997/10/16 20:07:40 roberto Exp roberto $
+** $Id: ltm.c,v 1.4 1997/10/24 17:17:24 roberto Exp roberto $
 ** Tag methods
 ** See Copyright Notice in lua.h
 */
@@ -168,7 +168,7 @@ TObject *luaT_gettagmethod (int t, char *event)
   if (validevent(t, e))
     return luaT_getim(t,e);
   else
-    return luaT_getim(LUA_T_NUMBER, IM_ADD);  /* always nil */
+    return &luaO_nilobject;
 }