new wxASSERT implementation using wxAssert() helper function
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15827 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
b7b35e5063
commit
aad65f130d
@ -34,6 +34,10 @@ wxBase:
|
||||
a function returning a pointer would stop compiling now (but this change
|
||||
is not supposed to have any effects on valid code)
|
||||
|
||||
- another minor change: wxApp::OnAssert() has a new "cond" argument, you
|
||||
must modify YourApp::OnAssert() signature if you were using it to override
|
||||
the default assert handling.
|
||||
|
||||
All (GUI):
|
||||
|
||||
! the event type constants are not constants any more but are dynamically
|
||||
|
@ -238,7 +238,7 @@ Returns 0 under X, and the wParam of the WM\_QUIT message under Windows.
|
||||
|
||||
\membersection{wxApp::OnAssert}\label{wxapponassert}
|
||||
|
||||
\func{void}{OnAssert}{\param{const wxChar }{*file}, \param{int }{line}, \param{const wxChar }{*msg}}
|
||||
\func{void}{OnAssert}{\param{const wxChar }{*file}, \param{int }{line}, \param{const wxChar }{*cond}, \param{const wxChar }{*msg}}
|
||||
|
||||
This function is called when an assert failure occurs, i.e. the condition
|
||||
specified in \helpref{wxASSERT}{wxassert} macro evaluated to {\tt FALSE}.
|
||||
@ -254,6 +254,8 @@ the user to stop the program, continue or ignore all subsequent asserts.
|
||||
|
||||
\docparam{line}{the line number in this file where the assert occured}
|
||||
|
||||
\docparam{cond}{the condition of the failed assert in string form}
|
||||
|
||||
\docparam{msg}{the message specified as argument to
|
||||
\helpref{wxASSERT\_MSG}{wxassertmsg} or \helpref{wxFAIL\_MSG}{wxfailmsg}, will
|
||||
be {\tt NULL} if just \helpref{wxASSERT}{wxassert} or \helpref{wxFAIL}{wxfail}
|
||||
|
@ -3435,7 +3435,7 @@ compilation error messages if the condition they check fail.
|
||||
|
||||
\membersection{::wxOnAssert}\label{wxonassert}
|
||||
|
||||
\func{void}{wxOnAssert}{\param{const char *}{fileName}, \param{int}{ lineNumber}, \param{const char *}{msg = NULL}}
|
||||
\func{void}{wxOnAssert}{\param{const char *}{fileName}, \param{int}{ lineNumber}, \param{const char *}{cond}, \param{const char *}{msg = NULL}}
|
||||
|
||||
This function is called whenever one of debugging macros fails (i.e. condition
|
||||
is false in an assertion). It is only defined in the debug mode, in release
|
||||
|
@ -330,8 +330,14 @@ public:
|
||||
// this function is called when an assert failure occurs, the base class
|
||||
// version does the normal processing (i.e. shows the usual assert failure
|
||||
// dialog box)
|
||||
//
|
||||
// the arguments are the place where the assert occured, the text of the
|
||||
// assert itself and the user-specified message
|
||||
#ifdef __WXDEBUG__
|
||||
virtual void OnAssert(const wxChar *file, int line, const wxChar *msg);
|
||||
virtual void OnAssert(const wxChar *file,
|
||||
int line,
|
||||
const wxChar *cond,
|
||||
const wxChar *msg);
|
||||
#endif // __WXDEBUG__
|
||||
|
||||
// check that the wxBuildOptions object (constructed in the application
|
||||
|
@ -78,36 +78,42 @@
|
||||
*/
|
||||
extern void WXDLLEXPORT wxOnAssert(const wxChar *szFile,
|
||||
int nLine,
|
||||
const wxChar *szCond,
|
||||
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
|
||||
the following code
|
||||
|
||||
if ( ... )
|
||||
wxASSERT(...);
|
||||
else
|
||||
...
|
||||
|
||||
works like expected: if there were no "else", the one in the code above
|
||||
would be matched with a wrong "if"
|
||||
*/
|
||||
// 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
|
||||
inline void WXDLLEXPORT wxAssert(int cond,
|
||||
const wxChar *szFile,
|
||||
int nLine,
|
||||
const wxChar *szCond,
|
||||
const wxChar *szMsg = NULL)
|
||||
{
|
||||
if ( !cond )
|
||||
wxOnAssert(szFile, nLine, szCond, szMsg);
|
||||
}
|
||||
|
||||
// generic assert macro
|
||||
#define wxASSERT(cond) if ( !(cond) ) wxOnAssert(__TFILE__, __LINE__); else
|
||||
#define wxASSERT(cond) wxAssert(!!(cond), __TFILE__, __LINE__, _T(#cond))
|
||||
|
||||
// assert with additional message explaining it's cause
|
||||
#define wxASSERT_MSG(cond, msg) \
|
||||
if ( !(cond) ) wxOnAssert(__TFILE__, __LINE__, msg); else
|
||||
wxAssert(!!(cond), __TFILE__, __LINE__, _T(#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 shouldn't be
|
||||
// used any longer
|
||||
extern bool WXDLLEXPORT wxAssertIsEqual(int x, int y);
|
||||
#else
|
||||
#define wxTrap()
|
||||
|
@ -424,23 +424,22 @@ void wxTrap()
|
||||
|
||||
// show the assert modal dialog
|
||||
static
|
||||
void ShowAssertDialog(const wxChar *szFile, int nLine, const wxChar *szMsg)
|
||||
void ShowAssertDialog(const wxChar *szFile,
|
||||
int nLine,
|
||||
const wxChar *szCond,
|
||||
const wxChar *szMsg)
|
||||
{
|
||||
// this variable can be set to true to suppress "assert failure" messages
|
||||
static bool s_bNoAsserts = FALSE;
|
||||
|
||||
wxChar szBuf[4096];
|
||||
|
||||
// make life easier for people using VC++ IDE: clicking on the message
|
||||
// will take us immediately to the place of the failed assert
|
||||
// make life easier for people using VC++ IDE by using this format: like
|
||||
// this, clicking on the message will take us immediately to the place of
|
||||
// the failed assert
|
||||
wxSnprintf(szBuf, WXSIZEOF(szBuf),
|
||||
#ifdef __VISUALC__
|
||||
wxT("%s(%d): assert failed"),
|
||||
#else // !VC++
|
||||
// make the error message more clear for all the others
|
||||
wxT("Assert failed in file %s at line %d"),
|
||||
#endif // VC/!VC
|
||||
szFile, nLine);
|
||||
wxT("%s(%d): assert \"%s\" failed"),
|
||||
szFile, nLine, szCond);
|
||||
|
||||
if ( szMsg != NULL )
|
||||
{
|
||||
@ -501,7 +500,10 @@ void ShowAssertDialog(const wxChar *szFile, int nLine, const wxChar *szMsg)
|
||||
}
|
||||
|
||||
// this function is called when an assert fails
|
||||
void wxOnAssert(const wxChar *szFile, int nLine, const wxChar *szMsg)
|
||||
void wxOnAssert(const wxChar *szFile,
|
||||
int nLine,
|
||||
const wxChar *szCond,
|
||||
const wxChar *szMsg)
|
||||
{
|
||||
// FIXME MT-unsafe
|
||||
static bool s_bInAssert = FALSE;
|
||||
@ -522,20 +524,23 @@ void wxOnAssert(const wxChar *szFile, int nLine, const wxChar *szMsg)
|
||||
{
|
||||
// by default, show the assert dialog box - we can't customize this
|
||||
// behaviour
|
||||
ShowAssertDialog(szFile, nLine, szMsg);
|
||||
ShowAssertDialog(szFile, nLine, szCond, szMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
// let the app process it as it wants
|
||||
wxTheApp->OnAssert(szFile, nLine, szMsg);
|
||||
wxTheApp->OnAssert(szFile, nLine, szCond, szMsg);
|
||||
}
|
||||
|
||||
s_bInAssert = FALSE;
|
||||
}
|
||||
|
||||
void wxAppBase::OnAssert(const wxChar *file, int line, const wxChar *msg)
|
||||
void wxAppBase::OnAssert(const wxChar *file,
|
||||
int line,
|
||||
const wxChar *cond,
|
||||
const wxChar *msg)
|
||||
{
|
||||
ShowAssertDialog(file, line, msg);
|
||||
ShowAssertDialog(file, line, cond, msg);
|
||||
}
|
||||
|
||||
#endif //WXDEBUG
|
||||
|
Loading…
Reference in New Issue
Block a user