]> git.lizzy.rs Git - minetest.git/blobdiff - src/debug.h
Disable mesh cache by default
[minetest.git] / src / debug.h
index 1532be824a2918a048e5dc592078fb2dead14c5d..9684aa2dff50e2d44f31ca9126e140b5eb7500d0 100644 (file)
@@ -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,20 +73,40 @@ extern std::ostream dstream;
 extern std::ostream dstream_no_stderr;
 extern Nullstream dummyout;
 
+
+/* 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();
 
 /*
        DebugStack
@@ -110,13 +131,12 @@ class DebugStacker
        bool m_overflowed;
 };
 
-#define DSTACK(msg)\
+#define DSTACK(msg) \
        DebugStacker __debug_stacker(msg);
 
-#define DSTACKF(...)\
-       char __buf[DEBUG_STACK_TEXT_SIZE];\
-       snprintf(__buf,\
-                       DEBUG_STACK_TEXT_SIZE, __VA_ARGS__);\
+#define DSTACKF(...) \
+       char __buf[DEBUG_STACK_TEXT_SIZE];                   \
+       snprintf(__buf, DEBUG_STACK_TEXT_SIZE, __VA_ARGS__); \
        DebugStacker __debug_stacker(__buf);
 
 /*
@@ -124,34 +144,13 @@ class DebugStacker
 */
 
 #if CATCH_UNHANDLED_EXCEPTIONS == 1
-       #define BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER try{
-       #define END_PORTABLE_DEBUG_EXCEPTION_HANDLER(logstream)\
-               }catch(std::exception &e){\
-                       logstream<<"ERROR: An unhandled exception occurred: "\
-                                       <<e.what()<<std::endl;\
-                       assert(0);\
+       #define BEGIN_DEBUG_EXCEPTION_HANDLER try {
+       #define END_DEBUG_EXCEPTION_HANDLER(logstream) \
+               } catch (std::exception &e) {                               \
+                       logstream << "ERROR: An unhandled exception occurred: " \
+                               << e.what() << std::endl;                           \
+                       assert(0);                                              \
                }
-       #ifdef _WIN32 // Windows
-               #ifdef _MSC_VER // MSVC
-void se_trans_func(unsigned int, EXCEPTION_POINTERS*);
-                       #define BEGIN_DEBUG_EXCEPTION_HANDLER \
-                               BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER\
-                               _set_se_translator(se_trans_func);
-
-                       #define END_DEBUG_EXCEPTION_HANDLER(logstream) \
-                               END_PORTABLE_DEBUG_EXCEPTION_HANDLER(logstream)
-               #else // Probably mingw
-                       #define BEGIN_DEBUG_EXCEPTION_HANDLER\
-                               BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER
-                       #define END_DEBUG_EXCEPTION_HANDLER(logstream)\
-                               END_PORTABLE_DEBUG_EXCEPTION_HANDLER(logstream)
-               #endif
-       #else // Posix
-               #define BEGIN_DEBUG_EXCEPTION_HANDLER\
-                       BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER
-               #define END_DEBUG_EXCEPTION_HANDLER(logstream)\
-                       END_PORTABLE_DEBUG_EXCEPTION_HANDLER(logstream)
-       #endif
 #else
        // Dummy ones
        #define BEGIN_DEBUG_EXCEPTION_HANDLER