better implementation of WARN

This commit is contained in:
Kent Overstreet 2019-03-08 14:41:43 -05:00
parent fd67296247
commit 166e32606e

View File

@ -9,22 +9,46 @@
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) #define BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2*!!(cond)]))
#define BUG() do { assert(0); unreachable(); } while (0) #define BUG() do { assert(0); unreachable(); } while (0)
#define BUG_ON(cond) assert(!(cond)) #define BUG_ON(cond) assert(!(cond))
#define WARN_ON_ONCE(cond) ({ bool _r = (cond); if (_r) assert(0); _r; }) #define WARN(cond, fmt, ...) \
#define WARN_ONCE(cond, ...) ({ bool _r = (cond); if (_r) assert(0); _r; }) ({ \
int __ret_warn_on = unlikely(!!(cond)); \
#define __WARN() assert(0)
#define __WARN_printf(arg...) assert(0)
#define WARN(cond, ...) assert(!(cond))
#define WARN_ON(condition) ({ \
int __ret_warn_on = unlikely(!!(condition)); \
if (__ret_warn_on) \ if (__ret_warn_on) \
__WARN(); \ fprintf(stderr, "WARNING at " __FILE__ ":%d: " fmt "\n",\
__LINE__, ##__VA_ARGS__); \
__ret_warn_on; \
})
#define WARN_ON(cond) ({ \
int __ret_warn_on = unlikely(!!(cond)); \
if (__ret_warn_on) \
fprintf(stderr, "WARNING at " __FILE__ ":%d\n", __LINE__);\
__ret_warn_on; \
})
#define WARN_ONCE(cond, fmt, ...) \
({ \
static bool __warned; \
int __ret_warn_on = unlikely(!!(cond)); \
if (__ret_warn_on && !__warned) { \
__warned = true; \
fprintf(stderr, "WARNING at " __FILE__ ":%d: " fmt "\n",\
__LINE__, ##__VA_ARGS__); \
} \
__ret_warn_on; \
})
#define WARN_ON_ONCE(cond) ({ \
static bool __warned; \
int __ret_warn_on = unlikely(!!(cond)); \
if (__ret_warn_on && !__warned) { \
__warned = true; \
fprintf(stderr, "WARNING at " __FILE__ ":%d\n", __LINE__);\
} \
__ret_warn_on; \ __ret_warn_on; \
}) })