From a32c9c7e9c9500f151ccae602d92f88e43d8df45 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 2 Feb 2013 12:47:54 -0500 Subject: [PATCH] Make g_assert and g_assert_not_reached use the same entry point These two assertion macros are commonly used outside tests, so we can't repurpose them, as we are going to do with the other assertion macros in the following commits. This change is in preparation for that. https://bugzilla.gnome.org/show_bug.cgi?id=692125 --- glib/gtestutils.c | 6 +++++- glib/gtestutils.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/glib/gtestutils.c b/glib/gtestutils.c index e74d11e..f1116a5 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -2218,7 +2218,11 @@ g_assertion_message_expr (const char *domain, const char *func, const char *expr) { - char *s = g_strconcat ("assertion failed: (", expr, ")", NULL); + char *s; + if (!expr) + s = g_strdup ("code should not be reached"); + else + s = g_strconcat ("assertion failed: (", expr, ")", NULL); g_assertion_message (domain, file, line, func, s); g_free (s); } diff --git a/glib/gtestutils.h b/glib/gtestutils.h index 30e07ca..ba8aa4b 100644 --- a/glib/gtestutils.h +++ b/glib/gtestutils.h @@ -70,7 +70,7 @@ typedef void (*GTestFixtureFunc) (gpointer fixture, #define g_assert_not_reached() do { (void) 0; } while (0) #define g_assert(expr) do { (void) 0; } while (0) #else /* !G_DISABLE_ASSERT */ -#define g_assert_not_reached() do { g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); } while (0) +#define g_assert_not_reached() do { g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); } while (0) #define g_assert(expr) do { if G_LIKELY (expr) ; else \ g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ #expr); } while (0) -- 2.7.4