aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-11-03 18:45:23 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-11-03 18:45:23 -0200
commit7135803cc87fafe80494bdc094613515487410b9 (patch)
tree439f9c6f1173707f7e37520c550e48edb5cafab8
parentb7567b667367180b75fbb60f7a73b75e5e89889e (diff)
downloadlua-7135803cc87fafe80494bdc094613515487410b9.tar.gz
lua-7135803cc87fafe80494bdc094613515487410b9.tar.bz2
lua-7135803cc87fafe80494bdc094613515487410b9.zip
"global" version of a nil object.
-rw-r--r--lgc.c15
-rw-r--r--lobject.c6
-rw-r--r--lobject.h4
-rw-r--r--ltm.c4
4 files changed, 13 insertions, 16 deletions
diff --git a/lgc.c b/lgc.c
index aafc4cb8..6fdbacaa 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.5 1997/10/23 16:26:37 roberto Exp roberto $ 2** $Id: lgc.c,v 1.6 1997/10/24 17:17:24 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*/
@@ -66,9 +66,8 @@ void lua_unref (int ref)
66 66
67TObject* luaC_getref (int ref) 67TObject* luaC_getref (int ref)
68{ 68{
69 static TObject nul = {LUA_T_NIL, {0}};
70 if (ref == -1) 69 if (ref == -1)
71 return &nul; 70 return &luaO_nilobject;
72 if (ref >= 0 && ref < refSize && 71 if (ref >= 0 && ref < refSize &&
73 (refArray[ref].status == LOCK || refArray[ref].status == HOLD)) 72 (refArray[ref].status == LOCK || refArray[ref].status == HOLD))
74 return &refArray[ref].o; 73 return &refArray[ref].o;
@@ -240,14 +239,6 @@ static int markobject (TObject *o)
240} 239}
241 240
242 241
243static void call_nilIM (void)
244{ /* signals end of garbage collection */
245 TObject t;
246 ttype(&t) = LUA_T_NIL;
247 luaD_gcIM(&t); /* end of list */
248}
249
250
251 242
252#define GARBAGE_BLOCK 150 243#define GARBAGE_BLOCK 150
253 244
@@ -279,7 +270,7 @@ long lua_collectgarbage (long limit)
279 luaC_threshold *= 4; /* to avoid GC during GC */ 270 luaC_threshold *= 4; /* to avoid GC during GC */
280 hashcallIM(freetable); /* GC tag methods for tables */ 271 hashcallIM(freetable); /* GC tag methods for tables */
281 strcallIM(freestr); /* GC tag methods for userdata */ 272 strcallIM(freestr); /* GC tag methods for userdata */
282 call_nilIM(); /* GC tag method for nil (signal end of GC) */ 273 luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */
283 luaH_free(freetable); 274 luaH_free(freetable);
284 luaS_free(freestr); 275 luaS_free(freestr);
285 luaF_freeproto(freefunc); 276 luaF_freeproto(freefunc);
diff --git a/lobject.c b/lobject.c
index 8c3c11f7..b38d3425 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.4 1997/10/23 16:26:37 roberto Exp roberto $ 2** $Id: lobject.c,v 1.5 1997/10/24 17:17:24 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*/
@@ -17,6 +17,10 @@ char *luaO_typenames[] = { /* ORDER LUA_T */
17}; 17};
18 18
19 19
20TObject luaO_nilobject = {LUA_T_NIL, {NULL}};
21
22
23
20unsigned long luaO_nblocks = 0; 24unsigned long luaO_nblocks = 0;
21 25
22 26
diff --git a/lobject.h b/lobject.h
index 7e9afd62..6cf77303 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.6 1997/10/23 16:26:37 roberto Exp roberto $ 2** $Id: lobject.h,v 1.7 1997/10/24 17:17:24 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*/
@@ -166,6 +166,8 @@ extern unsigned long luaO_nblocks;
166 166
167extern char *luaO_typenames[]; 167extern char *luaO_typenames[];
168 168
169extern TObject luaO_nilobject;
170
169int luaO_equalObj (TObject *t1, TObject *t2); 171int luaO_equalObj (TObject *t1, TObject *t2);
170int luaO_redimension (int oldsize); 172int luaO_redimension (int oldsize);
171int luaO_findstring (char *name, char *list[]); 173int luaO_findstring (char *name, char *list[]);
diff --git a/ltm.c b/ltm.c
index 980fd4d6..a171d78a 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.3 1997/10/16 20:07:40 roberto Exp roberto $ 2** $Id: ltm.c,v 1.4 1997/10/24 17:17:24 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -168,7 +168,7 @@ TObject *luaT_gettagmethod (int t, char *event)
168 if (validevent(t, e)) 168 if (validevent(t, e))
169 return luaT_getim(t,e); 169 return luaT_getim(t,e);
170 else 170 else
171 return luaT_getim(LUA_T_NUMBER, IM_ADD); /* always nil */ 171 return &luaO_nilobject;
172} 172}
173 173
174 174