From dac348b9e28c90e3ec6aa1bbd7f5085c90e9cdfd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 20 Jun 2002 22:33:22 +0000 Subject: [PATCH] fixed compilation with CW8 (SF patch 567845) and also added alignment fillers for wxCriticalSection::m_buffer git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15898 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/thread.h | 16 ++++++++++++++-- src/msw/thread.cpp | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/wx/thread.h b/include/wx/thread.h index b8585439be..6c126b9fbd 100644 --- a/include/wx/thread.h +++ b/include/wx/thread.h @@ -241,11 +241,23 @@ private: #elif defined(__WXMSW__) // we can't allocate any memory in the ctor, so use placement new - // unfortunately, we have to hardcode the sizeof() here because we can't - // include windows.h from this public header + // include windows.h from this public header and we also have to use the + // union to force the correct (i.e. maximal) alignment // // if CRITICAL_SECTION size changes in Windows, you'll get an assert from // thread.cpp and will need to increase the buffer size - char m_buffer[24]; + // + // finally, we need this typedef instead of declaring m_buffer directly + // because otherwise the assert mentioned above wouldn't compile with some + // compilers (notably CodeWarrior 8) + typedef char wxCritSectBuffer[24]; + union + { + unsigned long m_dummy1; + void *m_dummy2; + + wxCritSectBuffer m_buffer; + }; #else // nothing for OS/2 #endif // Unix/Win32/OS2 diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index 0f5886b86f..e839cba462 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -132,7 +132,7 @@ static bool gs_waitingForThread = FALSE; wxCriticalSection::wxCriticalSection() { - wxCOMPILE_TIME_ASSERT( sizeof(CRITICAL_SECTION) <= sizeof(m_buffer), + wxCOMPILE_TIME_ASSERT( sizeof(CRITICAL_SECTION) <= sizeof(wxCritSectBuffer), wxCriticalSectionBufferTooSmall ); ::InitializeCriticalSection((CRITICAL_SECTION *)m_buffer); -- 2.47.2