summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/assert.h10
1 files changed, 3 insertions, 7 deletions
diff --git a/src/common/assert.h b/src/common/assert.h
index 4f26c63e9..7b7d8bf28 100644
--- a/src/common/assert.h
+++ b/src/common/assert.h
@@ -8,6 +8,7 @@
8#include <cstdlib> 8#include <cstdlib>
9 9
10#include "common/common_funcs.h" 10#include "common/common_funcs.h"
11#include "common/logging/log.h"
11 12
12// For asserts we'd like to keep all the junk executed when an assert happens away from the 13// For asserts we'd like to keep all the junk executed when an assert happens away from the
13// important code in the function. One way of doing this is to put all the relevant code inside a 14// 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) {
28 exit(1); // Keeps GCC's mouth shut about this actually returning 29 exit(1); // Keeps GCC's mouth shut about this actually returning
29} 30}
30 31
31// TODO (yuriks) allow synchronous logging so we don't need printf
32#define ASSERT(_a_) \ 32#define ASSERT(_a_) \
33 do if (!(_a_)) { assert_noinline_call([] { \ 33 do if (!(_a_)) { assert_noinline_call([] { \
34 fprintf(stderr, "Assertion Failed!\n\n Line: %d\n File: %s\n Time: %s\n", \ 34 LOG_CRITICAL(Debug, "Assertion Failed!"); \
35 __LINE__, __FILE__, __TIME__); \
36 }); } while (0) 35 }); } while (0)
37 36
38#define ASSERT_MSG(_a_, ...) \ 37#define ASSERT_MSG(_a_, ...) \
39 do if (!(_a_)) { assert_noinline_call([&] { \ 38 do if (!(_a_)) { assert_noinline_call([&] { \
40 fprintf(stderr, "Assertion Failed!\n\n Line: %d\n File: %s\n Time: %s\n", \ 39 LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); \
41 __LINE__, __FILE__, __TIME__); \
42 fprintf(stderr, __VA_ARGS__); \
43 fprintf(stderr, "\n"); \
44 }); } while (0) 40 }); } while (0)
45 41
46#define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!") 42#define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!")