X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5260b1c582632afeb8f25db7f10697c8d45461b4..02847e598495dd5b34110eb6ccef6645a1eb29ed:/src/common/memory.cpp diff --git a/src/common/memory.cpp b/src/common/memory.cpp index fee8108d50..1d44a664e9 100644 --- a/src/common/memory.cpp +++ b/src/common/memory.cpp @@ -24,7 +24,7 @@ #include "wx/defs.h" #endif -#if (DEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT +#if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT #ifdef __GNUG__ // #pragma implementation @@ -37,12 +37,16 @@ #include -#if USE_IOSTREAMH +#if wxUSE_IOSTREAMH #include +#include #else #include +#include +# ifdef _MSC_VER + using namespace std; +# endif #endif -#include #if !defined(__WATCOMC__) && !defined(__VMS__) #include @@ -51,7 +55,7 @@ #include #include -#ifdef __WINDOWS__ +#ifdef __WXMSW__ #include #ifdef GetClassInfo @@ -66,11 +70,9 @@ #include "wx/memory.h" -/* #ifdef new #undef new #endif -*/ // wxDebugContext wxTheDebugContext; /* @@ -326,7 +328,7 @@ void wxMemStruct::PrintNode () { wxObject *obj = (wxObject *)m_actualData; wxClassInfo *info = obj->GetClassInfo(); - +/* if (info && info->GetClassName()) wxTrace("%s", info->GetClassName()); else @@ -335,13 +337,25 @@ void wxMemStruct::PrintNode () if (m_fileName) wxTrace(" (%s %d)", m_fileName, (int)m_lineNum); + wxTrace(" at $%lX, size %d\n", (long)GetActualData(), (int)RequestSize()); +*/ + // Let's put this in standard form so IDEs can load the file at the appropriate + // line + if (m_fileName) + wxTrace("%s(%d): ", m_fileName, (int)m_lineNum); + + if (info && info->GetClassName()) + wxTrace("%s", info->GetClassName()); + else + wxTrace("object"); + wxTrace(" at $%lX, size %d\n", (long)GetActualData(), (int)RequestSize()); } else { - wxTrace("Non-object data"); if (m_fileName) - wxTrace(" (%s %d)", m_fileName, (int)m_lineNum); + wxTrace("%s(%d): ", m_fileName, (int)m_lineNum); + wxTrace("non-object data"); wxTrace(" at $%lX, size %d\n", (long)GetActualData(), (int)RequestSize()); } } @@ -353,23 +367,19 @@ void wxMemStruct::Dump () if (m_isObject) { wxObject *obj = (wxObject *)m_actualData; -// wxClassInfo *info = obj->GetClassInfo(); if (m_fileName) - wxTrace("Item (%s %d)", m_fileName, (int)m_lineNum); - else - wxTrace("Item"); + wxTrace("%s(%d): ", m_fileName, (int)m_lineNum); - wxTrace(" at $%lX, size %d: ", (long)GetActualData(), (int)RequestSize()); -// wxTrace(info->GetClassName()); obj->Dump(wxDebugContext::GetStream()); + wxTrace(" at $%lX, size %d", (long)GetActualData(), (int)RequestSize()); wxTrace("\n"); } else { - wxTrace("Non-object data"); if (m_fileName) - wxTrace(" (%s %d)", m_fileName, (int)m_lineNum); + wxTrace("%s(%d): ", m_fileName, (int)m_lineNum); + wxTrace("non-object data"); wxTrace(" at $%lX, size %d\n", (long)GetActualData(), (int)RequestSize()); } } @@ -387,7 +397,9 @@ int wxMemStruct::ValidateNode () ErrorMsg ("Object already deleted"); else { // Can't use the error routines as we have no recognisable object. - wxTrace("Can't verify memory struct - all bets are off!\n"); +#ifndef __WXGTK__ + wxTrace("Can't verify memory struct - all bets are off!\n"); +#endif } return 0; } @@ -623,11 +635,11 @@ void wxDebugContext::TraverseList (PmSFV func, wxMemStruct *from) */ bool wxDebugContext::PrintList (void) { -#if DEBUG +#if WXDEBUG if (!HasStream()) return FALSE; - TraverseList ((PmSFV)&wxMemStruct::PrintNode, (checkPoint ? checkPoint->m_next : NULL)); + TraverseList ((PmSFV)&wxMemStruct::PrintNode, (checkPoint ? checkPoint->m_next : (wxMemStruct*)NULL)); return TRUE; #else @@ -637,7 +649,7 @@ bool wxDebugContext::PrintList (void) bool wxDebugContext::Dump(void) { -#if DEBUG +#if WXDEBUG if (!HasStream()) return FALSE; @@ -649,10 +661,16 @@ bool wxDebugContext::Dump(void) { appNameStr = wxTheApp->GetAppName(); appName = (char*) (const char*) appNameStr; - wxTrace("Memory dump of %s at %s:\n", appName, wxNow()); + wxTrace("----- Memory dump of %s at %s -----\n", appName, WXSTRINGCAST wxNow() ); + } + else + { + wxTrace( "----- Memory dump -----\n" ); } } - TraverseList ((PmSFV)&wxMemStruct::Dump, (checkPoint ? checkPoint->m_next : NULL)); + TraverseList ((PmSFV)&wxMemStruct::Dump, (checkPoint ? checkPoint->m_next : (wxMemStruct*)NULL)); + + wxTrace( "\n\n" ); return TRUE; #else @@ -687,10 +705,26 @@ static wxDebugStatsStruct *InsertStatsStruct(wxDebugStatsStruct *head, wxDebugSt bool wxDebugContext::PrintStatistics(bool detailed) { -#if DEBUG +#if WXDEBUG if (!HasStream()) return FALSE; + if (TRUE) + { + char* appName = "application"; + wxString appNameStr(""); + if (wxTheApp) + { + appNameStr = wxTheApp->GetAppName(); + appName = (char*) (const char*) appNameStr; + wxTrace("----- Memory statistics of %s at %s -----\n", appName, WXSTRINGCAST wxNow() ); + } + else + { + wxTrace( "----- Memory statistics -----\n" ); + } + } + bool currentMode = GetDebugMode(); SetDebugMode(FALSE); @@ -700,7 +734,7 @@ bool wxDebugContext::PrintStatistics(bool detailed) wxDebugStatsStruct *list = NULL; - wxMemStruct *from = (checkPoint ? checkPoint->m_next : NULL); + wxMemStruct *from = (checkPoint ? checkPoint->m_next : (wxMemStruct*)NULL ); if (!from) from = wxDebugContext::GetHead (); @@ -758,6 +792,7 @@ bool wxDebugContext::PrintStatistics(bool detailed) wxTrace("Number of object items: %ld\n", noObjectNodes); wxTrace("Number of non-object items: %ld\n", noNonObjectNodes); wxTrace("Total allocated size: %ld\n", totalSize); + wxTrace("\n\n"); return TRUE; #else @@ -778,14 +813,19 @@ bool wxDebugContext::PrintClasses(void) { appNameStr = wxTheApp->GetAppName(); appName = (char*) (const char*) appNameStr; - wxTrace("Classes in %s:\n\n", appName); + wxTrace("----- Classes in %s -----\n", appName); } } int n = 0; - wxClassInfo *info = wxClassInfo::first; - while (info) + wxNode *node; + wxClassInfo *info; + + wxClassInfo::sm_classTable->BeginFind(); + node = wxClassInfo::sm_classTable->Next(); + while (node) { + info = (wxClassInfo *)node->Data(); if (info->GetClassName()) { wxTrace("%s ", info->GetClassName()); @@ -794,15 +834,15 @@ bool wxDebugContext::PrintClasses(void) wxTrace("is a %s", info->GetBaseClassName1()); else if (info->GetBaseClassName1() && info->GetBaseClassName2()) wxTrace("is a %s, %s", info->GetBaseClassName1(), info->GetBaseClassName2()); - if (info->objectConstructor) + if (info->GetConstructor()) wxTrace(": dynamic\n"); else wxTrace("\n"); } - info = info->next; + node = wxClassInfo::sm_classTable->Next(); n ++; } - wxTrace("\nThere are %d classes derived from wxObject.\n", n); + wxTrace("\nThere are %d classes derived from wxObject.\n\n\n", n); return TRUE; } @@ -819,7 +859,7 @@ int wxDebugContext::Check(bool checkAll) { int nFailures = 0; - wxMemStruct *from = (checkPoint ? checkPoint->m_next : NULL); + wxMemStruct *from = (checkPoint ? checkPoint->m_next : (wxMemStruct*)NULL ); if (!from || checkAll) from = wxDebugContext::GetHead (); @@ -860,7 +900,7 @@ int wxDebugContext::CountObjectsLeft(void) // We'll only do malloc and free for the moment: leave the interesting // stuff for the wxObject versions. -#if DEBUG && USE_GLOBAL_MEMORY_OPERATORS +#if WXDEBUG && wxUSE_GLOBAL_MEMORY_OPERATORS #ifdef new #undef new @@ -884,7 +924,7 @@ void * operator new (size_t size, char * fileName, int lineNum) #endif } -#if !( defined (_MSC_VER) && (_MSC_VER <= 800) ) +#if !( defined (_MSC_VER) && (_MSC_VER <= 1020) ) void * operator new[] (size_t size, char * fileName, int lineNum) { #ifdef NO_DEBUG_ALLOCATION @@ -904,7 +944,15 @@ void operator delete (void * buf) #endif } -#if !( defined (_MSC_VER) && (_MSC_VER <= 800) ) +// VC++ 6.0 +#if _MSC_VER >= 1200 +void operator delete(void* pData, char* /* fileName */, int /* lineNum */) +{ + ::operator delete(pData); +} +#endif + +#if !( defined (_MSC_VER) && (_MSC_VER <= 1020) ) void operator delete[] (void * buf) { #ifdef NO_DEBUG_ALLOCATION @@ -918,7 +966,7 @@ void operator delete[] (void * buf) #endif // TODO: store whether this is a vector or not. -void * wxDebugAlloc(size_t size, char * fileName, int lineNum, bool isObject, bool isVect) +void * wxDebugAlloc(size_t size, char * fileName, int lineNum, bool isObject, bool WXUNUSED(isVect) ) { // If not in debugging allocation mode, do the normal thing // so we don't leave any trace of ourselves in the node list. @@ -969,7 +1017,7 @@ void * wxDebugAlloc(size_t size, char * fileName, int lineNum, bool isObject, bo } // TODO: check whether was allocated as a vector -void wxDebugFree(void * buf, bool isVect) +void wxDebugFree(void * buf, bool WXUNUSED(isVect) ) { if (!buf) return; @@ -1021,7 +1069,7 @@ void wxTrace(const char *fmt ...) va_start(ap, fmt); -#ifdef __WINDOWS__ +#ifdef __WXMSW__ wvsprintf(buffer,fmt,ap) ; #else vsprintf(buffer,fmt,ap) ; @@ -1035,7 +1083,7 @@ void wxTrace(const char *fmt ...) wxDebugContext::GetStream().flush(); } else -#ifdef __WINDOWS__ +#ifdef __WXMSW__ OutputDebugString((LPCSTR)buffer) ; #else fprintf(stderr, buffer); @@ -1053,7 +1101,7 @@ void wxTraceLevel(int level, const char *fmt ...) va_start(ap, fmt); -#ifdef __WINDOWS__ +#ifdef __WXMSW__ wvsprintf(buffer,fmt,ap) ; #else vsprintf(buffer,fmt,ap) ; @@ -1067,14 +1115,14 @@ void wxTraceLevel(int level, const char *fmt ...) wxDebugContext::GetStream().flush(); } else -#ifdef __WINDOWS__ +#ifdef __WXMSW__ OutputDebugString((LPCSTR)buffer) ; #else fprintf(stderr, buffer); #endif } -#else // USE_MEMORY_TRACING && DEBUG +#else // wxUSE_MEMORY_TRACING && WXDEBUG void wxTrace(const char *WXUNUSED(fmt) ...) { }