From: Ivan Maidanski Date: Mon, 23 Jan 2012 16:08:30 +0000 (+0400) Subject: Split GC_abort with GC_on_abort and abort() invoked from ABORT X-Git-Tag: gc7_3alpha2~197 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aef9081b60bcfc2580b09ea4b9f57e34b34e5339;p=gc Split GC_abort with GC_on_abort and abort() invoked from ABORT (to let ABORT inherit 'noreturn' attribute of abort) * misc.c (GC_abort): Replace with GC_on_abort (return from GC_on_abort instead of abort); update the comment. * include/private/gc_priv.h (GC_abort): Likewise. * include/private/gc_priv.h (GC_on_abort): Define as empty macro in case of SMALL_CONFIG. * include/private/gc_priv.h (ABORT): Always call GC_on_abort (unless PCR) and abort (or _exit, or ExitProcess or DebugBreak, depending on the target). --- diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 32f1eba4..407458b5 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -436,16 +436,24 @@ typedef char * ptr_t; /* A generic pointer to which we can add */ # define DebugBreak() _exit(-1) /* there is no abort() in WinCE */ # endif # ifdef SMALL_CONFIG -# if (defined(MSWIN32) && !defined(LINT2)) || defined(MSWINCE) -# define ABORT(msg) DebugBreak() -# else -# define ABORT(msg) abort() -# endif +# define GC_on_abort(msg) (void)0 /* be silent on abort */ # else - GC_API_PRIV void GC_abort(const char * msg); -# define ABORT(msg) GC_abort(msg) -# endif -# endif + GC_API_PRIV void GC_on_abort(const char * msg); +# endif /* !SMALL_CONFIG */ +# if defined(MSWIN32) && (defined(NO_DEBUGGING) || defined(LINT2)) + /* A more user-friendly abort after showing fatal message. */ +# define ABORT(msg) (GC_on_abort(msg), _exit(-1)) + /* Exit on error without running "at-exit" callbacks. */ +# elif defined(MSWINCE) && defined(NO_DEBUGGING) +# define ABORT(msg) (GC_on_abort(msg), ExitProcess(-1)) +# elif defined(MSWIN32) || defined(MSWINCE) +# define ABORT(msg) (GC_on_abort(msg), DebugBreak()) + /* Note that on a WinCE box, this could be silently */ + /* ignored (i.e., the program is not aborted). */ +# else +# define ABORT(msg) (GC_on_abort(msg), abort()) +# endif /* !MSWIN32 */ +# endif /* !PCR */ /* Same as ABORT but does not have 'no-return' attribute. */ /* ABORT on dummy condition (which is always true). */ diff --git a/misc.c b/misc.c index e4f31b92..b4bea7a8 100644 --- a/misc.c +++ b/misc.c @@ -1397,8 +1397,8 @@ GC_API GC_warn_proc GC_CALL GC_get_warn_proc(void) } #if !defined(PCR) && !defined(SMALL_CONFIG) - /* Abort the program with a message. msg must not be NULL. */ - void GC_abort(const char *msg) + /* Print (or display) a message before abort. msg must not be NULL. */ + void GC_on_abort(const char *msg) { # if defined(MSWIN32) # ifndef DONT_USE_USER32_DLL @@ -1418,7 +1418,7 @@ GC_API GC_warn_proc GC_CALL GC_get_warn_proc(void) # endif /* Also duplicate msg to GC log file. */ # endif - /* Avoid calling GC_err_printf() here, as GC_abort() could be */ + /* Avoid calling GC_err_printf() here, as GC_on_abort() could be */ /* called from it. Note 1: this is not an atomic output. */ /* Note 2: possible write errors are ignored. */ if (WRITE(GC_stderr, (void *)msg, strlen(msg)) >= 0) @@ -1429,23 +1429,10 @@ GC_API GC_warn_proc GC_CALL GC_get_warn_proc(void) /* It's arguably nicer to sleep, but that makes it harder */ /* to look at the thread if the debugger doesn't know much */ /* about threads. */ - for(;;) {} + for(;;) { + /* Empty */ + } } -# ifndef LINT2 - if (!msg) return; /* to suppress compiler warnings in ABORT callers. */ -# endif -# if defined(MSWIN32) && (defined(NO_DEBUGGING) || defined(LINT2)) - /* A more user-friendly abort after showing fatal message. */ - _exit(-1); /* exit on error without running "at-exit" callbacks */ -# elif defined(MSWINCE) && defined(NO_DEBUGGING) - ExitProcess(-1); -# elif defined(MSWIN32) || defined(MSWINCE) - DebugBreak(); - /* Note that on a WinCE box, this could be silently */ - /* ignored (i.e., the program is not aborted). */ -# else - (void) abort(); -# endif } #endif /* !SMALL_CONFIG */