-#if wxUSE_UNICODE
- /* char versions are used by debugging macros; we have to provide
- wxChar* szMsg version because it's common to use _T() in the macros
- and finally, we can't use const wx(char)* szMsg = NULL, because that
- would be ambiguous: */
- extern void WXDLLIMPEXP_BASE wxOnAssert(const char *szFile,
- int nLine,
- const char *szFunc,
- const char *szCond);
-
- extern void WXDLLIMPEXP_BASE wxOnAssert(const char *szFile,
- int nLine,
- const char *szFunc,
- const char *szCond,
- const char *szMsg);
-
- extern void WXDLLIMPEXP_BASE wxOnAssert(const char *szFile,
- int nLine,
- const char *szFunc,
- const char *szCond,
- const wxChar *szMsg);
-#endif // wxUSE_UNICODE
-
- class WXDLLIMPEXP_BASE wxString;
- /* these two work when szMsg passed to debug macro is a string: */
- extern void WXDLLIMPEXP_BASE wxOnAssert(const wxString& szFile,
- int nLine,
- const wxString& szFunc,
- const wxString& szCond,
- const wxString& szMsg);
-
- extern void WXDLLIMPEXP_BASE wxOnAssert(const wxString& szFile,
- int nLine,
- const wxString& szFunc,
- const wxString& szCond);
-
- extern void WXDLLIMPEXP_BASE wxOnAssert(const char *szFile,
- int nLine,
- const char *szFunc,
- const char *szCond,
- const wxString& szMsg);
-
- /* call this function to break into the debugger unconditionally (assuming */
- /* the program is running under debugger, of course) */
- extern void WXDLLIMPEXP_BASE wxTrap();
-
- /* generic assert macro */
- #define wxASSERT(cond) wxASSERT_MSG(cond, (const char*)NULL)
-
-
- /* assert with additional message explaining its cause */
-
- /* compilers can give a warning (such as "possible unwanted ;") when using */
- /* the default definition of wxASSERT_MSG so we provide an alternative */
- #if defined(__MWERKS__)
- #define wxASSERT_MSG(cond, msg) \
- if ( cond ) \
- {} \
- else \
- wxOnAssert(__FILE__, __LINE__, __WXFUNCTION__, #cond, msg)
- #else
- #define wxASSERT_MSG(cond, msg) \
- if ( cond ) \
- ; \
- else \
- wxOnAssert(__FILE__, __LINE__, __WXFUNCTION__, #cond, msg)
- #endif
-
- /* special form of assert: always triggers it (in debug mode) */
- #define wxFAIL wxFAIL_MSG((const char*)NULL)
-
- /* FAIL with some message */
- #define wxFAIL_MSG(msg) wxFAIL_COND_MSG("wxAssertFailure", msg)
-
- /* FAIL with some message and a condition */
- #define wxFAIL_COND_MSG(cond, msg) \
- wxOnAssert(__FILE__, __LINE__, __WXFUNCTION__, cond, msg)
-
- /* 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) ) */
- /* */
- /* NB: this is made obsolete by wxCOMPILE_TIME_ASSERT() and should no */
- /* longer be used. */
- extern bool WXDLLIMPEXP_BASE wxAssertIsEqual(int x, int y);
+// ----------------------------------------------------------------------------
+// Handling assertion failures
+// ----------------------------------------------------------------------------
+
+/*
+ Type for the function called in case of assert failure, see
+ wxSetAssertHandler().
+ */
+typedef void (*wxAssertHandler_t)(const wxString& file,
+ int line,
+ const wxString& func,
+ const wxString& cond,
+ const wxString& msg);
+
+#if wxDEBUG_LEVEL
+
+// the global assert handler function, if it is NULL asserts don't check their
+// conditions
+extern WXDLLIMPEXP_DATA_BASE(wxAssertHandler_t) wxTheAssertHandler;
+
+/*
+ Sets the function to be called in case of assertion failure.
+
+ The default assert handler forwards to wxApp::OnAssertFailure() whose
+ default behaviour is, in turn, to show the standard assertion failure
+ dialog if a wxApp object exists or shows the same dialog itself directly
+ otherwise.
+
+ While usually it is enough -- and more convenient -- to just override
+ OnAssertFailure(), to handle all assertion failures, including those
+ occurring even before wxApp object creation or after its destruction you
+ need to provide your assertion handler function.
+
+ This function also provides a simple way to disable all asserts: simply
+ pass NULL pointer to it. Doing this will result in not even evaluating
+ assert conditions at all, avoiding almost all run-time cost of asserts.
+
+ Notice that this function is not MT-safe, so you should call it before
+ starting any other threads.
+
+ The return value of this function is the previous assertion handler. It can
+ be called after any pre-processing by your handler and can also be restored
+ later if you uninstall your handler.
+ */
+inline wxAssertHandler_t wxSetAssertHandler(wxAssertHandler_t handler)
+{
+ const wxAssertHandler_t old = wxTheAssertHandler;
+ wxTheAssertHandler = handler;
+ return old;
+}
+
+/*
+ Reset the default assert handler.
+
+ This may be used to enable asserts, which are disabled by default in this
+ case, for programs built in release build (NDEBUG defined).
+ */
+extern void WXDLLIMPEXP_BASE wxSetDefaultAssertHandler();
+
+#else // !wxDEBUG_LEVEL
+
+// provide empty stubs in case assertions are completely disabled
+//
+// NB: can't use WXUNUSED() here as we're included from wx/defs.h before it is
+// defined
+inline wxAssertHandler_t wxSetAssertHandler(wxAssertHandler_t /* handler */)
+{
+ return NULL;
+}
+
+inline void wxSetDefaultAssertHandler() { }
+
+#endif // wxDEBUG_LEVEL/!wxDEBUG_LEVEL
+
+// simply a synonym for wxSetAssertHandler(NULL)
+inline void wxDisableAsserts() { wxSetAssertHandler(NULL); }
+
+/*
+ A macro which disables asserts for applications compiled in release build.
+
+ By default, IMPLEMENT_APP (or rather IMPLEMENT_WXWIN_MAIN) disable the
+ asserts in the applications compiled in the release build by calling this.
+ It does nothing if NDEBUG is not defined.
+ */
+#ifdef NDEBUG
+ #define wxDISABLE_ASSERTS_IN_RELEASE_BUILD() wxDisableAsserts()