From 93d0fd68aa4dfc54fca92aa48c51fae9eda470d8 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 18 Nov 2014 08:00:40 +0100 Subject: [PATCH] Backport g_assert_null() and g_assert_nonnull() These were added in newer GLibbversions, but upgrading requirements just because of these would be an overkill. --- tests/test-asserts.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test-asserts.h b/tests/test-asserts.h index 756d107..0f065ac 100644 --- a/tests/test-asserts.h +++ b/tests/test-asserts.h @@ -24,4 +24,22 @@ } \ } G_STMT_END +/* g_assert_null() and g_assert_nonnull() were defined in 2.36 and + * 2.40. Requiring a newer GLib just because of this would be an + * overkill, so let's just backport them: + */ +#ifndef g_assert_null +#define g_assert_null(expr) do { if G_LIKELY ((expr) == NULL) ; else \ + g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ + "'" #expr "' should be NULL"); \ + } while (0) +#endif + +#ifndef g_assert_nonnull +#define g_assert_nonnull(expr) do { if G_LIKELY ((expr) != NULL) ; else \ + g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ + "'" #expr "' should not be NULL"); \ + } while (0) +#endif + #endif /* __SWE_GLIB_TEST_ASSERTS_H__ */