From d020903787f3aa4f949bd5c48083cfd71d36df6f Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sat, 23 Jun 2012 22:42:36 +0400 Subject: [PATCH] Add public GC_set/get_abort_func to replace default GC_on_abort * include/gc.h (GC_abort_func): New public typedef. * include/gc.h (GC_set_abort_func, GC_get_abort_func): New API function declaration. * include/private/gc_priv.h (GC_on_abort): Change function declaration to function pointer of GC_abort_func type (only if SMALL_CONFIG and not PCR). * misc.c (GC_on_abort): Rename to GC_default_on_abort; make it STATIC and decorate with GC_CALLBACK; define GC_on_abort variable initialized to GC_default_on_abort (only if SMALL_CONFIG and not PCR). * misc.c (GC_set_abort_func, GC_get_abort_func): New public function (only if if SMALL_CONFIG and not PCR) to alter and read GC_on_abort value. --- include/gc.h | 11 +++++++++++ include/private/gc_priv.h | 2 +- misc.c | 23 ++++++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/gc.h b/include/gc.h index f9405bb3..39c4293e 100644 --- a/include/gc.h +++ b/include/gc.h @@ -1058,6 +1058,17 @@ GC_API GC_warn_proc GC_CALL GC_get_warn_proc(void); /* to suppress all warnings (unless statistics printing is turned on). */ GC_API void GC_CALLBACK GC_ignore_warn_proc(char *, GC_word); +/* abort_func is invoked on GC fatal aborts (just before OS-dependent */ +/* abort or exit(1) is called). Must be non-NULL. The default one */ +/* outputs msg to stderr provided msg is non-NULL. msg is NULL if */ +/* invoked before exit(1) otherwise msg is non-NULL (i.e., if invoked */ +/* before abort). Both the setter and getter acquire the GC lock. */ +/* Both the setter and getter are defined only if the library has been */ +/* compiled without SMALL_CONFIG. */ +typedef void (GC_CALLBACK * GC_abort_func)(const char * /* msg */); +GC_API void GC_CALL GC_set_abort_func(GC_abort_func) GC_ATTR_NONNULL(1); +GC_API GC_abort_func GC_CALL GC_get_abort_func(void); + /* The following is intended to be used by a higher level */ /* (e.g. Java-like) finalization facility. It is expected */ /* that finalization code will arrange for hidden pointers to */ diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 5ba0f718..49c1c80c 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -467,7 +467,7 @@ typedef char * ptr_t; /* A generic pointer to which we can add */ # ifdef SMALL_CONFIG # define GC_on_abort(msg) (void)0 /* be silent on abort */ # else - GC_API_PRIV void GC_on_abort(const char * msg); + GC_API_PRIV GC_abort_func GC_on_abort; # endif /* !SMALL_CONFIG */ # if defined(MSWIN32) && (defined(NO_DEBUGGING) || defined(LINT2)) /* A more user-friendly abort after showing fatal message. */ diff --git a/misc.c b/misc.c index 6e6eab22..945297df 100644 --- a/misc.c +++ b/misc.c @@ -1465,7 +1465,7 @@ GC_API GC_warn_proc GC_CALL GC_get_warn_proc(void) /* Print (or display) a message before abnormal exit (including */ /* abort). Invoked from ABORT(msg) macro (there msg is non-NULL) */ /* and from EXIT() macro (msg is NULL in that case). */ - void GC_on_abort(const char *msg) + STATIC void GC_CALLBACK GC_default_on_abort(const char *msg) { if (msg != NULL) { # if defined(MSWIN32) @@ -1506,6 +1506,27 @@ GC_API GC_warn_proc GC_CALL GC_get_warn_proc(void) } # endif } + + GC_abort_func GC_on_abort = GC_default_on_abort; + + GC_API void GC_CALL GC_set_abort_func(GC_abort_func fn) + { + DCL_LOCK_STATE; + GC_ASSERT(fn != 0); + LOCK(); + GC_on_abort = fn; + UNLOCK(); + } + + GC_API GC_abort_func GC_CALL GC_get_abort_func(void) + { + GC_abort_func fn; + DCL_LOCK_STATE; + LOCK(); + fn = GC_on_abort; + UNLOCK(); + return fn; + } #endif /* !SMALL_CONFIG */ GC_API void GC_CALL GC_enable(void) -- 2.40.0