chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
40531a5
)
macro: hookup assert logic with log logic
author
Lennart Poettering
<lennart@poettering.net>
Tue, 13 Apr 2010 01:59:39 +0000
(
03:59
+0200)
committer
Lennart Poettering
<lennart@poettering.net>
Tue, 13 Apr 2010 01:59:39 +0000
(
03:59
+0200)
macro.h
patch
|
blob
|
history
diff --git
a/macro.h
b/macro.h
index 2eaa3d6fbbdadbf5075a99d825423a815ff08e6a..d56585dc341bdfc93480c8a92ec8f4a55138bade 100644
(file)
--- a/
macro.h
+++ b/
macro.h
@@
-35,6
+35,8
@@
#define _deprecated __attribute__ ((deprecated))
#define _packed __attribute__ ((packed))
#define _malloc __attribute__ ((malloc))
#define _deprecated __attribute__ ((deprecated))
#define _packed __attribute__ ((packed))
#define _malloc __attribute__ ((malloc))
+#define _likely(x) (__builtin_expect(!!(x),1))
+#define _unlikely(x) (__builtin_expect(!!(x),0))
/* Rounds up */
static inline size_t ALIGN(size_t l) {
/* Rounds up */
static inline size_t ALIGN(size_t l) {
@@
-65,11
+67,29
@@
static inline size_t ALIGN(size_t l) {
((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \
})
((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \
})
+#define assert_se(expr) \
+ do { \
+ if (_unlikely(!(expr))) { \
+ log_error("Assertion '%s' failed at %s:%u, function %s(). Aborting.", \
+ #expr , __FILE__, __LINE__, __PRETTY_FUNCTION__); \
+ abort(); \
+ } \
+ } while (false) \
+
+/* We override the glibc assert() here. */
+#undef assert
+#ifdef NDEBUG
+#define assert(expr) do {} while(false)
+#else
+#define assert(expr) assert_se(expr)
+#endif
-
-#define assert_not_reached(t) assert(!(t))
-
-#define assert_se(x) assert(x)
+#define assert_not_reached(t) \
+ do { \
+ log_error("Code should not be reached '%s' at %s:%u, function %s(). Aborting.", \
+ t, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
+ abort(); \
+ } while (false)
#define assert_cc(expr) \
do { \
#define assert_cc(expr) \
do { \
@@
-103,4
+123,6
@@
static inline size_t ALIGN(size_t l) {
(iovec).iov_len = strlen(s); \
} while(false);
(iovec).iov_len = strlen(s); \
} while(false);
+#include "log.h"
+
#endif
#endif