summaryrefslogtreecommitdiff
path: root/src/debug.h
diff options
context:
space:
mode:
authorCraig Robbins <kde.psych@gmail.com>2015-03-06 20:21:51 +1000
committerCraig Robbins <kde.psych@gmail.com>2015-03-07 22:41:47 +1000
commitced6d20295a8263757d57c02a07ffcb66688a163 (patch)
treea44527357c1ffccb88bf479686735aef168d15c1 /src/debug.h
parenta603a767877b94b4d3bc4d3de8d762fbc56a583d (diff)
downloadminetest-ced6d20295a8263757d57c02a07ffcb66688a163.tar.gz
minetest-ced6d20295a8263757d57c02a07ffcb66688a163.tar.bz2
minetest-ced6d20295a8263757d57c02a07ffcb66688a163.zip
For usages of assert() that are meant to persist in Release builds (when NDEBUG is defined), replace those usages with persistent alternatives
Diffstat (limited to 'src/debug.h')
-rw-r--r--src/debug.h37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/debug.h b/src/debug.h
index 1027fde69..9684aa2df 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <iostream>
#include <exception>
+#include <assert.h>
#include "gettime.h"
#if (defined(WIN32) || defined(_WIN32_WCE))
@@ -72,28 +73,38 @@ extern std::ostream dstream;
extern std::ostream dstream_no_stderr;
extern Nullstream dummyout;
-/*
- Include assert.h and immediately undef assert so that it can't override
- our assert later on. leveldb/slice.h is a notable offender.
-*/
-#include <assert.h>
-#undef assert
+/* Abort program execution immediately
+ */
+__NORETURN extern void fatal_error_fn(
+ const char *msg, const char *file,
+ unsigned int line, const char *function);
+
+#define FATAL_ERROR(msg) \
+ fatal_error_fn((msg), __FILE__, __LINE__, __FUNCTION_NAME)
+
+#define FATAL_ERROR_IF(expr, msg) \
+ ((expr) \
+ ? fatal_error_fn((msg), __FILE__, __LINE__, __FUNCTION_NAME) \
+ : (void)(0))
/*
- Assert
+ sanity_check()
+ Equivalent to assert() but persists in Release builds (i.e. when NDEBUG is
+ defined)
*/
-__NORETURN extern void assert_fail(
+__NORETURN extern void sanity_check_fn(
const char *assertion, const char *file,
unsigned int line, const char *function);
-#define ASSERT(expr)\
- ((expr)\
- ? (void)(0)\
- : assert_fail(#expr, __FILE__, __LINE__, __FUNCTION_NAME))
+#define SANITY_CHECK(expr) \
+ ((expr) \
+ ? (void)(0) \
+ : sanity_check_fn(#expr, __FILE__, __LINE__, __FUNCTION_NAME))
+
+#define sanity_check(expr) SANITY_CHECK(expr)
-#define assert(expr) ASSERT(expr)
void debug_set_exception_handler();