diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-09-19 16:54:22 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-09-19 16:54:22 -0300 |
commit | 6fb0fd506367d70fb83a7885441fc5bd499e937a (patch) | |
tree | 84ea7d0d53e6bc613c3fdcbc66360e8ee587d7c7 /lgc.c | |
parent | 565e6d74e1440b1500d0ba0d3757307de0a38b9e (diff) | |
download | lua-6fb0fd506367d70fb83a7885441fc5bd499e937a.tar.gz lua-6fb0fd506367d70fb83a7885441fc5bd499e937a.tar.bz2 lua-6fb0fd506367d70fb83a7885441fc5bd499e937a.zip |
avoid `reclearing' weak tables
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -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 | */ |
252 | static void cleartablekeys (GCState *st) { | 252 | static 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 | */ |
271 | static void cleartablevalues (GCState *st) { | 270 | static 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 | ||
396 | void luaC_collectgarbage (lua_State *L) { | 394 | void 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 */ |