no more support for gc TM for tables

This commit is contained in:
Roberto Ierusalimschy 2000-03-27 17:08:02 -03:00
parent 4c03196697
commit 102a1be615
3 changed files with 16 additions and 39 deletions

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lbuiltin.c,v 1.96 2000/03/10 18:37:44 roberto Exp roberto $ ** $Id: lbuiltin.c,v 1.97 2000/03/24 17:26:08 roberto Exp roberto $
** Built-in functions ** Built-in functions
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -239,10 +239,8 @@ void luaB_settagmethod (lua_State *L) {
lua_Object nf = luaL_nonnullarg(L, 3); lua_Object nf = luaL_nonnullarg(L, 3);
luaL_arg_check(L, lua_isnil(L, nf) || lua_isfunction(L, nf), 3, luaL_arg_check(L, lua_isnil(L, nf) || lua_isfunction(L, nf), 3,
"function or nil expected"); "function or nil expected");
#ifndef LUA_COMPAT_GC
if (strcmp(event, "gc") == 0 && tag != TAG_NIL) if (strcmp(event, "gc") == 0 && tag != TAG_NIL)
lua_error(L, "cannot set this `gc' tag method from Lua"); lua_error(L, "deprecated use: cannot set the `gc' tag method from Lua");
#endif
lua_pushobject(L, nf); lua_pushobject(L, nf);
lua_pushobject(L, lua_settagmethod(L, tag, event)); lua_pushobject(L, lua_settagmethod(L, tag, event));
} }

21
lgc.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lgc.c,v 1.41 2000/01/28 16:53:00 roberto Exp roberto $ ** $Id: lgc.c,v 1.42 2000/03/10 18:37:44 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -216,24 +216,6 @@ static void collectstring (lua_State *L, int limit) {
} }
#ifdef LUA_COMPAT_GC
static void tableTM (lua_State *L) {
Hash *p;
TObject o;
ttype(&o) = TAG_ARRAY;
for (p = L->roottable; p; p = p->next) {
if (!p->marked) {
avalue(&o) = p;
luaD_gcIM(L, &o);
}
}
}
#else
#define tableTM(L) /* do nothing */
#endif
static void markall (lua_State *L) { static void markall (lua_State *L) {
travstack(L); /* mark stack objects */ travstack(L); /* mark stack objects */
travglobal(L); /* mark global variable values and names */ travglobal(L); /* mark global variable values and names */
@ -246,7 +228,6 @@ void luaC_collect (lua_State *L, int all) {
int oldah = L->allowhooks; int oldah = L->allowhooks;
L->allowhooks = 0; /* stop debug hooks during GC */ L->allowhooks = 0; /* stop debug hooks during GC */
L->GCthreshold *= 4; /* to avoid GC during GC */ L->GCthreshold *= 4; /* to avoid GC during GC */
tableTM(L); /* call TM for tables (if LUA_COMPAT_GC) */
collecttable(L); collecttable(L);
collectstring(L, all?MAX_INT:1); collectstring(L, all?MAX_INT:1);
collectproto(L); collectproto(L);

28
ltm.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltm.c,v 1.34 2000/03/10 18:37:44 roberto Exp roberto $ ** $Id: ltm.c,v 1.35 2000/03/20 19:14:54 roberto Exp roberto $
** Tag methods ** Tag methods
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -25,10 +25,12 @@ const char *const luaT_eventname[] = { /* ORDER IM */
}; };
static int luaI_checkevent (lua_State *L, const char *name) { static int luaI_checkevent (lua_State *L, const char *name, int t) {
int e = luaL_findstring(name, luaT_eventname); int e = luaL_findstring(name, luaT_eventname);
if (e >= IM_N) if (e >= IM_N)
luaL_verror(L, "event `%.50s' is deprecated", name); luaL_verror(L, "event `%.50s' is deprecated", name);
if (e == IM_GC && t == TAG_ARRAY)
luaL_verror(L, "event `gc' for tables is deprecated");
if (e < 0) if (e < 0)
luaL_verror(L, "`%.50s' is not a valid event name", name); luaL_verror(L, "`%.50s' is not a valid event name", name);
return e; return e;
@ -41,20 +43,16 @@ static int luaI_checkevent (lua_State *L, const char *name) {
*/ */
/* ORDER LUA_T, ORDER IM */ /* ORDER LUA_T, ORDER IM */
static const char luaT_validevents[NUM_TAGS][IM_N] = { static const char luaT_validevents[NUM_TAGS][IM_N] = {
{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* TAG_USERDATA */ {1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* TAG_USERDATA */
{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* TAG_NUMBER */ {1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* TAG_NUMBER */
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* TAG_STRING */ {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* TAG_STRING */
{0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* TAG_ARRAY */ {0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* TAG_ARRAY */
{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* TAG_LPROTO */ {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* TAG_LPROTO */
{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* TAG_CPROTO */ {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* TAG_CPROTO */
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* TAG_NIL */ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* TAG_NIL */
}; };
static int luaT_validevent (int t, int e) { /* ORDER LUA_T */ static int luaT_validevent (int t, int e) { /* ORDER LUA_T */
#ifdef LUA_COMPAT_GC
if (t == TAG_ARRAY && e == IM_GC)
return 1; /* old versions allowed gc tag method for tables */
#endif
return (t > TAG_NIL) ? 1 : luaT_validevents[t][e]; return (t > TAG_NIL) ? 1 : luaT_validevents[t][e];
} }
@ -126,7 +124,7 @@ int luaT_effectivetag (lua_State *L, const TObject *o) {
const TObject *luaT_gettagmethod (lua_State *L, int t, const char *event) { const TObject *luaT_gettagmethod (lua_State *L, int t, const char *event) {
int e; int e;
e = luaI_checkevent(L, event); e = luaI_checkevent(L, event, t);
checktag(L, t); checktag(L, t);
if (luaT_validevent(t, e)) if (luaT_validevent(t, e))
return luaT_getim(L, t,e); return luaT_getim(L, t,e);
@ -138,7 +136,7 @@ const TObject *luaT_gettagmethod (lua_State *L, int t, const char *event) {
void luaT_settagmethod (lua_State *L, int t, const char *event, TObject *func) { void luaT_settagmethod (lua_State *L, int t, const char *event, TObject *func) {
TObject temp; TObject temp;
int e; int e;
e = luaI_checkevent(L, event); e = luaI_checkevent(L, event, t);
checktag(L, t); checktag(L, t);
if (!luaT_validevent(t, e)) if (!luaT_validevent(t, e))
luaL_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s", luaL_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s",