From 91f9635c1e8f649839a005b0468c1d77c2c87987 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 24 Jan 2008 15:21:33 +0000 Subject: [PATCH] fix GC bug related to park[] and finalization svn: r8397 --- src/mzscheme/gc2/compact.c | 14 +++++++++++++- src/mzscheme/gc2/newgc.c | 15 ++++++++++++++- src/mzscheme/src/schemef.h | 4 ++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/mzscheme/gc2/compact.c b/src/mzscheme/gc2/compact.c index fc0d1258ff..90d66ce4b5 100644 --- a/src/mzscheme/gc2/compact.c +++ b/src/mzscheme/gc2/compact.c @@ -386,7 +386,7 @@ static int running_finals; static char zero_sized[4]; /* Temporary pointer-holder used by routines that allocate */ -static void *park[2]; +static void *park[2], *park_save[2]; static int during_gc, avoid_collection; @@ -2825,6 +2825,7 @@ static void init(void) GC_add_roots(&run_queue, (char *)&run_queue + sizeof(run_queue) + 1); GC_add_roots(&last_in_queue, (char *)&last_in_queue + sizeof(last_in_queue) + 1); GC_add_roots(&park, (char *)&park + sizeof(park) + 1); + GC_add_roots(&park_save, (char *)&park_save + sizeof(park_save) + 1); sets[0] = &tagged; sets[1] = &array; @@ -3487,6 +3488,12 @@ static void gcollect(int full) if (!running_finals) { running_finals = 1; + /* Finalization might allocate, which might need park: */ + park_save[0] = park[0]; + park_save[1] = park[1]; + park[0] = NULL; + park[1] = NULL; + while (run_queue) { Fnl *f; void **gcs; @@ -3505,6 +3512,11 @@ static void gcollect(int full) } running_finals = 0; + + park[0] = park_save[0]; + park[1] = park_save[1]; + park_save[0] = NULL; + park_save[1] = NULL; } } diff --git a/src/mzscheme/gc2/newgc.c b/src/mzscheme/gc2/newgc.c index 331f965eae..2e6aa0784b 100644 --- a/src/mzscheme/gc2/newgc.c +++ b/src/mzscheme/gc2/newgc.c @@ -136,7 +136,7 @@ void (*GC_fixup_xtagged)(void *obj); #include "my_qsort.c" -static void *park[2]; +static void *park[2], *park_save[2]; /*****************************************************************************/ /* OS-Level Memory Management Routines */ @@ -2117,6 +2117,7 @@ void GC_init_type_tags(int count, int pair, int mutable_pair, int weakbox, int e fixup_weak_array, 0, 0); initialize_signal_handler(); GC_add_roots(&park, (char *)&park + sizeof(park) + 1); + GC_add_roots(&park_save, (char *)&park_save + sizeof(park_save) + 1); initialize_protect_page_ranges(malloc_dirty_pages(APAGE_SIZE, APAGE_SIZE), APAGE_SIZE); } @@ -3202,6 +3203,13 @@ static void garbage_collect(int force_full) finalizer completes its execution */ if(!running_finalizers) { running_finalizers = 1; + + /* Finalization might allocate, which might need park: */ + park_save[0] = park[0]; + park_save[1] = park[1]; + park[0] = NULL; + park[1] = NULL; + while(run_queue) { struct finalizer *f; void **gcs; @@ -3217,6 +3225,11 @@ static void garbage_collect(int force_full) } run_account_hooks(); running_finalizers = 0; + + park[0] = park_save[0]; + park[1] = park_save[1]; + park_save[0] = NULL; + park_save[1] = NULL; } DUMP_HEAP(); CLOSE_DEBUG_FILE(); diff --git a/src/mzscheme/src/schemef.h b/src/mzscheme/src/schemef.h index 30762e87df..34869703d3 100644 --- a/src/mzscheme/src/schemef.h +++ b/src/mzscheme/src/schemef.h @@ -615,8 +615,8 @@ MZ_EXTERN Scheme_Object *scheme_rational_from_float(float d); # define scheme_rational_from_float scheme_rational_from_double #endif MZ_EXTERN Scheme_Object *scheme_rational_normalize(const Scheme_Object *n); -MZ_EXTERN Scheme_Object *scheme_rational_numerator(const Scheme_Object *n); -MZ_EXTERN Scheme_Object *scheme_rational_denominator(const Scheme_Object *n); +XFORM_NONGCING MZ_EXTERN Scheme_Object *scheme_rational_numerator(const Scheme_Object *n); +XFORM_NONGCING MZ_EXTERN Scheme_Object *scheme_rational_denominator(const Scheme_Object *n); /*========================================================================*/ /* complexes */