X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77ffb5937e89927b621128789401db8921fe580f..a9a0ceca5b549414a6119e98bc6d868c071a8b1b:/src/common/memory.cpp diff --git a/src/common/memory.cpp b/src/common/memory.cpp index 0f6c284aae..9bf20f536b 100644 --- a/src/common/memory.cpp +++ b/src/common/memory.cpp @@ -1,46 +1,39 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: memory.cpp +// Name: src/common/memory.cpp // Purpose: Memory checking implementation // Author: Arthur Seaton, Julian Smart // Modified by: // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWidgets licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation "memory.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#ifndef WX_PRECOMP -#include "wx/defs.h" + #pragma hdrstop #endif #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -// #pragma implementation -#endif +#include "wx/memory.h" #ifndef WX_PRECOMP -#include "wx/utils.h" -#include "wx/app.h" -#include "wx/hash.h" + #ifdef __WXMSW__ + #include "wx/msw/wrapwin.h" + #endif + #include "wx/utils.h" + #include "wx/app.h" + #include "wx/hash.h" + #include "wx/log.h" #endif #if wxUSE_THREADS -#include "wx/thread.h" + #include "wx/thread.h" #endif -#include "wx/log.h" #include #include "wx/ioswrap.h" @@ -53,22 +46,7 @@ #include #include -#ifdef __WXMSW__ -#include "wx/msw/wrapwin.h" - -#ifdef GetClassInfo -#undef GetClassInfo -#endif - -#ifdef GetClassName -#undef GetClassName -#endif - -#endif - -#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 @@ -768,14 +746,13 @@ bool wxDebugContext::PrintClasses(void) } int n = 0; - wxHashTable::compatibility_iterator node; - wxClassInfo *info; + const wxClassInfo *info; - wxClassInfo::sm_classTable->BeginFind(); - node = wxClassInfo::sm_classTable->Next(); - while (node) + for (wxClassInfo::const_iterator node = wxClassInfo::begin_classinfo(), + end = wxClassInfo::end_classinfo(); + node != end; ++node) { - info = (wxClassInfo *)node->GetData(); + info = *node; if (info->GetClassName()) { wxString msg(info->GetClassName()); @@ -798,7 +775,6 @@ bool wxDebugContext::PrintClasses(void) wxLogMessage(msg); } - node = wxClassInfo::sm_classTable->Next(); n ++; } wxLogMessage(wxEmptyString); @@ -867,13 +843,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'); @@ -892,6 +868,9 @@ public: MemoryCriticalSection() { memSectionOk = true; } + ~MemoryCriticalSection() { + memSectionOk = false; + } }; class MemoryCriticalSectionLocker @@ -910,19 +889,53 @@ private: bool m_locked; }; -MemoryCriticalSection &GetMemLocker() +static MemoryCriticalSection memLocker; + +#endif // USE_THREADSAFE_MEMORY_ALLOCATION + + +#ifdef __WXDEBUG__ +#if !(defined(__WXMSW__) && (defined(WXUSINGDLL) || defined(WXMAKINGDLL_BASE))) +#if wxUSE_GLOBAL_MEMORY_OPERATORS +void * operator new (size_t size, wxChar * fileName, int lineNum) { - static MemoryCriticalSection memLocker; - return memLocker; + return wxDebugAlloc(size, fileName, lineNum, false, false); } -#endif +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 // wxUSE_GLOBAL_MEMORY_OPERATORS +#endif // !(defined(__WXMSW__) && (defined(WXUSINGDLL) || defined(WXMAKINGDLL_BASE))) // TODO: store whether this is a vector or not. void * wxDebugAlloc(size_t size, wxChar * fileName, int lineNum, bool isObject, bool WXUNUSED(isVect) ) { #if USE_THREADSAFE_MEMORY_ALLOCATION - MemoryCriticalSectionLocker lock(GetMemLocker()); + MemoryCriticalSectionLocker lock(memLocker); #endif // If not in debugging allocation mode, do the normal thing @@ -982,7 +995,7 @@ void * wxDebugAlloc(size_t size, wxChar * fileName, int lineNum, bool isObject, void wxDebugFree(void * buf, bool WXUNUSED(isVect) ) { #if USE_THREADSAFE_MEMORY_ALLOCATION - MemoryCriticalSectionLocker lock(GetMemLocker()); + MemoryCriticalSectionLocker lock(memLocker); #endif if (!buf) @@ -1028,6 +1041,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 * ...) { @@ -1106,11 +1121,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; @@ -1125,8 +1140,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 -