chiark / gitweb /
basic: nicer assert messages
[elogind.git] / src / basic / macro.h
index 7715c6e..b9a24f6 100644 (file)
@@ -214,18 +214,20 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
                 (__x / __y + !!(__x % __y));                            \
         })
 
-#define assert_se(expr)                                                 \
+#define assert_message_se(expr, message)                                \
         do {                                                            \
                 if (_unlikely_(!(expr)))                                \
-                        log_assert_failed(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
-        } while (false)                                                 \
+                        log_assert_failed(message, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
+        } while (false)
+
+#define assert_se(expr) assert_message_se(expr, #expr)
 
 /* We override the glibc assert() here. */
 #undef assert
 #ifdef NDEBUG
 #define assert(expr) do {} while(false)
 #else
-#define assert(expr) assert_se(expr)
+#define assert(expr) assert_message_se(expr, #expr)
 #endif
 
 #define assert_not_reached(t)                                           \
@@ -250,19 +252,19 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
         REENABLE_WARNING
 #endif
 
-#define assert_log(expr) ((_likely_(expr))      \
-        ? (true)                                \
-        : (log_assert_failed_return(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__), false))
+#define assert_log(expr, message) ((_likely_(expr))                     \
+        ? (true)                                                        \
+        : (log_assert_failed_return(message, __FILE__, __LINE__, __PRETTY_FUNCTION__), false))
 
 #define assert_return(expr, r)                                          \
         do {                                                            \
-                if (!assert_log(expr))                                  \
+                if (!assert_log(expr, #expr))                           \
                         return (r);                                     \
         } while (false)
 
 #define assert_return_errno(expr, r, err)                               \
         do {                                                            \
-                if (!assert_log(expr)) {                                \
+                if (!assert_log(expr, #expr)) {                         \
                         errno = err;                                    \
                         return (r);                                     \
                 }                                                       \