aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lgc.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/lgc.c b/lgc.c
index 1afd9c80..afaba8c2 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.149 2002/09/02 19:54:49 roberto Exp roberto $ 2** $Id: lgc.c,v 1.150 2002/09/05 19:57:40 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*/
@@ -249,9 +249,8 @@ static int valismarked (const TObject *o) {
249/* 249/*
250** clear collected keys from weaktables 250** clear collected keys from weaktables
251*/ 251*/
252static void cleartablekeys (GCState *st) { 252static void cleartablekeys (Table *h) {
253 Table *h; 253 for (; h; h = h->gclist) {
254 for (h = st->toclear; h; h = h->gclist) {
255 lua_assert(h->mode & (WEAKKEY | WEAKVALUE)); 254 lua_assert(h->mode & (WEAKKEY | WEAKVALUE));
256 if ((h->mode & WEAKKEY)) { /* table may have collected keys? */ 255 if ((h->mode & WEAKKEY)) { /* table may have collected keys? */
257 int i = sizenode(h); 256 int i = sizenode(h);
@@ -268,9 +267,8 @@ static void cleartablekeys (GCState *st) {
268/* 267/*
269** clear collected values from weaktables 268** clear collected values from weaktables
270*/ 269*/
271static void cleartablevalues (GCState *st) { 270static void cleartablevalues (Table *h) {
272 Table *h; 271 for (; h; h = h->gclist) {
273 for (h = st->toclear; h; h = h->gclist) {
274 if ((h->mode & WEAKVALUE)) { /* table may have collected values? */ 272 if ((h->mode & WEAKVALUE)) { /* table may have collected values? */
275 int i = sizearray(h); 273 int i = sizearray(h);
276 while (i--) { 274 while (i--) {
@@ -395,17 +393,22 @@ void luaC_sweep (lua_State *L, int all) {
395 393
396void luaC_collectgarbage (lua_State *L) { 394void luaC_collectgarbage (lua_State *L) {
397 GCState st; 395 GCState st;
396 Table *toclear;
398 st.L = L; 397 st.L = L;
399 st.tmark = NULL; 398 st.tmark = NULL;
400 st.toclear = NULL; 399 st.toclear = NULL;
401 traversestacks(&st); /* mark all stacks */ 400 traversestacks(&st); /* mark all stacks */
402 propagatemarks(&st); /* mark all reachable objects */ 401 propagatemarks(&st); /* mark all reachable objects */
403 cleartablevalues(&st); 402 toclear = st.toclear; /* weak tables; to be cleared */
403 st.toclear = NULL;
404 cleartablevalues(toclear);
404 separateudata(L); /* separate userdata to be preserved */ 405 separateudata(L); /* separate userdata to be preserved */
405 marktmu(&st); /* mark `preserved' userdata */ 406 marktmu(&st); /* mark `preserved' userdata */
406 propagatemarks(&st); /* remark, to propagate `preserveness' */ 407 propagatemarks(&st); /* remark, to propagate `preserveness' */
407 cleartablevalues(&st); /* again, for eventual weak preserved tables */ 408 cleartablekeys(toclear);
408 cleartablekeys(&st); 409 /* `propagatemarks' may reborne some weak tables; clear them too */
410 cleartablekeys(st.toclear);
411 cleartablevalues(st.toclear);
409 luaC_sweep(L, 0); 412 luaC_sweep(L, 0);
410 checkSizes(L); 413 checkSizes(L);
411 G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */ 414 G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */