aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-04-14 15:12:35 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-04-14 15:12:35 -0300
commit870f61d2998cc9a998b9599997ae8975879d9314 (patch)
treee87398ff6bcf367357d7e6813332568247136a9c /lgc.c
parentc845ec777a29e434da6ceee50de9d5a6dfa40ea7 (diff)
downloadlua-870f61d2998cc9a998b9599997ae8975879d9314.tar.gz
lua-870f61d2998cc9a998b9599997ae8975879d9314.tar.bz2
lua-870f61d2998cc9a998b9599997ae8975879d9314.zip
code redistribution
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/lgc.c b/lgc.c
index e1885570..ac213df2 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.45 2000/03/29 20:19:20 roberto Exp roberto $ 2** $Id: lgc.c,v 1.46 2000/03/30 20:55:50 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*/
@@ -20,6 +20,17 @@
20 20
21 21
22 22
23static void luaD_gcTM (lua_State *L, const TObject *o) {
24 const TObject *im = luaT_getimbyObj(L, o, IM_GC);
25 if (ttype(im) != TAG_NIL) {
26 luaD_checkstack(L, 2);
27 *(L->top++) = *im;
28 *(L->top++) = *o;
29 luaD_call(L, L->top-2, 0);
30 }
31}
32
33
23static int markobject (lua_State *L, TObject *o); 34static int markobject (lua_State *L, TObject *o);
24 35
25 36
@@ -201,7 +212,7 @@ static void collectstring (lua_State *L, int limit) {
201 else { /* collect */ 212 else { /* collect */
202 if (next->constindex == -1) { /* is userdata? */ 213 if (next->constindex == -1) { /* is userdata? */
203 tsvalue(&o) = next; 214 tsvalue(&o) = next;
204 luaD_gcIM(L, &o); 215 luaD_gcTM(L, &o);
205 } 216 }
206 *p = next->nexthash; 217 *p = next->nexthash;
207 luaS_free(L, next); 218 luaS_free(L, next);
@@ -240,13 +251,13 @@ long lua_collectgarbage (lua_State *L, long limit) {
240 markall(L); 251 markall(L);
241 luaR_invalidaterefs(L); 252 luaR_invalidaterefs(L);
242 luaC_collect(L, 0); 253 luaC_collect(L, 0);
243 luaD_gcIM(L, &luaO_nilobject); /* GC tag method for nil (signal end of GC) */
244 recovered = recovered - L->nblocks; 254 recovered = recovered - L->nblocks;
245 L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit; 255 L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit;
246 if (L->Mbuffsize > L->Mbuffnext*4) { /* is buffer too big? */ 256 if (L->Mbuffsize > L->Mbuffnext*4) { /* is buffer too big? */
247 L->Mbuffsize /= 2; /* still larger than Mbuffnext*2 */ 257 L->Mbuffsize /= 2; /* still larger than Mbuffnext*2 */
248 luaM_reallocvector(L, L->Mbuffer, L->Mbuffsize, char); 258 luaM_reallocvector(L, L->Mbuffer, L->Mbuffsize, char);
249 } 259 }
260 luaD_gcTM(L, &luaO_nilobject);
250 return recovered; 261 return recovered;
251} 262}
252 263