Force usage of assert() condition when NDEBUG is defined
[lttng-tools.git] / src / common / macros.h
index e52d7f7712764751d81aea4c69ce39856c7d9994..2b16e5b68a42fe073b22904f8f645b465efd046a 100644 (file)
@@ -77,6 +77,16 @@ void *zmalloc(size_t len)
 #define LTTNG_PACKED __attribute__((__packed__))
 #endif
 
+#ifndef LTTNG_NO_SANITIZE_ADDRESS
+#if defined(__clang__) || defined (__GNUC__)
+#define LTTNG_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
+#else
+#define LTTNG_NO_SANITIZE_ADDRESS
+#endif
+#endif
+
+#define is_signed(type) (((type) -1) < (type) 1)
+
 /*
  * Align value to the next multiple of align. Returns val if it already is a
  * multiple of align. Align must be a power of two.
@@ -96,7 +106,7 @@ void *zmalloc(size_t len)
 
 #define member_sizeof(type, field)     sizeof(((type *) 0)->field)
 
-#define ASSERT_LOCKED(lock) assert(pthread_mutex_trylock(&lock))
+#define ASSERT_LOCKED(lock) LTTNG_ASSERT(pthread_mutex_trylock(&lock))
 
 /*
  * Get an aligned pointer to a value. This is meant
@@ -123,4 +133,15 @@ int lttng_strncpy(char *dst, const char *src, size_t dst_len)
        return 0;
 }
 
+#ifdef NDEBUG
+/*
+* Force usage of the assertion condition to prevent unused variable warnings
+* when `assert()` are disabled by the `NDEBUG` definition.
+*/
+# define LTTNG_ASSERT(_cond) ((void) sizeof((void) (_cond), 0))
+#else
+# include <assert.h>
+# define LTTNG_ASSERT(_cond) assert(_cond)
+#endif
+
 #endif /* _MACROS_H */
This page took 0.02417 seconds and 4 git commands to generate.