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 d3548279c1)
This commit is contained in:
Thomas Haller 2023-02-13 09:20:13 +01:00
parent f5c48ee238
commit c1fd9fee12
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 12 additions and 13 deletions

View file

@ -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

View file

@ -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 "" : "<dropped>"), \
__FILE__, \
__LINE__, \
((NM_MORE_ASSERTS) ? __func__ : "<unknown-fcn>"))
#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)