]> granicus.if.org Git - gc/commitdiff
Add public GC_set/get_abort_func to replace default GC_on_abort
authorIvan Maidanski <ivmai@mail.ru>
Sat, 23 Jun 2012 18:42:36 +0000 (22:42 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Sun, 24 Jun 2012 09:21:43 +0000 (13:21 +0400)
* 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
include/private/gc_priv.h
misc.c

index f9405bb3205fd9b32a75db7bffaad4dcf31b4c0e..39c4293ecb4e2b6de374ee081f2e8afe40b3341d 100644 (file)
@@ -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   */
index 5ba0f718310c320ba144bbff76d996db6415cf51..49c1c80c002bd94e9ef0eeb7c039ef0d81f31285 100644 (file)
@@ -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 6e6eab22e2e5ee732c87ccb797736e2ed42141b7..945297dffafe01e9a65fd4369200ca405cfb9d90 100644 (file)
--- 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)