Browse Source

bug: collector did not compensate enough for userdata with finalizers

v5-2
Roberto Ierusalimschy 19 years ago
parent
commit
0079efc479
  1. 12
      lgc.c

12
lgc.c

@ -1,5 +1,5 @@
/* /*
** $Id: lgc.c,v 2.36 2005/08/24 17:06:36 roberto Exp roberto $ ** $Id: lgc.c,v 2.37 2005/12/22 16:19:56 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -320,8 +320,10 @@ static l_mem propagatemark (global_State *g) {
} }
static void propagateall (global_State *g) { static size_t propagateall (global_State *g) {
while (g->gray) propagatemark(g); size_t m = 0;
while (g->gray) m += propagatemark(g);
return m;
} }
@ -540,7 +542,7 @@ static void atomic (lua_State *L) {
propagateall(g); propagateall(g);
udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */ udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */
marktmu(g); /* mark `preserved' userdata */ marktmu(g); /* mark `preserved' userdata */
propagateall(g); /* remark, to propagate `preserveness' */ udsize += propagateall(g); /* remark, to propagate `preserveness' */
cleartable(g->weak); /* remove collected objects from weak tables */ cleartable(g->weak); /* remove collected objects from weak tables */
/* flip current white */ /* flip current white */
g->currentwhite = cast_byte(otherwhite(g)); g->currentwhite = cast_byte(otherwhite(g));
@ -590,6 +592,8 @@ static l_mem singlestep (lua_State *L) {
case GCSfinalize: { case GCSfinalize: {
if (g->tmudata) { if (g->tmudata) {
GCTM(L); GCTM(L);
if (g->estimate > GCFINALIZECOST)
g->estimate -= GCFINALIZECOST;
return GCFINALIZECOST; return GCFINALIZECOST;
} }
else { else {

Loading…
Cancel
Save