Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit d020903787f3aa4f949bd5c48083cfd71d36df6f 1 parent 770355f
@ivmai authored
Showing with 34 additions and 2 deletions.
  1. +11 −0 include/gc.h
  2. +1 −1  include/private/gc_priv.h
  3. +22 −1 misc.c
View
11 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 */
View
2  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. */
View
23 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)
Please sign in to comment.
Something went wrong with that request. Please try again.