bug.h revamp, easier to use
This commit is contained in:
@@ -11,20 +11,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* we allow multiple inclusions, so that BUG_ON/WARN_ON can change during
|
#ifndef BUG_H
|
||||||
* compilation.
|
|
||||||
*/
|
|
||||||
#ifdef BUG_H
|
|
||||||
|
|
||||||
#undef BUG_H
|
|
||||||
|
|
||||||
/* reset all macros */
|
|
||||||
#undef bug_on
|
|
||||||
#undef warn_on
|
|
||||||
#undef warn
|
|
||||||
|
|
||||||
#endif /* BUG_H */
|
|
||||||
|
|
||||||
#define BUG_H
|
#define BUG_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -32,44 +19,43 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#ifndef BUG_ON
|
#define bug_on_always(expr) do { \
|
||||||
#define BUG_ON 0
|
if (expr) { \
|
||||||
#endif
|
|
||||||
#ifndef WARN_ON
|
|
||||||
#define WARN_ON 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "likely.h"
|
|
||||||
|
|
||||||
#if (BUG_ON + 0 == 1)
|
|
||||||
#define bug_on(expr) do { \
|
|
||||||
if (unlikely(expr)) { \
|
|
||||||
fprintf(stderr, \
|
fprintf(stderr, \
|
||||||
"** BUG IN %s[%s:%d]: assertion \"" #expr "\" failed.\n", \
|
"** BUG ON %s[%s:%d]: assertion '%s' failed.\n", \
|
||||||
__func__, __FILE__,__LINE__); \
|
__func__, __FILE__,__LINE__, #expr); \
|
||||||
abort(); \
|
abort(); \
|
||||||
|
/* not reached */ \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
|
||||||
#define bug_on(expr)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (WARN_ON + 0 == 1)
|
|
||||||
#define warn_on(expr) ({ \
|
|
||||||
int _ret = !!(expr); \
|
|
||||||
if (unlikely(_ret)) \
|
|
||||||
fprintf(stderr, \
|
|
||||||
"** WARN ON %s[%s:%d]: assertion \"" #expr "\" failed.\n", \
|
|
||||||
__func__, __FILE__,__LINE__); \
|
|
||||||
_ret; \
|
|
||||||
})
|
|
||||||
#else
|
|
||||||
#define warn_on(expr) ({ 0; })
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define warn(expr, args...) ({ \
|
#define warn(expr, args...) ({ \
|
||||||
int _ret = !!(expr); \
|
int _ret = !!(expr); \
|
||||||
if (unlikely(_ret)) \
|
if (_ret) \
|
||||||
fprintf(stderr, ##args); \
|
fprintf(stderr, ##args); \
|
||||||
_ret; \
|
_ret; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#define warn_on_always(expr) ({ \
|
||||||
|
warn(expr, \
|
||||||
|
"** WARN ON %s[%s:%d]: assertion '%s' failed.\n", \
|
||||||
|
__func__, __FILE__,__LINE__, #expr); \
|
||||||
|
})
|
||||||
|
|
||||||
|
#ifdef BUG_ON
|
||||||
|
|
||||||
|
#define bug_on(expr) bug_on_always(expr)
|
||||||
|
|
||||||
|
#define warn_on(expr) warn_on_always(expr)
|
||||||
|
#define warn_on_or_eval(expr) warn_on(expr)
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define bug_on(expr)
|
||||||
|
|
||||||
|
#define warn_on(expr)
|
||||||
|
#define warn_on_or_eval(expr) (expr)
|
||||||
|
|
||||||
|
#endif /* BUG_ON */
|
||||||
|
|
||||||
|
#endif /* BUG_H */
|
||||||
|
Reference in New Issue
Block a user