Skip to content

Commit

Permalink
Add public GC_set/get_abort_func to replace default GC_on_abort
Browse files Browse the repository at this point in the history
* 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
ivmai committed Jun 24, 2012
1 parent 770355f commit d020903
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
11 changes: 11 additions & 0 deletions include/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
23 changes: 22 additions & 1 deletion misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d020903

Please sign in to comment.