X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=macro.h;h=622c08eeda89ef840f06ac24638ae01873d13469;hp=2eaa3d6fbbdadbf5075a99d825423a815ff08e6a;hb=05a602f468a4f00d36ee7da73f13c0b014786fea;hpb=2fa086a8e02b1b2d62a9a424b41944f3a2251e60 diff --git a/macro.h b/macro.h index 2eaa3d6fb..622c08eed 100644 --- a/macro.h +++ b/macro.h @@ -35,6 +35,9 @@ #define _deprecated __attribute__ ((deprecated)) #define _packed __attribute__ ((packed)) #define _malloc __attribute__ ((malloc)) +#define _weak __attribute__ ((weak)) +#define _likely(x) (__builtin_expect(!!(x),1)) +#define _unlikely(x) (__builtin_expect(!!(x),0)) /* Rounds up */ static inline size_t ALIGN(size_t l) { @@ -65,11 +68,28 @@ static inline size_t ALIGN(size_t l) { ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \ }) +#define assert_se(expr) \ + do { \ + if (_unlikely(!(expr))) \ + log_assert(__FILE__, __LINE__, __PRETTY_FUNCTION__, \ + "Assertion '%s' failed at %s:%u, function %s(). Aborting.", \ + #expr , __FILE__, __LINE__, __PRETTY_FUNCTION__); \ + } 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_assert(__FILE__, __LINE__, __PRETTY_FUNCTION__, \ + "Code should not be reached '%s' at %s:%u, function %s(). Aborting.", \ + t, __FILE__, __LINE__, __PRETTY_FUNCTION__); \ + } while (false) #define assert_cc(expr) \ do { \ @@ -97,10 +117,14 @@ static inline size_t ALIGN(size_t l) { #define char_array_0(x) x[sizeof(x)-1] = 0; -#define IOVEC_SET_STRING(iovec, s) \ +#define IOVEC_SET_STRING(i, s) \ do { \ - (iovec).iov_base = s; \ - (iovec).iov_len = strlen(s); \ + struct iovec *_i = &(i); \ + char *_s = (char *)(s); \ + _i->iov_base = _s; \ + _i->iov_len = strlen(_s); \ } while(false); +#include "log.h" + #endif