Common: Use the log system to print assert messages
This commit is contained in:
parent
b88c91dd3d
commit
c8eae338a8
|
@ -8,6 +8,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
|
#include "common/logging/log.h"
|
||||||
|
|
||||||
// For asserts we'd like to keep all the junk executed when an assert happens away from the
|
// For asserts we'd like to keep all the junk executed when an assert happens away from the
|
||||||
// important code in the function. One way of doing this is to put all the relevant code inside a
|
// important code in the function. One way of doing this is to put all the relevant code inside a
|
||||||
|
@ -28,19 +29,14 @@ static void assert_noinline_call(const Fn& fn) {
|
||||||
exit(1); // Keeps GCC's mouth shut about this actually returning
|
exit(1); // Keeps GCC's mouth shut about this actually returning
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO (yuriks) allow synchronous logging so we don't need printf
|
|
||||||
#define ASSERT(_a_) \
|
#define ASSERT(_a_) \
|
||||||
do if (!(_a_)) { assert_noinline_call([] { \
|
do if (!(_a_)) { assert_noinline_call([] { \
|
||||||
fprintf(stderr, "Assertion Failed!\n\n Line: %d\n File: %s\n Time: %s\n", \
|
LOG_CRITICAL(Debug, "Assertion Failed!"); \
|
||||||
__LINE__, __FILE__, __TIME__); \
|
|
||||||
}); } while (0)
|
}); } while (0)
|
||||||
|
|
||||||
#define ASSERT_MSG(_a_, ...) \
|
#define ASSERT_MSG(_a_, ...) \
|
||||||
do if (!(_a_)) { assert_noinline_call([&] { \
|
do if (!(_a_)) { assert_noinline_call([&] { \
|
||||||
fprintf(stderr, "Assertion Failed!\n\n Line: %d\n File: %s\n Time: %s\n", \
|
LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); \
|
||||||
__LINE__, __FILE__, __TIME__); \
|
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
|
||||||
fprintf(stderr, "\n"); \
|
|
||||||
}); } while (0)
|
}); } while (0)
|
||||||
|
|
||||||
#define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!")
|
#define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!")
|
||||||
|
|
Reference in New Issue