Correct fix to the compile time assert under OW. Kudos to Vadim to the tip.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30030 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Włodzimierz Skiba
2004-10-20 01:20:58 +00:00
parent 8e5d510855
commit 1c6f24145e
6 changed files with 67 additions and 61 deletions

View File

@@ -198,8 +198,17 @@
It may be used both within a function and in the global scope. It may be used both within a function and in the global scope.
*/ */
#define wxCOMPILE_TIME_ASSERT(expr, msg) \ #ifdef __WATCOMC__
/* avoid "unused symbol" warning */
#define wxCOMPILE_TIME_ASSERT(expr, msg) \
class wxMAKE_UNIQUE_ASSERT_NAME { \
unsigned int msg: expr; \
wxMAKE_UNIQUE_ASSERT_NAME(){wxUnusedVar(msg);} \
}
#else
#define wxCOMPILE_TIME_ASSERT(expr, msg) \
struct wxMAKE_UNIQUE_ASSERT_NAME { unsigned int msg: expr; } struct wxMAKE_UNIQUE_ASSERT_NAME { unsigned int msg: expr; }
#endif
/* for compatibility only, don't use any more, not needed */ /* for compatibility only, don't use any more, not needed */

View File

@@ -32,10 +32,6 @@
#undef Yield #undef Yield
#endif #endif
#ifdef __WXMSW__
#include "wx/msw/wrapwin.h"
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// constants // constants
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -247,7 +243,8 @@ private:
// include windows.h from this public header and we also have to use the // include windows.h from this public header and we also have to use the
// union to force the correct (i.e. maximal) alignment // union to force the correct (i.e. maximal) alignment
// //
// if CRITICAL_SECTION size changes in Windows, you'll get an assert below // if CRITICAL_SECTION size changes in Windows, you'll get an assert from
// thread.cpp and will need to increase the buffer size
// //
// finally, we need this typedef instead of declaring m_buffer directly // finally, we need this typedef instead of declaring m_buffer directly
// because otherwise the assert mentioned above wouldn't compile with some // because otherwise the assert mentioned above wouldn't compile with some
@@ -257,10 +254,6 @@ private:
#else // __WIN32__ #else // __WIN32__
typedef char wxCritSectBuffer[24]; typedef char wxCritSectBuffer[24];
#endif #endif
wxCOMPILE_TIME_ASSERT( sizeof(CRITICAL_SECTION) <= sizeof(wxCritSectBuffer),
wxCriticalSectionBufferTooSmall );
union union
{ {
unsigned long m_dummy1; unsigned long m_dummy1;

View File

@@ -1190,8 +1190,9 @@ wxString wxFileName::GetForbiddenChars(wxPathFormat format)
// Inits to forbidden characters that are common to (almost) all platforms. // Inits to forbidden characters that are common to (almost) all platforms.
wxString strForbiddenChars = wxT("*?"); wxString strForbiddenChars = wxT("*?");
// In case of a new path format // If asserts, wxPathFormat has been changed. In case of a new path format
// addition, the following code might have to be updated. // addition, the following code might have to be updated.
wxCOMPILE_TIME_ASSERT(wxPATH_MAX == 5, wxPathFormatChanged);
switch ( GetFormat(format) ) switch ( GetFormat(format) )
{ {
default : default :

View File

@@ -275,16 +275,19 @@ wxCursor::wxCursor(const wxString& filename,
} }
} }
// all wxWidgets standard cursors // Cursors by stock number
static const struct StdCursor wxCursor::wxCursor(int idCursor)
{ {
// all wxWidgets standard cursors
static const struct StdCursor
{
// is this a standard Windows cursor? // is this a standard Windows cursor?
bool isStd; bool isStd;
// the cursor name or id // the cursor name or id
LPCTSTR name; LPCTSTR name;
} stdCursors[] = } stdCursors[] =
{ {
{ true, NULL }, // wxCURSOR_NONE { true, NULL }, // wxCURSOR_NONE
{ true, IDC_ARROW }, // wxCURSOR_ARROW { true, IDC_ARROW }, // wxCURSOR_ARROW
{ false, _T("WXCURSOR_RIGHT_ARROW") }, // wxCURSOR_RIGHT_ARROW { false, _T("WXCURSOR_RIGHT_ARROW") }, // wxCURSOR_RIGHT_ARROW
@@ -315,14 +318,11 @@ static const struct StdCursor
{ true, IDC_APPSTARTING }, // wxCURSOR_ARROWWAIT { true, IDC_APPSTARTING }, // wxCURSOR_ARROWWAIT
// no entry for wxCURSOR_MAX // no entry for wxCURSOR_MAX
}; };
wxCOMPILE_TIME_ASSERT( WXSIZEOF(stdCursors) == wxCURSOR_MAX, wxCOMPILE_TIME_ASSERT( WXSIZEOF(stdCursors) == wxCURSOR_MAX,
CursorsIdArrayMismatch ); CursorsIdArrayMismatch );
// Cursors by stock number
wxCursor::wxCursor(int idCursor)
{
wxCHECK_RET( idCursor > 0 && (size_t)idCursor < WXSIZEOF(stdCursors), wxCHECK_RET( idCursor > 0 && (size_t)idCursor < WXSIZEOF(stdCursors),
_T("invalid cursor id in wxCursor() ctor") ); _T("invalid cursor id in wxCursor() ctor") );

View File

@@ -113,16 +113,16 @@ public:
m_pItem = &item; m_pItem = &item;
} }
// memcpy() in Init() can't work if the struct sizes are different
wxCOMPILE_TIME_ASSERT( sizeof(LV_ITEM_OTHER) == sizeof(LV_ITEM_NATIVE),
CodeCantWorkIfDiffSizes);
// init with conversion // init with conversion
void Init(LV_ITEM_OTHER& item) void Init(LV_ITEM_OTHER& item)
{ {
// avoid unnecessary dynamic memory allocation, jjust make m_pItem // avoid unnecessary dynamic memory allocation, jjust make m_pItem
// point to our own m_item // point to our own m_item
// memcpy() can't work if the struct sizes are different
wxCOMPILE_TIME_ASSERT( sizeof(LV_ITEM_OTHER) == sizeof(LV_ITEM_NATIVE),
CodeCantWorkIfDiffSizes);
memcpy(&m_item, &item, sizeof(LV_ITEM_NATIVE)); memcpy(&m_item, &item, sizeof(LV_ITEM_NATIVE));
// convert text from ANSI to Unicod if necessary // convert text from ANSI to Unicod if necessary

View File

@@ -144,6 +144,9 @@ static bool gs_waitingForThread = false;
wxCriticalSection::wxCriticalSection() wxCriticalSection::wxCriticalSection()
{ {
wxCOMPILE_TIME_ASSERT( sizeof(CRITICAL_SECTION) <= sizeof(wxCritSectBuffer),
wxCriticalSectionBufferTooSmall );
::InitializeCriticalSection((CRITICAL_SECTION *)m_buffer); ::InitializeCriticalSection((CRITICAL_SECTION *)m_buffer);
} }