From c1fd9fee128f986df7ec452e574213aa292bd883 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 13 Feb 2023 09:20:13 +0100 Subject: [PATCH] std-aux: suppress verbose assert message with _nm_assert_fail() We also do that with g_return*() macros. These strings increase the binary size for little use. Drop them, unless we build with more asserts enabled. This affects nm_assert() messages. (cherry picked from commit d3548279c1ca761738e960a6c2935dbf0656baaf) --- src/libnm-glib-aux/nm-macros-internal.h | 12 ++++++------ src/libnm-std-aux/nm-std-aux.h | 13 ++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/libnm-glib-aux/nm-macros-internal.h b/src/libnm-glib-aux/nm-macros-internal.h index 71a17e3e37..0534ee5d9b 100644 --- a/src/libnm-glib-aux/nm-macros-internal.h +++ b/src/libnm-glib-aux/nm-macros-internal.h @@ -529,12 +529,12 @@ nm_str_realloc(char *str) /* redefine assertions to use g_assert*() */ #undef _nm_assert_fail -#define _nm_assert_fail(msg) \ - G_STMT_START \ - { \ - g_assertion_message_expr(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); \ - _nm_unreachable_code(); \ - } \ +#define _nm_assert_fail(msg) \ + G_STMT_START \ + { \ + g_assertion_message_expr(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, "" msg ""); \ + _nm_unreachable_code(); \ + } \ G_STMT_END #undef _NM_ASSERT_FAIL_ENABLED diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index 75703e70b4..a5e5abd3d5 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -221,15 +221,14 @@ typedef uint64_t _nm_bitwise nm_be64_t; #ifndef NDEBUG #define _NM_ASSERT_FAIL_ENABLED 1 -#define _nm_assert_fail(msg) __assert_fail((msg), __FILE__, __LINE__, __func__) +#define _nm_assert_fail(msg) \ + __assert_fail(((NM_MORE_ASSERTS) ? "" msg "" : ""), \ + __FILE__, \ + __LINE__, \ + ((NM_MORE_ASSERTS) ? __func__ : "")) #else #define _NM_ASSERT_FAIL_ENABLED 0 -#define _nm_assert_fail(msg) \ - do { \ - _nm_unused const char *_msg = (msg); \ - \ - _nm_unreachable_code(); \ - } while (0) +#define _nm_assert_fail(msg) ((void) ("" msg ""), _nm_unreachable_code()) #endif #define NM_MORE_ASSERTS_EFFECTIVE (_NM_ASSERT_FAIL_ENABLED ? NM_MORE_ASSERTS : 0)