X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6f28211af2258ce0c052e5b5c1d862e7bbc8de27..b9efe021b554fa3967d1442cf758435c5cd5ae8f:/src/common/memory.cpp diff --git a/src/common/memory.cpp b/src/common/memory.cpp index e32260e3aa..90812da1f1 100644 --- a/src/common/memory.cpp +++ b/src/common/memory.cpp @@ -68,7 +68,7 @@ #include "wx/memory.h" -#if wxUSE_THREADS && defined(__WXDEBUG__) && !defined(__WXMAC__) +#if wxUSE_THREADS && defined(__WXDEBUG__) #define USE_THREADSAFE_MEMORY_ALLOCATION 1 #else #define USE_THREADSAFE_MEMORY_ALLOCATION 0 @@ -117,7 +117,7 @@ */ void wxMemStruct::ErrorMsg (const char * mesg) { - wxLogMessage(wxT("wxWindows memory checking error: %s"), mesg); + wxLogMessage(wxT("wxWidgets memory checking error: %s"), mesg); PrintNode (); } @@ -126,7 +126,7 @@ void wxMemStruct::ErrorMsg (const char * mesg) */ void wxMemStruct::ErrorMsg () { - wxLogMessage(wxT("wxWindows over/underwrite memory error:")); + wxLogMessage(wxT("wxWidgets over/underwrite memory error:")); PrintNode (); } @@ -867,13 +867,13 @@ void wxDebugContext::OutputDumpLine(const wxChar *szFormat, ...) int count; va_list argptr; va_start(argptr, szFormat); - buf[sizeof(buf)-1] = _T('\0'); + buf[sizeof(buf)/sizeof(wxChar)-1] = _T('\0'); // keep 3 bytes for a \r\n\0 - count = wxVsnprintf(buf, sizeof(buf)-3, szFormat, argptr); + count = wxVsnprintf(buf, sizeof(buf)/sizeof(wxChar)-3, szFormat, argptr); if ( count < 0 ) - count = sizeof(buf)-3; + count = sizeof(buf)/sizeof(wxChar)-3; buf[count]=_T('\r'); buf[count+1]=_T('\n'); buf[count+2]=_T('\0'); @@ -889,16 +889,19 @@ static bool memSectionOk = false; class MemoryCriticalSection : public wxCriticalSection { public: - MemoryCriticalSection() { - memSectionOk = true; - } + MemoryCriticalSection() { + memSectionOk = true; + } + ~MemoryCriticalSection() { + memSectionOk = false; + } }; class MemoryCriticalSectionLocker { public: inline MemoryCriticalSectionLocker(wxCriticalSection& critsect) - : m_critsect(critsect), m_locked(memSectionOk) { if(m_locked) m_critsect.Enter(); } + : m_critsect(critsect), m_locked(memSectionOk) { if(m_locked) m_critsect.Enter(); } inline ~MemoryCriticalSectionLocker() { if(m_locked) m_critsect.Leave(); } private: @@ -907,12 +910,50 @@ private: MemoryCriticalSectionLocker& operator=(const MemoryCriticalSectionLocker&); wxCriticalSection& m_critsect; - bool m_locked; + bool m_locked; }; static MemoryCriticalSection memLocker; + #endif +#if !(defined(__WXMSW__) && (defined(WXUSINGDLL) || defined(WXMAKINGDLL_BASE))) +#ifdef __WXDEBUG__ +#if wxUSE_GLOBAL_MEMORY_OPERATORS +void * operator new (size_t size, wxChar * fileName, int lineNum) +{ + return wxDebugAlloc(size, fileName, lineNum, false, false); +} + +void * operator new (size_t size) +{ + return wxDebugAlloc(size, NULL, 0, false); +} + +void operator delete (void * buf) +{ + wxDebugFree(buf, false); +} + +#if wxUSE_ARRAY_MEMORY_OPERATORS +void * operator new[] (size_t size) +{ + return wxDebugAlloc(size, NULL, 0, false, true); +} + +void * operator new[] (size_t size, wxChar * fileName, int lineNum) +{ + return wxDebugAlloc(size, fileName, lineNum, false, true); +} + +void operator delete[] (void * buf) +{ + wxDebugFree(buf, true); +} +#endif // wxUSE_ARRAY_MEMORY_OPERATORS +#endif // !(defined(__WXMSW__) && (defined(WXUSINGDLL) || defined(WXMAKINGDLL_BASE))) +#endif // wxUSE_GLOBAL_MEMORY_OPERATORS + // TODO: store whether this is a vector or not. void * wxDebugAlloc(size_t size, wxChar * fileName, int lineNum, bool isObject, bool WXUNUSED(isVect) ) { @@ -1023,6 +1064,8 @@ void wxDebugFree(void * buf, bool WXUNUSED(isVect) ) free((char *)st); } +#endif // __WXDEBUG__ + // Trace: send output to the current debugging stream void wxTrace(const wxChar * ...) { @@ -1101,11 +1144,11 @@ void wxTraceLevel(int, const wxChar * ...) } //---------------------------------------------------------------------------- -// Final cleanup after all global objects in all files have been destructed +// Final cleanup after all global objects in all files have been destroyed //---------------------------------------------------------------------------- // Don't set it to 0 by dynamic initialization -// Some compilers will realy do the asignment later +// Some compilers will really do the assignment later // All global variables are initialized to 0 at the very beginning, and this is just fine. int wxDebugContextDumpDelayCounter::sm_count; @@ -1120,7 +1163,7 @@ void wxDebugContextDumpDelayCounter::DoDump() } // Even if there is nothing else, make sure that there is at -// least one clenup counter object +// least one cleanup counter object static wxDebugContextDumpDelayCounter wxDebugContextDumpDelayCounter_One; #endif // (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT