]> git.saurik.com Git - wxWidgets.git/commitdiff
don't evaluate assert expression unless the condition is false (patch 1450705)
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 21 Mar 2006 14:17:49 +0000 (14:17 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 21 Mar 2006 14:17:49 +0000 (14:17 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38249 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/debug.h
src/common/appbase.cpp

index c2fc985ec281550dc06cee5954ffb6e280acfb6b..e1d1f8a8212e6e748a363e06dd92c4cf91075ea1 100644 (file)
 /*  NB: these functions are implemented in src/common/appcmn.cpp */
 #if defined(__cplusplus) && defined(__WXDEBUG__)
   /*
-    this function may be redefined to do something non trivial and is called
-    whenever one of debugging macros fails (i.e. condition is false in an
-    assertion)
+    This function is called whenever one of debugging macros fails (i.e.
+    condition is false in an assertion). To customize its behaviour, override
+    wxApp::OnAssert().
 
-    parameters:
+    Parameters:
        szFile and nLine - file name and line number of the ASSERT
+       szCond           - text form of the condition which failed
        szMsg            - optional message explaining the reason
   */
   extern void WXDLLIMPEXP_BASE wxOnAssert(const wxChar *szFile,
   /*  the program is running under debugger, of course) */
   extern void WXDLLIMPEXP_BASE wxTrap();
 
-  /*  helper function used to implement wxASSERT and wxASSERT_MSG */
-  /*  */
-  /*  note using "int" and not "bool" for cond to avoid VC++ warnings about */
-  /*  implicit conversions when doing "wxAssert( pointer )" and also use of */
-  /*  "!!cond" below to ensure that everything is converted to int */
-  extern void WXDLLIMPEXP_BASE wxAssert(int cond,
-                                        const wxChar *szFile,
-                                        int nLine,
-                                        const wxChar *szCond,
-                                        const wxChar *szMsg = NULL) ;
-
   /*  generic assert macro */
-  #define wxASSERT(cond) wxAssert(!!(cond), __TFILE__, __LINE__, _T(#cond))
+  #define wxASSERT(cond) wxASSERT_MSG(cond, NULL)
 
   /*  assert with additional message explaining it's cause */
   #define wxASSERT_MSG(cond, msg) \
-    wxAssert(!!(cond), __TFILE__, __LINE__, _T(#cond), msg)
+    if (cond) ; else wxOnAssert(__TFILE__, __LINE__, _T(#cond), msg)
+
+  /*  special form of assert: always triggers it (in debug mode) */
+  #define wxFAIL wxFAIL_MSG(NULL)
+
+  /*  FAIL with some message */
+  #define wxFAIL_MSG(msg) wxOnAssert(__TFILE__, __LINE__, wxT("wxAssertFailure"), msg)
 
   /*  an assert helper used to avoid warning when testing constant expressions, */
   /*  i.e. wxASSERT( sizeof(int) == 4 ) can generate a compiler warning about */
   /*  no more bugs ;-) */
   #define wxASSERT(cond)
   #define wxASSERT_MSG(x, m)
+  #define wxFAIL
+  #define wxFAIL_MSG(msg)
 #endif  /* __WXDEBUG__ */
 
 #ifdef __cplusplus
 
 #define wxAssertFailure wxFalse
 
-/*  special form of assert: always triggers it (in debug mode) */
-#define wxFAIL                 wxASSERT(wxAssertFailure)
-
-/*  FAIL with some message */
-#define wxFAIL_MSG(msg)        wxASSERT_MSG(wxAssertFailure, msg)
-
 /*  NB: the following macros work also in release mode! */
 
 /*
 */
 
 /*  check that expression is true, "return" if not (also FAILs in debug mode) */
-#define wxCHECK(x, rc)            if (!(x)) {wxFAIL; return rc; }
+#define wxCHECK(x, rc)            wxCHECK_MSG(x, rc, NULL)
 
 /*  as wxCHECK but with a message explaining why we fail */
-#define wxCHECK_MSG(x, rc, msg)   if (!(x)) {wxFAIL_MSG(msg); return rc; }
+#define wxCHECK_MSG(x, rc, msg)   wxCHECK2_MSG(x, return rc, msg)
 
 /*  check that expression is true, perform op if not */
-#define wxCHECK2(x, op)           if (!(x)) {wxFAIL; op; }
+#define wxCHECK2(x, op)           wxCHECK2_MSG(x, op, NULL)
 
 /*  as wxCHECK2 but with a message explaining why we fail */
-#define wxCHECK2_MSG(x, op, msg)  if (!(x)) {wxFAIL_MSG(msg); op; }
+#define wxCHECK2_MSG(x, op, msg)  if (x) ; else do { wxFAIL_MSG(msg); op; } while (0)
 
 /*  special form of wxCHECK2: as wxCHECK, but for use in void functions */
 /*  */
 /*      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; }
+#define wxCHECK_RET(x, msg)       wxCHECK2_MSG(x, return, msg)
 
 /*  ---------------------------------------------------------------------------- */
 /*  Compile time asserts */
index fd408ab0d95aee5ac8c709687e25a03a0d68aa69..1c4d53b480681e9ad0d08a7f228f8ebcf223c436 100644 (file)
@@ -587,16 +587,6 @@ void wxTrap()
 #endif // Win/Unix
 }
 
-void wxAssert(int cond,
-              const wxChar *szFile,
-              int nLine,
-              const wxChar *szCond,
-              const wxChar *szMsg)
-{
-    if ( !cond )
-        wxOnAssert(szFile, nLine, szCond, szMsg);
-}
-
 // this function is called when an assert fails
 void wxOnAssert(const wxChar *szFile,
                 int nLine,