build: add --enable-more-asserts configure option and nm_assert() macro
authorThomas Haller <thaller@redhat.com>
Fri, 10 Apr 2015 05:25:03 +0000 (07:25 +0200)
committerThomas Haller <thaller@redhat.com>
Fri, 10 Apr 2015 16:06:59 +0000 (18:06 +0200)
NM already has two kinds of assertions:
 - g_assert*(), conditionally compiled via #ifndef G_DISABLE_ASSERT
 - g_return*(), conditionally compiled via #ifndef G_DISABLE_CHECKS

In theory, one should be able to disable both asserts and NM should
still work correctly (and possibly more efficient). In practice,
hardly anybody is testing such a configuration and it might be broken.
Especially, we don't disable asserts for production builds, both because
of less test coverage and because it might reduce our ability to debug.

Add a new configure option --enable-more-asserts, which defines
NM_MORE_ASSERTS and nm_assert(). This is for expensive asserts,
that -- contrary to the asserts above -- are disabled by default.
This is useful for extended debugging.

configure.ac
include/nm-utils-internal.h

index ee58d44..ce3ea7b 100644 (file)
@@ -850,6 +850,12 @@ AM_CONDITIONAL(BUILD_NMTUI, test "$build_nmtui" = yes)
 
 NM_COMPILER_WARNINGS
 
+AC_ARG_ENABLE(more-asserts,
+              AS_HELP_STRING([--enable-more-asserts], [Enable more assertions for debugging (default: no)]))
+if test "${enable_more_asserts}" = "yes"; then
+    AC_DEFINE(NM_MORE_ASSERTS, [1], [Define if more asserts are enabled])
+fi
+
 AC_ARG_ENABLE(lto, AS_HELP_STRING([--enable-lto], [Enable Link Time Optimization for smaller size (default: no)]))
 if (test "${enable_lto}" = "yes"); then
     CFLAGS="-flto $CFLAGS"
index 7ca44f3..49991cf 100644 (file)
 
 /*****************************************************************************/
 
+#ifdef NM_MORE_ASSERTS
+#define nm_assert(cond) G_STMT_START { g_assert (cond); } G_STMT_END
+#else
+#define nm_assert(cond) G_STMT_START { (void) 0; } G_STMT_END
+#endif
+
+/*****************************************************************************/
+
 #define NM_DEFINE_SINGLETON_INSTANCE(TYPE) \
 static TYPE *singleton_instance