Browse Source

"global" version of a nil object.

v5-2
Roberto Ierusalimschy 27 years ago
parent
commit
7135803cc8
  1. 15
      lgc.c
  2. 6
      lobject.c
  3. 4
      lobject.h
  4. 4
      ltm.c

15
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 ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -66,9 +66,8 @@ void lua_unref (int ref)
TObject* luaC_getref (int ref) TObject* luaC_getref (int ref)
{ {
static TObject nul = {LUA_T_NIL, {0}};
if (ref == -1) if (ref == -1)
return &nul; return &luaO_nilobject;
if (ref >= 0 && ref < refSize && if (ref >= 0 && ref < refSize &&
(refArray[ref].status == LOCK || refArray[ref].status == HOLD)) (refArray[ref].status == LOCK || refArray[ref].status == HOLD))
return &refArray[ref].o; 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 #define GARBAGE_BLOCK 150
@ -279,7 +270,7 @@ long lua_collectgarbage (long limit)
luaC_threshold *= 4; /* to avoid GC during GC */ luaC_threshold *= 4; /* to avoid GC during GC */
hashcallIM(freetable); /* GC tag methods for tables */ hashcallIM(freetable); /* GC tag methods for tables */
strcallIM(freestr); /* GC tag methods for userdata */ 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); luaH_free(freetable);
luaS_free(freestr); luaS_free(freestr);
luaF_freeproto(freefunc); luaF_freeproto(freefunc);

6
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 ** Some generic functions over Lua objects
** See Copyright Notice in lua.h ** 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; unsigned long luaO_nblocks = 0;

4
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 ** Type definitions for Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -166,6 +166,8 @@ extern unsigned long luaO_nblocks;
extern char *luaO_typenames[]; extern char *luaO_typenames[];
extern TObject luaO_nilobject;
int luaO_equalObj (TObject *t1, TObject *t2); int luaO_equalObj (TObject *t1, TObject *t2);
int luaO_redimension (int oldsize); int luaO_redimension (int oldsize);
int luaO_findstring (char *name, char *list[]); int luaO_findstring (char *name, char *list[]);

4
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 ** Tag methods
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -168,7 +168,7 @@ TObject *luaT_gettagmethod (int t, char *event)
if (validevent(t, e)) if (validevent(t, e))
return luaT_getim(t,e); return luaT_getim(t,e);
else else
return luaT_getim(LUA_T_NUMBER, IM_ADD); /* always nil */ return &luaO_nilobject;
} }

Loading…
Cancel
Save