chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
macro: log assertion at debug level in assert_return()
[elogind.git]
/
src
/
shared
/
macro.h
diff --git
a/src/shared/macro.h
b/src/shared/macro.h
index 37cdff1cb3065456aad3183359183b7edae58adb..fd3762eed4aae50976bff45148966dbde4cb6764 100644
(file)
--- a/
src/shared/macro.h
+++ b/
src/shared/macro.h
@@
-53,6
+53,11
@@
#define XSTRINGIFY(x) #x
#define STRINGIFY(x) XSTRINGIFY(x)
#define XSTRINGIFY(x) #x
#define STRINGIFY(x) XSTRINGIFY(x)
+#define XCONCATENATE(x, y) x ## y
+#define CONCATENATE(x, y) XCONCATENATE(x, y)
+
+#define UNIQUE(prefix) CONCATENATE(prefix, __LINE__)
+
/* Rounds up */
#define ALIGN4(l) (((l) + 3) & ~3)
/* Rounds up */
#define ALIGN4(l) (((l) + 3) & ~3)
@@
-145,13
+150,15
@@
static inline size_t ALIGN_TO(size_t l, size_t ali) {
#if defined(static_assert)
#define assert_cc(expr) static_assert(expr, #expr)
#else
#if defined(static_assert)
#define assert_cc(expr) static_assert(expr, #expr)
#else
-#define assert_cc(expr) struct
_assert_struct_ ## __LINE__ { char x[(expr) ? 0 : -1]; }
+#define assert_cc(expr) struct
UNIQUE(_assert_struct_) { char x[(expr) ? 0 : -1]; };
#endif
#endif
-#define assert_return(expr, r) \
- do { \
- if (!(expr)) \
- return (r); \
+#define assert_return(expr, r) \
+ do { \
+ if (_unlikely_(!(expr))) { \
+ log_assert_failed_return(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
+ return (r); \
+ } \
} while (false)
#define PTR_TO_INT(p) ((int) ((intptr_t) (p)))
} while (false)
#define PTR_TO_INT(p) ((int) ((intptr_t) (p)))
@@
-262,7
+269,7
@@
do { \
} \
} while(false)
} \
} while(false)
- /* Because statfs.t_type can be int on some architecures, we have to cast
+ /* Because statfs.t_type can be int on some architec
t
ures, we have to cast
* the const magic to the type, otherwise the compiler warns about
* signed/unsigned comparison, because the magic can be 32 bit unsigned.
*/
* the const magic to the type, otherwise the compiler warns about
* signed/unsigned comparison, because the magic can be 32 bit unsigned.
*/
@@
-272,7
+279,7
@@
do { \
* specified type as a decimal string. Adds in extra space for a
* negative '-' prefix. */
#define DECIMAL_STR_MAX(type) \
* specified type as a decimal string. Adds in extra space for a
* negative '-' prefix. */
#define DECIMAL_STR_MAX(type) \
- (
1
+(sizeof(type) <= 1 ? 3 : \
+ (
2
+(sizeof(type) <= 1 ? 3 : \
sizeof(type) <= 2 ? 5 : \
sizeof(type) <= 4 ? 10 : \
sizeof(type) <= 8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)])))
sizeof(type) <= 2 ? 5 : \
sizeof(type) <= 4 ? 10 : \
sizeof(type) <= 8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)])))
@@
-280,4
+287,18
@@
do { \
#define SET_FLAG(v, flag, b) \
(v) = (b) ? ((v) | (flag)) : ((v) & ~(flag))
#define SET_FLAG(v, flag, b) \
(v) = (b) ? ((v) | (flag)) : ((v) & ~(flag))
+#define IN_SET(x, ...) \
+ ({ \
+ const typeof(x) _x = (x); \
+ unsigned _i; \
+ bool _found = false; \
+ for (_i = 0; _i < sizeof((const typeof(_x)[]) { __VA_ARGS__ })/sizeof(const typeof(_x)); _i++) \
+ if (((const typeof(_x)[]) { __VA_ARGS__ })[_i] == _x) { \
+ _found = true; \
+ break; \
+ } \
+ _found; \
+ })
+
+
#include "log.h"
#include "log.h"