diff options
-rw-r--r-- | cord/cordxtra.c | 12 | ||||
-rw-r--r-- | cord/tests/cordtest.c | 4 | ||||
-rw-r--r-- | include/gc/gc_cpp.h | 42 | ||||
-rw-r--r-- | tests/cpp.cc | 4 | ||||
-rw-r--r-- | tests/disclaim_bench.c | 9 | ||||
-rw-r--r-- | tests/gctest.c | 4 |
6 files changed, 48 insertions, 27 deletions
diff --git a/cord/cordxtra.c b/cord/cordxtra.c index 3771997e..f7bb1ad2 100644 --- a/cord/cordxtra.c +++ b/cord/cordxtra.c @@ -573,12 +573,14 @@ char CORD_lf_func(size_t i, void * client_data) return(cl -> data[MOD_LINE_SZ(i)]); } -void CORD_lf_close_proc(void * obj, void * client_data CORD_ATTR_UNUSED) -{ +#ifndef GC_NO_FINALIZATION + void CORD_lf_close_proc(void * obj, void * client_data CORD_ATTR_UNUSED) + { if (fclose(((lf_state *)obj) -> lf_file) != 0) { ABORT("CORD_lf_close_proc: fclose failed"); } -} + } +#endif CORD CORD_from_file_lazy_inner(FILE * f, size_t len) { @@ -604,7 +606,9 @@ CORD CORD_from_file_lazy_inner(FILE * f, size_t len) state -> lf_cache[i] = 0; } state -> lf_current = 0; - GC_REGISTER_FINALIZER(state, CORD_lf_close_proc, 0, 0, 0); +# ifndef GC_NO_FINALIZATION + GC_REGISTER_FINALIZER(state, CORD_lf_close_proc, 0, 0, 0); +# endif return(CORD_from_fn(CORD_lf_func, state, len)); } diff --git a/cord/tests/cordtest.c b/cord/tests/cordtest.c index 16362973..44e36ba9 100644 --- a/cord/tests/cordtest.c +++ b/cord/tests/cordtest.c @@ -221,8 +221,10 @@ void test_extras(void) *(CORD volatile *)&w = CORD_EMPTY; *(CORD volatile *)&z = CORD_EMPTY; GC_gcollect(); - GC_invoke_finalizers(); +# ifndef GC_NO_FINALIZATION + GC_invoke_finalizers(); /* Of course, this does not guarantee the files are closed. */ +# endif if (remove(FNAME1) != 0) { /* On some systems, e.g. OS2, this may fail if f1 is still open. */ /* But we cannot call fclose as it might lead to double close. */ diff --git a/include/gc/gc_cpp.h b/include/gc/gc_cpp.h index 8a429aff..bc105e21 100644 --- a/include/gc/gc_cpp.h +++ b/include/gc/gc_cpp.h @@ -473,9 +473,11 @@ inline void gc::operator delete(void* obj) GC_NOEXCEPT inline gc_cleanup::~gc_cleanup() { - void* base = GC_base(this); - if (0 == base) return; // Non-heap object. - GC_register_finalizer_ignore_self(base, 0, 0, 0, 0); +# ifndef GC_NO_FINALIZATION + void* base = GC_base(this); + if (0 == base) return; // Non-heap object. + GC_register_finalizer_ignore_self(base, 0, 0, 0, 0); +# endif } inline void GC_CALLBACK gc_cleanup::cleanup(void* obj, void* displ) @@ -485,19 +487,21 @@ inline void GC_CALLBACK gc_cleanup::cleanup(void* obj, void* displ) inline gc_cleanup::gc_cleanup() { - GC_finalization_proc oldProc = 0; - void* oldData = NULL; // to avoid "might be uninitialized" compiler warning - void* this_ptr = (void*)this; - void* base = GC_base(this_ptr); - if (base != 0) { - // Don't call the debug version, since this is a real base address. - GC_register_finalizer_ignore_self(base, (GC_finalization_proc) cleanup, - (void*)((char*)this_ptr - (char*)base), - &oldProc, &oldData); - if (oldProc != 0) { - GC_register_finalizer_ignore_self(base, oldProc, oldData, 0, 0); +# ifndef GC_NO_FINALIZATION + GC_finalization_proc oldProc = 0; + void* oldData = NULL; // to avoid "might be uninitialized" compiler warning + void* this_ptr = (void*)this; + void* base = GC_base(this_ptr); + if (base != 0) { + // Don't call the debug version, since this is a real base address. + GC_register_finalizer_ignore_self(base, (GC_finalization_proc) cleanup, + (void*)((char*)this_ptr-(char*)base), + &oldProc, &oldData); + if (oldProc != 0) { + GC_register_finalizer_ignore_self(base, oldProc, oldData, 0, 0); + } } - } +# endif } #ifdef GC_NAMESPACE @@ -512,9 +516,11 @@ inline void* operator new(size_t size, GC_NS_QUALIFY(GCPlacement) gcp, switch (gcp) { case GC_NS_QUALIFY(UseGC): obj = GC_MALLOC(size); - if (cleanup != 0 && obj != 0) { - GC_REGISTER_FINALIZER_IGNORE_SELF(obj, cleanup, clientData, 0, 0); - } +# ifndef GC_NO_FINALIZATION + if (cleanup != 0 && obj != 0) { + GC_REGISTER_FINALIZER_IGNORE_SELF(obj, cleanup, clientData, 0, 0); + } +# endif break; case GC_NS_QUALIFY(PointerFreeGC): obj = GC_MALLOC_ATOMIC(size); diff --git a/tests/cpp.cc b/tests/cpp.cc index 90b1947e..6a19fe71 100644 --- a/tests/cpp.cc +++ b/tests/cpp.cc @@ -372,7 +372,7 @@ void* Undisguise( GC_word i ) { B::Deleting( 1 ); GC_CHECKED_DELETE(b); B::Deleting( 0 );} -# ifdef FINALIZE_ON_DEMAND +# if defined(FINALIZE_ON_DEMAND) && !defined(GC_NO_FINALIZATION) GC_invoke_finalizers(); # endif } @@ -394,7 +394,7 @@ void* Undisguise( GC_word i ) { B::Deleting( 1 ); GC_CHECKED_DELETE(b); B::Deleting( 0 ); -# ifdef FINALIZE_ON_DEMAND +# if defined(FINALIZE_ON_DEMAND) && !defined(GC_NO_FINALIZATION) GC_invoke_finalizers(); # endif } diff --git a/tests/disclaim_bench.c b/tests/disclaim_bench.c index 1eed6275..e9fa9c9d 100644 --- a/tests/disclaim_bench.c +++ b/tests/disclaim_bench.c @@ -62,12 +62,14 @@ testobj_t testobj_new(int model) { testobj_t obj; switch (model) { +# ifndef GC_NO_FINALIZATION case 0: obj = GC_NEW(struct testobj_s); if (obj != NULL) GC_REGISTER_FINALIZER_NO_ORDER(obj, testobj_finalize, &free_count, NULL, NULL); break; +# endif case 1: obj = (testobj_t)GC_finalized_malloc(sizeof(struct testobj_s), &fclos); @@ -116,9 +118,12 @@ int main(int argc, char **argv) model_min = model_max = (int)COVERT_DATAFLOW(atoi(argv[1])); if (model_min < 0 || model_max > 2) exit(2); - } - else { + } else { +# ifndef GC_NO_FINALIZATION model_min = 0; +# else + model_min = 1; +# endif model_max = 2; } if (GC_get_find_leak()) diff --git a/tests/gctest.c b/tests/gctest.c index 43a09141..b394ce2a 100644 --- a/tests/gctest.c +++ b/tests/gctest.c @@ -60,6 +60,10 @@ # include <assert.h> /* Not normally used, but handy for debugging. */ # endif +#if defined(GC_NO_FINALIZATION) && !defined(NO_TYPED_TEST) +# define NO_TYPED_TEST +#endif + #ifndef NO_TYPED_TEST # include "gc/gc_typed.h" #endif |