From 50a94f972d26ee15fc22cce657d13023d1022905 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 26 Jan 2021 09:41:55 +0000 Subject: Fix debug macro situation (#5114) Use the standard NDEBUG. --- src/Globals.h | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/Globals.h') 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 #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 - #include - #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 + #include + #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; 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; #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 -- cgit v1.2.3