diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2021-01-26 10:41:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-26 10:41:55 +0100 |
commit | 50a94f972d26ee15fc22cce657d13023d1022905 (patch) | |
tree | 24417c741cf85061b73098a32e61ecd3749be05e /src/Globals.h | |
parent | Redstone: inline -> static (diff) | |
download | cuberite-50a94f972d26ee15fc22cce657d13023d1022905.tar cuberite-50a94f972d26ee15fc22cce657d13023d1022905.tar.gz cuberite-50a94f972d26ee15fc22cce657d13023d1022905.tar.bz2 cuberite-50a94f972d26ee15fc22cce657d13023d1022905.tar.lz cuberite-50a94f972d26ee15fc22cce657d13023d1022905.tar.xz cuberite-50a94f972d26ee15fc22cce657d13023d1022905.tar.zst cuberite-50a94f972d26ee15fc22cce657d13023d1022905.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Globals.h | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/Globals.h b/src/Globals.h index cdfea9e5a..7b488326f 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -45,22 +45,20 @@ // Use non-standard defines in <cmath> #define _USE_MATH_DEFINES - #ifdef _DEBUG + #ifndef NDEBUG // Override the "new" operator to include file and line specification for debugging memory leaks // Ref.: https://social.msdn.microsoft.com/Forums/en-US/ebc7dd7a-f3c6-49f1-8a60-e381052f21b6/debugging-memory-leaks?forum=vcgeneral#53f0cc89-62fe-45e8-bbf0-56b89f2a1901 // This causes MSVC Debug runs to produce a report upon program exit, that contains memory-leaks // together with the file:line information about where the memory was allocated. // Note that this doesn't work with placement-new, which needs to temporarily #undef the macro // (See AllocationPool.h for an example). - #ifdef _DEBUG - #define _CRTDBG_MAP_ALLOC - #include <stdlib.h> - #include <crtdbg.h> - #define DEBUG_CLIENTBLOCK new(_CLIENT_BLOCK, __FILE__, __LINE__) - #define new DEBUG_CLIENTBLOCK - // For some reason this works magically - each "new X" gets replaced as "new(_CLIENT_BLOCK, "file", line) X" - // The CRT has a definition for this operator new that stores the debugging info for leak-finding later. - #endif + #define _CRTDBG_MAP_ALLOC + #include <stdlib.h> + #include <crtdbg.h> + #define DEBUG_CLIENTBLOCK new(_CLIENT_BLOCK, __FILE__, __LINE__) + #define new DEBUG_CLIENTBLOCK + // For some reason this works magically - each "new X" gets replaced as "new(_CLIENT_BLOCK, "file", line) X" + // The CRT has a definition for this operator new that stores the debugging info for leak-finding later. #endif #elif defined(__GNUC__) @@ -277,10 +275,10 @@ template class SizeChecker<UInt8, 1>; int lineNumber() const { return mLineNumber; } }; - #ifdef _DEBUG - #define ASSERT(x) do { if (!(x)) { throw cAssertFailure(#x, __FILE__, __LINE__);} } while (0) + #ifdef NDEBUG + #define ASSERT(x) #else - #define ASSERT(...) + #define ASSERT(x) do { if (!(x)) { throw cAssertFailure(#x, __FILE__, __LINE__);} } while (0) #endif // Pretty much the same as ASSERT() but stays in Release builds @@ -288,10 +286,10 @@ template class SizeChecker<UInt8, 1>; #else // TEST_GLOBALS - #ifdef _DEBUG - #define ASSERT(x) ( !!(x) || ( LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__), std::abort(), 0)) - #else + #ifdef NDEBUG #define ASSERT(x) + #else + #define ASSERT(x) ( !!(x) || ( LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__), std::abort(), 0)) #endif // Pretty much the same as ASSERT() but stays in Release builds |