#include "wx/msw/private.h" // includes windows.h
#endif
+#if wxUSE_THREADS
+
+// define static functions providing access to the critical sections we use
+// instead of just using static critical section variables as log functions may
+// be used during static initialization and while this is certainly not
+// advisable it's still better to not crash (as we'd do if we used a yet
+// uninitialized critical section) if it happens
+
+static inline wxCriticalSection& GetTraceMaskCS()
+{
+ static wxCriticalSection s_csTrace;
+
+ return s_csTrace;
+}
+
+static inline wxCriticalSection& GetPreviousLogCS()
+{
+ static wxCriticalSection s_csPrev;
+
+ return s_csPrev;
+}
+
+#endif // wxUSE_THREADS
+
// ----------------------------------------------------------------------------
// non member functions
// ----------------------------------------------------------------------------
void wxSafeShowMessage(const wxString& title, const wxString& text)
{
#ifdef __WINDOWS__
- ::MessageBox(NULL, text.wx_str(), title.wx_str(), MB_OK | MB_ICONSTOP);
+ ::MessageBox(NULL, text.t_str(), title.t_str(), MB_OK | MB_ICONSTOP);
#else
wxFprintf(stderr, wxS("%s: %s\n"), title.c_str(), text.c_str());
fflush(stderr);
unsigned wxLog::LogLastRepeatIfNeeded()
{
- wxCRIT_SECT_LOCKER(lock, ms_prevCS);
+ wxCRIT_SECT_LOCKER(lock, GetPreviousLogCS());
return LogLastRepeatIfNeededUnlocked();
}
{
if ( GetRepetitionCounting() )
{
- wxCRIT_SECT_LOCKER(lock, ms_prevCS);
+ wxCRIT_SECT_LOCKER(lock, GetPreviousLogCS());
if ( szString == ms_prevString )
{
void wxLog::AddTraceMask(const wxString& str)
{
- wxCRIT_SECT_LOCKER(lock, ms_traceCS);
+ wxCRIT_SECT_LOCKER(lock, GetTraceMaskCS());
ms_aTraceMasks.push_back(str);
}
void wxLog::RemoveTraceMask(const wxString& str)
{
- wxCRIT_SECT_LOCKER(lock, ms_traceCS);
+ wxCRIT_SECT_LOCKER(lock, GetTraceMaskCS());
int index = ms_aTraceMasks.Index(str);
if ( index != wxNOT_FOUND )
void wxLog::ClearTraceMasks()
{
- wxCRIT_SECT_LOCKER(lock, ms_traceCS);
+ wxCRIT_SECT_LOCKER(lock, GetTraceMaskCS());
ms_aTraceMasks.Clear();
}
/*static*/ bool wxLog::IsAllowedTraceMask(const wxString& mask)
{
- wxCRIT_SECT_LOCKER(lock, ms_traceCS);
+ wxCRIT_SECT_LOCKER(lock, GetTraceMaskCS());
for ( wxArrayString::iterator it = ms_aTraceMasks.begin(),
en = ms_aTraceMasks.end();
wxLogInterposerTemp::wxLogInterposerTemp()
: wxLogChain(this)
{
- DetachOldLog();
+ DetachOldLog();
}
#ifdef __VISUALC__
// static variables
// ----------------------------------------------------------------------------
-#if wxUSE_THREADS
-wxCriticalSection wxLog::ms_prevCS,
- wxLog::ms_traceCS;
-#endif // wxUSE_THREADS
bool wxLog::ms_bRepetCounting = false;
wxString wxLog::ms_prevString;
unsigned int wxLog::ms_prevCounter = 0;
time_t wxLog::ms_prevTimeStamp= 0;
wxLogLevel wxLog::ms_prevLevel;
-wxLog *wxLog::ms_pLogger = (wxLog *)NULL;
+wxLog *wxLog::ms_pLogger = NULL;
bool wxLog::ms_doLog = true;
bool wxLog::ms_bAutoCreate = true;
bool wxLog::ms_bVerbose = false;
#if !defined(__SMARTPHONE__) /* of WinCE */
if( lpMsgBuf != 0 )
{
- wxStrncpy(s_szBuf, (const wxChar *)lpMsgBuf, WXSIZEOF(s_szBuf) - 1);
- s_szBuf[WXSIZEOF(s_szBuf) - 1] = wxS('\0');
+ wxStrlcpy(s_szBuf, (const wxChar *)lpMsgBuf, WXSIZEOF(s_szBuf));
LocalFree(lpMsgBuf);