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
|
#define MAX_ERROR_SIZE 1024
|
||||||
|
|
||||||
const char *format_check_error_ex(const char *filename, int linenum,
|
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 error[MAX_ERROR_SIZE];
|
||||||
static char custom[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 *format_check_error(const char *filename, int linenum,
|
||||||
const char *expr) {
|
const char *expr, const char *unused) {
|
||||||
return format_check_error_ex(filename, linenum, expr, NULL);
|
return format_check_error_ex(filename, linenum, expr, unused, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,27 +12,28 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char *format_check_error_ex(const char *filename, int linenum,
|
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 *format_check_error(const char *filename, int linenum,
|
||||||
const char *expr);
|
const char *expr, const char *unused);
|
||||||
|
|
||||||
// 3: VA_ARGS = format_check_error
|
// 3: VA_ARGS = format_check_error
|
||||||
// 4+: VA_ARGS = format_check_error_ex
|
// 4+: VA_ARGS = format_check_error_ex
|
||||||
#define GET_FORMAT_CHECK_ERROR(_1, _2, _3, _4, _5, _6, _7, _8, _9, NAME, ...) \
|
#define SELECT_FORMAT_CHECK_ERROR(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
|
||||||
NAME
|
#define EXPAND_FORMAT_CHECK_ERROR(x) x
|
||||||
#define FORMAT_CHECK_ERROR(...) \
|
|
||||||
GET_FORMAT_CHECK_ERROR(__VA_ARGS__, format_check_error_ex, \
|
#define FORMAT_CHECK_ERROR(filename, linenum, expr, ...) \
|
||||||
format_check_error_ex, format_check_error_ex, \
|
EXPAND_FORMAT_CHECK_ERROR(SELECT_FORMAT_CHECK_ERROR( \
|
||||||
format_check_error_ex, format_check_error_ex, \
|
__VA_ARGS__, /* unused, */ format_check_error_ex, format_check_error_ex, \
|
||||||
format_check_error_ex, format_check_error) \
|
format_check_error_ex, format_check_error_ex, format_check_error_ex, \
|
||||||
(__VA_ARGS__)
|
format_check_error)(filename, linenum, expr, ##__VA_ARGS__))
|
||||||
|
|
||||||
// checks ran for all build configurations
|
// checks ran for all build configurations
|
||||||
#define CHECK_BINARY_OP(v1, v2, op, ...) \
|
#define CHECK_BINARY_OP(v1, v2, op, ...) \
|
||||||
do { \
|
do { \
|
||||||
if (!CHECK_EXPECT_TRUE((v1)op(v2))) { \
|
if (!CHECK_EXPECT_TRUE((v1)op(v2))) { \
|
||||||
const char *msg = FORMAT_CHECK_ERROR( \
|
const char *msg = FORMAT_CHECK_ERROR( \
|
||||||
__FILE__, __LINE__, #v1 " " #op " " #v2, ##__VA_ARGS__); \
|
__FILE__, __LINE__, #v1 " " #op " " #v2, 0, ##__VA_ARGS__); \
|
||||||
LOG_FATAL(msg); \
|
LOG_FATAL(msg); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
@ -46,15 +47,15 @@ const char *format_check_error(const char *filename, int linenum,
|
||||||
do { \
|
do { \
|
||||||
if (!CHECK_EXPECT_TRUE(val)) { \
|
if (!CHECK_EXPECT_TRUE(val)) { \
|
||||||
const char *msg = FORMAT_CHECK_ERROR( \
|
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); \
|
LOG_FATAL(msg); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define CHECK(condition, ...) \
|
#define CHECK(condition, ...) \
|
||||||
do { \
|
do { \
|
||||||
if (!CHECK_EXPECT_TRUE(condition)) { \
|
if (!CHECK_EXPECT_TRUE(condition)) { \
|
||||||
const char *msg = \
|
const char *msg = FORMAT_CHECK_ERROR(__FILE__, __LINE__, #condition, 0, \
|
||||||
FORMAT_CHECK_ERROR(__FILE__, __LINE__, #condition, ##__VA_ARGS__); \
|
##__VA_ARGS__); \
|
||||||
LOG_FATAL(msg); \
|
LOG_FATAL(msg); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
Loading…
Reference in New Issue