From 5974428d2561b13072d627f85f012886f0df7ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Wed, 30 Mar 2016 13:56:43 +0000 Subject: [PATCH] Add g_abort() The new g_abort() macro just expands to abort() on systems where abort() behaves in a sane way. On other systems (read: Windows) it does its best to emulate a sane abort() behaviour. https://bugzilla.gnome.org/show_bug.cgi?id=665446 --- glib/gutils.c | 24 ++++++++++++++++++++++++ glib/gutils.h | 10 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/glib/gutils.c b/glib/gutils.c index 43a277629..4d0794157 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -2390,3 +2390,27 @@ g_check_setuid (void) return FALSE; #endif } + +/** + * g_abort: + * + * A wrapper for the POSIX abort() function. + * + * On Windows it is a function that makes extra effort (including a call + * to abort()) to ensure that a debugger-catchable exception is thrown + * before the program terminates. + * + * See your C library manual for more details about abort(). + * + * Since: 2.50 + */ +void +g_abort (void) +{ + /* One call to break the debugger */ + DebugBreak (); + /* One call in case CRT does get saner about abort() behaviour */ + abort (); + /* And one call to bind them all and terminate the program for sure */ + ExitProcess (127); +} diff --git a/glib/gutils.h b/glib/gutils.h index b24bc0b96..f84fbcb0b 100644 --- a/glib/gutils.h +++ b/glib/gutils.h @@ -299,6 +299,16 @@ g_bit_storage_impl (gulong number) #endif } +/* Crashes the program. */ +#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_50 +#ifndef G_OS_WIN32 +# define g_abort() abort () +#else +GLIB_AVAILABLE_IN_2_50 +void g_abort (void) G_GNUC_NORETURN G_ANALYZER_NORETURN; +#endif +#endif + #ifndef G_DISABLE_DEPRECATED /*