X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7ba4fbebbc40bdf9c140f4c9ba9977fbf810527d..1d21855083920c136002fbd9a283def320cd1c53:/include/wx/debug.h diff --git a/include/wx/debug.h b/include/wx/debug.h index 4fd54e2d91..85dee4be29 100644 --- a/include/wx/debug.h +++ b/include/wx/debug.h @@ -16,6 +16,32 @@ #include "wx/wxchar.h" +// ---------------------------------------------------------------------------- +// Defines controlling the debugging macros +// ---------------------------------------------------------------------------- + +// if _DEBUG is defined (MS VC++ and others use it in debug builds), define +// __WXDEBUG__ too +#ifdef _DEBUG + #ifndef __WXDEBUG__ + #define __WXDEBUG__ + #endif // !__WXDEBUG__ +#endif // _DEBUG + +// if NDEBUG is defined ( uses it), undef __WXDEBUG__ and WXDEBUG +#ifdef NDEBUG + #undef __WXDEBUG__ + #undef WXDEBUG +#endif // NDEBUG + +// if __WXDEBUG__ is defined, make sure that WXDEBUG is defined and >= 1 +#ifdef __WXDEBUG__ + #if !defined(WXDEBUG) || !WXDEBUG + #undef WXDEBUG + #define WXDEBUG 1 + #endif // !WXDEBUG +#endif // __WXDEBUG__ + // ---------------------------------------------------------------------------- // Debugging macros // @@ -36,11 +62,9 @@ // a judicious use of them might increase your program's stability. // ---------------------------------------------------------------------------- -// Use of these suppresses compiler warnings about testing constant expression -WXDLLEXPORT_DATA(extern const bool) wxTrue; -WXDLLEXPORT_DATA(extern const bool) wxFalse; - // Macros which are completely disabled in 'release' mode +// +// NB: these functions are implemented in src/common/appcmn.cpp #ifdef __WXDEBUG__ /* this function may be redefined to do something non trivial and is called @@ -51,7 +75,13 @@ WXDLLEXPORT_DATA(extern const bool) wxFalse; szFile and nLine - file name and line number of the ASSERT szMsg - optional message explaining the reason */ - void WXDLLEXPORT wxOnAssert(const wxChar *szFile, int nLine, const wxChar *szMsg = (const wxChar *) NULL); + extern void WXDLLEXPORT wxOnAssert(const wxChar *szFile, + int nLine, + const wxChar *szMsg = NULL); + + // call this function to break into the debugger uncodnitionally (assuming + // the program is running under debugger, of course) + extern void WXDLLEXPORT wxTrap(); /* notice the usage of else at the end of wxASSERT macro: this ensures that @@ -72,13 +102,25 @@ WXDLLEXPORT_DATA(extern const bool) wxFalse; // assert with additional message explaining it's cause #define wxASSERT_MSG(cond, msg) \ if ( !(cond) ) wxOnAssert(__TFILE__, __LINE__, msg); else + + // an assert helper used to avoid warning when testing constant expressions, + // i.e. wxASSERT( sizeof(int) == 4 ) can generate a compiler warning about + // expression being always true, but not using + // wxASSERT( wxAssertIsEqual(sizeof(int), 4) ) + extern bool WXDLLEXPORT wxAssertIsEqual(int x, int y); #else + #define wxTrap() + // nothing to do in release modes (hopefully at this moment there are // no more bugs ;-) #define wxASSERT(cond) #define wxASSERT_MSG(x, m) #endif //__WXDEBUG__ +// Use of wxFalse instead of FALSE suppresses compiler warnings about testing +// constant expression +WXDLLEXPORT_DATA(extern const bool) wxFalse; + // special form of assert: always triggers it (in debug mode) #define wxFAIL wxASSERT(wxFalse) @@ -107,10 +149,11 @@ WXDLLEXPORT_DATA(extern const bool) wxFalse; #define wxCHECK2_MSG(x, op, msg) if (!(x)) {wxFAIL_MSG(msg); op; } // special form of wxCHECK2: as wxCHECK, but for use in void functions -// NB: there is only one form (with msg parameter) and it's intentional: -// there is no other way to tell the caller what exactly went wrong -// from the void function (of course, the function shouldn't be void -// to begin with...) +// +// NB: there is only one form (with msg parameter) and it's intentional: +// there is no other way to tell the caller what exactly went wrong +// from the void function (of course, the function shouldn't be void +// to begin with...) #define wxCHECK_RET(x, msg) if (!(x)) {wxFAIL_MSG(msg); return; } #endif // _WX_DEBUG_H_