diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-05 10:00:17 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-05 10:00:17 -0300 |
commit | 046a3d6173792b7d4d4d26a4e063e2fe383c10a7 (patch) | |
tree | efe5a4544585084ab6e8d301847cc8568a1cc955 /lgc.c | |
parent | 001f2bdd0e2f8803889c1b5164b57a51e44aef5b (diff) | |
download | lua-046a3d6173792b7d4d4d26a4e063e2fe383c10a7.tar.gz lua-046a3d6173792b7d4d4d26a4e063e2fe383c10a7.tar.bz2 lua-046a3d6173792b7d4d4d26a4e063e2fe383c10a7.zip |
tag methods are always functions, so don't need to store a whole object
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 39 |
1 files changed, 21 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.69 2000/10/02 14:47:43 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.70 2000/10/05 12:14:08 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 | */ |
@@ -63,16 +63,6 @@ static void marklock (lua_State *L, GCState *st) { | |||
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | static void marktagmethods (lua_State *L, GCState *st) { | ||
67 | int e; | ||
68 | for (e=0; e<IM_N; e++) { | ||
69 | int t; | ||
70 | for (t=0; t<=L->last_tag; t++) | ||
71 | markobject(st, luaT_getim(L, t,e)); | ||
72 | } | ||
73 | } | ||
74 | |||
75 | |||
76 | static void markclosure (GCState *st, Closure *cl) { | 66 | static void markclosure (GCState *st, Closure *cl) { |
77 | if (!ismarked(cl)) { | 67 | if (!ismarked(cl)) { |
78 | if (!cl->isC) | 68 | if (!cl->isC) |
@@ -83,6 +73,18 @@ static void markclosure (GCState *st, Closure *cl) { | |||
83 | } | 73 | } |
84 | 74 | ||
85 | 75 | ||
76 | static void marktagmethods (lua_State *L, GCState *st) { | ||
77 | int e; | ||
78 | for (e=0; e<TM_N; e++) { | ||
79 | int t; | ||
80 | for (t=0; t<=L->last_tag; t++) { | ||
81 | Closure *cl = luaT_gettm(L, t, e); | ||
82 | if (cl) markclosure(st, cl); | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | |||
87 | |||
86 | static void markobject (GCState *st, TObject *o) { | 88 | static void markobject (GCState *st, TObject *o) { |
87 | switch (ttype(o)) { | 89 | switch (ttype(o)) { |
88 | case LUA_TUSERDATA: case LUA_TSTRING: | 90 | case LUA_TUSERDATA: case LUA_TSTRING: |
@@ -269,8 +271,8 @@ static void collectudata (lua_State *L, int all) { | |||
269 | else { /* collect */ | 271 | else { /* collect */ |
270 | int tag = next->u.d.tag; | 272 | int tag = next->u.d.tag; |
271 | *p = next->nexthash; | 273 | *p = next->nexthash; |
272 | next->nexthash = L->IMtable[tag].collected; /* chain udata */ | 274 | next->nexthash = L->TMtable[tag].collected; /* chain udata */ |
273 | L->IMtable[tag].collected = next; | 275 | L->TMtable[tag].collected = next; |
274 | L->nblocks -= gcsizeudata; | 276 | L->nblocks -= gcsizeudata; |
275 | L->udt.nuse--; | 277 | L->udt.nuse--; |
276 | } | 278 | } |
@@ -292,12 +294,13 @@ static void checkMbuffer (lua_State *L) { | |||
292 | 294 | ||
293 | 295 | ||
294 | static void callgcTM (lua_State *L, const TObject *o) { | 296 | static void callgcTM (lua_State *L, const TObject *o) { |
295 | const TObject *im = luaT_getimbyObj(L, o, IM_GC); | 297 | Closure *tm = luaT_gettmbyObj(L, o, TM_GC); |
296 | if (ttype(im) != LUA_TNIL) { | 298 | if (tm != NULL) { |
297 | int oldah = L->allowhooks; | 299 | int oldah = L->allowhooks; |
298 | L->allowhooks = 0; /* stop debug hooks during GC tag methods */ | 300 | L->allowhooks = 0; /* stop debug hooks during GC tag methods */ |
299 | luaD_checkstack(L, 2); | 301 | luaD_checkstack(L, 2); |
300 | *(L->top) = *im; | 302 | clvalue(L->top) = tm; |
303 | ttype(L->top) = LUA_TFUNCTION; | ||
301 | *(L->top+1) = *o; | 304 | *(L->top+1) = *o; |
302 | L->top += 2; | 305 | L->top += 2; |
303 | luaD_call(L, L->top-2, 0); | 306 | luaD_call(L, L->top-2, 0); |
@@ -313,8 +316,8 @@ static void callgcTMudata (lua_State *L) { | |||
313 | L->GCthreshold = 2*L->nblocks; /* avoid GC during tag methods */ | 316 | L->GCthreshold = 2*L->nblocks; /* avoid GC during tag methods */ |
314 | for (tag=L->last_tag; tag>=0; tag--) { /* for each tag (in reverse order) */ | 317 | for (tag=L->last_tag; tag>=0; tag--) { /* for each tag (in reverse order) */ |
315 | TString *udata; | 318 | TString *udata; |
316 | while ((udata = L->IMtable[tag].collected) != NULL) { | 319 | while ((udata = L->TMtable[tag].collected) != NULL) { |
317 | L->IMtable[tag].collected = udata->nexthash; /* remove it from list */ | 320 | L->TMtable[tag].collected = udata->nexthash; /* remove it from list */ |
318 | tsvalue(&o) = udata; | 321 | tsvalue(&o) = udata; |
319 | callgcTM(L, &o); | 322 | callgcTM(L, &o); |
320 | luaM_free(L, udata); | 323 | luaM_free(L, udata); |