mirror of https://github.com/inolen/redream.git
updated assert macros to compile under msvc / gcc / clang
This commit is contained in:
parent
a60442724f
commit
6fdfd17903
|
@ -5,7 +5,8 @@
|
|||
#define MAX_ERROR_SIZE 1024
|
||||
|
||||
const char *format_check_error_ex(const char *filename, int linenum,
|
||||
const char *expr, const char *format, ...) {
|
||||
const char *expr, const char *unused,
|
||||
const char *format, ...) {
|
||||
static char error[MAX_ERROR_SIZE];
|
||||
static char custom[MAX_ERROR_SIZE];
|
||||
|
||||
|
@ -26,6 +27,6 @@ const char *format_check_error_ex(const char *filename, int linenum,
|
|||
}
|
||||
|
||||
const char *format_check_error(const char *filename, int linenum,
|
||||
const char *expr) {
|
||||
return format_check_error_ex(filename, linenum, expr, NULL);
|
||||
const char *expr, const char *unused) {
|
||||
return format_check_error_ex(filename, linenum, expr, unused, NULL);
|
||||
}
|
||||
|
|
|
@ -12,27 +12,28 @@
|
|||
#endif
|
||||
|
||||
const char *format_check_error_ex(const char *filename, int linenum,
|
||||
const char *expr, const char *format, ...);
|
||||
const char *expr, const char *unused,
|
||||
const char *format, ...);
|
||||
const char *format_check_error(const char *filename, int linenum,
|
||||
const char *expr);
|
||||
const char *expr, const char *unused);
|
||||
|
||||
// 3: VA_ARGS = format_check_error
|
||||
// 4+: VA_ARGS = format_check_error_ex
|
||||
#define GET_FORMAT_CHECK_ERROR(_1, _2, _3, _4, _5, _6, _7, _8, _9, NAME, ...) \
|
||||
NAME
|
||||
#define FORMAT_CHECK_ERROR(...) \
|
||||
GET_FORMAT_CHECK_ERROR(__VA_ARGS__, format_check_error_ex, \
|
||||
format_check_error_ex, format_check_error_ex, \
|
||||
format_check_error_ex, format_check_error_ex, \
|
||||
format_check_error_ex, format_check_error) \
|
||||
(__VA_ARGS__)
|
||||
#define SELECT_FORMAT_CHECK_ERROR(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
|
||||
#define EXPAND_FORMAT_CHECK_ERROR(x) x
|
||||
|
||||
#define FORMAT_CHECK_ERROR(filename, linenum, expr, ...) \
|
||||
EXPAND_FORMAT_CHECK_ERROR(SELECT_FORMAT_CHECK_ERROR( \
|
||||
__VA_ARGS__, /* unused, */ format_check_error_ex, format_check_error_ex, \
|
||||
format_check_error_ex, format_check_error_ex, format_check_error_ex, \
|
||||
format_check_error)(filename, linenum, expr, ##__VA_ARGS__))
|
||||
|
||||
// checks ran for all build configurations
|
||||
#define CHECK_BINARY_OP(v1, v2, op, ...) \
|
||||
do { \
|
||||
if (!CHECK_EXPECT_TRUE((v1)op(v2))) { \
|
||||
const char *msg = FORMAT_CHECK_ERROR( \
|
||||
__FILE__, __LINE__, #v1 " " #op " " #v2, ##__VA_ARGS__); \
|
||||
__FILE__, __LINE__, #v1 " " #op " " #v2, 0, ##__VA_ARGS__); \
|
||||
LOG_FATAL(msg); \
|
||||
} \
|
||||
} while (0)
|
||||
|
@ -46,15 +47,15 @@ const char *format_check_error(const char *filename, int linenum,
|
|||
do { \
|
||||
if (!CHECK_EXPECT_TRUE(val)) { \
|
||||
const char *msg = FORMAT_CHECK_ERROR( \
|
||||
__FILE__, __LINE__, #val " must be non-NULL", ##__VA_ARGS__); \
|
||||
__FILE__, __LINE__, #val " must be non-NULL", 0, ##__VA_ARGS__); \
|
||||
LOG_FATAL(msg); \
|
||||
} \
|
||||
} while (0)
|
||||
#define CHECK(condition, ...) \
|
||||
do { \
|
||||
if (!CHECK_EXPECT_TRUE(condition)) { \
|
||||
const char *msg = \
|
||||
FORMAT_CHECK_ERROR(__FILE__, __LINE__, #condition, ##__VA_ARGS__); \
|
||||
const char *msg = FORMAT_CHECK_ERROR(__FILE__, __LINE__, #condition, 0, \
|
||||
##__VA_ARGS__); \
|
||||
LOG_FATAL(msg); \
|
||||
} \
|
||||
} while (0)
|
||||
|
|
Loading…
Reference in New Issue