From ba950cedee5c4a92d9fb7e00f58b9f97a151b9e8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Oct 2016 14:44:02 +0200 Subject: [PATCH] shared: add nm_assert_se() macro We usually don't build NM with g_assert() disabled (G_DISABLE_ASSERT). But even if we would, there is no assertion macro that always evaluates the condition for possible side effects. I think that is a useful thing to have. --- shared/nm-utils/nm-macros-internal.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 26b69bc138..658b3b92a4 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -305,9 +305,11 @@ nm_strdup_not_empty (const char *str) #if NM_MORE_ASSERTS #define nm_assert(cond) G_STMT_START { g_assert (cond); } G_STMT_END +#define nm_assert_se(cond) G_STMT_START { if (G_LIKELY (cond)) { ; } else { g_assert (FALSE && (cond)); } } G_STMT_END #define nm_assert_not_reached() G_STMT_START { g_assert_not_reached (); } G_STMT_END #else #define nm_assert(cond) G_STMT_START { if (FALSE) { if (cond) { } } } G_STMT_END +#define nm_assert_se(cond) G_STMT_START { if (G_LIKELY (cond)) { ; } } G_STMT_END #define nm_assert_not_reached() G_STMT_START { ; } G_STMT_END #endif