From a09c8d7beb79611a7bc5f2b6f8255cc18b0feef3 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 5 Apr 2010 11:15:35 -0300 Subject: [PATCH] cannot sweep main thread in sweepstring phase --- lgc.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lgc.c b/lgc.c index acbbf9c5..2988467c 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.75 2010/03/29 17:43:14 roberto Exp roberto $ +** $Id: lgc.c,v 2.76 2010/04/02 14:37:41 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -778,25 +778,34 @@ static l_mem singlestep (lua_State *L) { sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]); } else { /* no more strings to sweep */ - /* sweep main thread */ - sweeplist(L, cast(GCObject **, &g->mainthread), 1); g->sweepgc = &g->udgc; /* prepare to sweep userdata */ g->gcstate = GCSsweepudata; } return GCSWEEPCOST; } - case GCSsweepudata: - case GCSsweep: { + case GCSsweepudata: { if (*g->sweepgc) { g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); return GCSWEEPMAX*GCSWEEPCOST; } else { /* go to next phase */ - g->sweepgc = &g->allgc; /* useless (but harmless) in GCSsweep case */ - g->gcstate = (g->gcstate == GCSsweep) ? GCSfinalize : GCSsweep; + g->sweepgc = &g->allgc; + g->gcstate = GCSsweep; return 0; } } + case GCSsweep: { + if (*g->sweepgc) { + g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); + return GCSWEEPMAX*GCSWEEPCOST; + } + else { + /* sweep main thread */ + sweeplist(L, cast(GCObject **, &g->mainthread), 1); + g->gcstate = GCSfinalize; /* go to next phase */ + return GCSWEEPCOST; + } + } case GCSfinalize: { if (g->tobefnz) { GCTM(L, 1);