diff options
author | Thomas Haller <thaller@redhat.com> | 2016-06-06 15:20:05 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-06-09 12:03:39 +0200 |
commit | 00f58adb16ef469f0e6110095a0536bcd07e6366 (patch) | |
tree | b7bb55599cba27268f8f9665e74e4badba066b3a | |
parent | fa973afa192a2b4e8566864bb9ceb5ff1d9b287f (diff) | |
download | NetworkManager-00f58adb16ef469f0e6110095a0536bcd07e6366.tar.gz |
build: remove assertion messages in non-debug build
Assertions like g_assert*() and g_return_*() contain the stringified
test expression. This string ends up in the binary and increases its
size.
We usually don't have failing assertions. These string are a waste,
instead the file and line number shall suffice.
It reduces the striped size of the NetworkManager binary from 2500k
to 2392k, that is -108k, -4.3%.
This changes
- "g_assert (1 == 2);"
from: NetworkManager:ERROR:source.c:347:some_function: assertion failed: (1 == 2)
to: NetworkManager:ERROR:source.c:347:<unknown-fcn>: assertion failed: (<dropped>)
- "g_return_if_fail (1 == 2);"
from: (process:21024): NetworkManager-CRITICAL **: some_function: assertion '1 == 2' failed
to: (process:21024): NetworkManager-CRITICAL **: ((source.c:347)): assertion '<dropped>' failed
When doing a non-debug build, those string are now removed. Debug-builds
can be enabled by setting --with-more-assert=$LEVEL to larger then zero.
https://bugzilla.gnome.org/show_bug.cgi?id=767296
-rw-r--r-- | shared/nm-default.h | 44 | ||||
-rw-r--r-- | shared/nm-test-utils.h | 7 |
2 files changed, 50 insertions, 1 deletions
diff --git a/shared/nm-default.h b/shared/nm-default.h index aeb977a935..5d7c8f141c 100644 --- a/shared/nm-default.h +++ b/shared/nm-default.h @@ -53,6 +53,50 @@ #define NM_VERSION_MIN_REQUIRED NM_VERSION_0_9_8 #include <stdlib.h> +#include <glib.h> + +/*****************************************************************************/ + +#ifndef NM_MORE_ASSERTS +#define NM_MORE_ASSERTS 0 +#endif + +#if NM_MORE_ASSERTS == 0 + +/* glib assertions (g_return_*(), g_assert*()) contain a textual representation + * of the checked statement. This part of the assertion blows up the size of the + * binary. Unless we compile a debug-build with NM_MORE_ASSERTS, drop these + * parts. Note that the failed assertion still prints the file and line where the + * assertion fails. That shall suffice. */ + +static inline void +_nm_g_return_if_fail_warning (const char *log_domain, + const char *file, + int line) +{ + char file_buf[256 + 15]; + + g_snprintf (file_buf, sizeof (file_buf), "((%s:%d))", file, line); + g_return_if_fail_warning (log_domain, file_buf, "<dropped>"); +} + +#define g_return_if_fail_warning(log_domain, pretty_function, expression) \ + _nm_g_return_if_fail_warning (log_domain, __FILE__, __LINE__) + +#define g_assertion_message_expr(domain, file, line, func, expr) \ + g_assertion_message_expr(domain, file, line, "<unknown-fcn>", (expr) ? "<dropped>" : NULL) + +#define NM_ASSERT_G_RETURN_EXPR(expr) "<dropped>" +#define NM_ASSERT_NO_MSG 1 + +#else + +#define NM_ASSERT_G_RETURN_EXPR(expr) ""expr"" +#define NM_ASSERT_NO_MSG 0 + +#endif + +/*****************************************************************************/ #include "nm-glib.h" #include "nm-version.h" diff --git a/shared/nm-test-utils.h b/shared/nm-test-utils.h index 471bf73d81..83e1f47e47 100644 --- a/shared/nm-test-utils.h +++ b/shared/nm-test-utils.h @@ -92,6 +92,11 @@ #include "nm-default.h" +#if NM_ASSERT_NO_MSG +#undef g_return_if_fail_warning +#undef g_assertion_message_expr +#endif + #include <arpa/inet.h> #include <stdio.h> #include <unistd.h> @@ -103,7 +108,7 @@ /*******************************************************************************/ -#define NMTST_G_RETURN_MSG_S(expr) "*: assertion '"expr"' failed" +#define NMTST_G_RETURN_MSG_S(expr) "*: assertion '"NM_ASSERT_G_RETURN_EXPR(expr)"' failed" #define NMTST_G_RETURN_MSG(expr) NMTST_G_RETURN_MSG_S(#expr) /*******************************************************************************/ |