aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-11-04 15:23:12 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-11-04 15:23:12 -0200
commitcde179b36979c58d9380d3c4dd29b61412d13b51 (patch)
tree804c457691024d797a7479eddf711e103966b513 /lgc.c
parent80b39d83c3512e1dd627842e64c69841638d9088 (diff)
downloadlua-cde179b36979c58d9380d3c4dd29b61412d13b51.tar.gz
lua-cde179b36979c58d9380d3c4dd29b61412d13b51.tar.bz2
lua-cde179b36979c58d9380d3c4dd29b61412d13b51.zip
new implementation for global variable values (separated from strings)
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/lgc.c b/lgc.c
index fc5c1739..c52e3f3b 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.28 1999/10/11 16:13:11 roberto Exp roberto $ 2** $Id: lgc.c,v 1.29 1999/10/14 19:13:31 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*/
@@ -62,13 +62,13 @@ static void hashmark (Hash *h) {
62} 62}
63 63
64 64
65static void globalmark (void) { 65static void travglobal (void) {
66 TaggedString *g; 66 GlobalVar *gv;
67 for (g=L->rootglobal; g; g=g->nextglobal) { 67 for (gv=L->rootglobal; gv; gv=gv->next) {
68 LUA_ASSERT(g->constindex >= 0, "userdata in global list"); 68 LUA_ASSERT(gv->name->u.s.gv == gv, "inconsistent global name");
69 if (g->u.s.globalval.ttype != LUA_T_NIL) { 69 if (gv->value.ttype != LUA_T_NIL) {
70 markobject(&g->u.s.globalval); 70 strmark(gv->name); /* cannot collect non nil global variables */
71 strmark(g); /* cannot collect non nil global variables */ 71 markobject(&gv->value);
72 } 72 }
73 } 73 }
74} 74}
@@ -157,12 +157,16 @@ static void collecttable (void) {
157} 157}
158 158
159 159
160/*
161** remove from the global list globals whose names will be collected
162** (the global itself is freed when its name is freed)
163*/
160static void clear_global_list (int limit) { 164static void clear_global_list (int limit) {
161 TaggedString **p = &L->rootglobal; 165 GlobalVar **p = &L->rootglobal;
162 TaggedString *next; 166 GlobalVar *next;
163 while ((next = *p) != NULL) { 167 while ((next = *p) != NULL) {
164 if (next->marked >= limit) p = &next->nextglobal; 168 if (next->name->marked >= limit) p = &next->next;
165 else *p = next->nextglobal; 169 else *p = next->next;
166 } 170 }
167} 171}
168 172
@@ -226,7 +230,7 @@ static void tableTM (void) {
226 230
227static void markall (void) { 231static void markall (void) {
228 travstack(); /* mark stack objects */ 232 travstack(); /* mark stack objects */
229 globalmark(); /* mark global variable values and names */ 233 travglobal(); /* mark global variable values and names */
230 travlock(); /* mark locked objects */ 234 travlock(); /* mark locked objects */
231 luaT_travtagmethods(markobject); /* mark tag methods */ 235 luaT_travtagmethods(markobject); /* mark tag methods */
232} 236}
@@ -239,8 +243,6 @@ void luaC_collect (int all) {
239 collectstring(all?MAX_INT:1); 243 collectstring(all?MAX_INT:1);
240 collectproto(); 244 collectproto();
241 collectclosure(); 245 collectclosure();
242 if (!all)
243 luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */
244} 246}
245 247
246 248
@@ -249,6 +251,7 @@ long lua_collectgarbage (long limit) {
249 markall(); 251 markall();
250 luaR_invalidaterefs(); 252 luaR_invalidaterefs();
251 luaC_collect(0); 253 luaC_collect(0);
254 luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */
252 recovered = recovered - L->nblocks; 255 recovered = recovered - L->nblocks;
253 L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit; 256 L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit;
254 return recovered; 257 return recovered;