From b2e62791783802c10e70e714c5fd3c49d345a49e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 24 Apr 2002 14:52:53 +0000 Subject: [PATCH] Removed the use of __FUNCTION__ from MemoryManager to remove problems with VisualStudio .NET compile. Added support for OSG_NOTIFY_LEVEL and OSG_FILE_PATH into the relevant getenv routines. This compliments the exisiting OSGNOTIFYLEVEL & OSGFILEPATH which are deprecated but still supported. The OSG_ version are more consistent with the rest of the env variables used in the OSG. --- include/osg/MemoryManager | 28 ++++++++------------- src/osg/MemoryManager.cpp | 43 ++++++++++++++------------------- src/osg/Notify.cpp | 3 ++- src/osgDB/FileUtils_Mac.cpp | 7 +++++- src/osgDB/FileUtils_Unix.cpp | 7 +++++- src/osgDB/FileUtils_Windows.cpp | 7 +++++- 6 files changed, 48 insertions(+), 47 deletions(-) diff --git a/include/osg/MemoryManager b/include/osg/MemoryManager index 9182fa619..9afd1d57a 100644 --- a/include/osg/MemoryManager +++ b/include/osg/MemoryManager @@ -19,14 +19,6 @@ #include #include -// --------------------------------------------------------------------------------------------------------------------------------- -// For systems that don't have the __FUNCTION__ variable, we can just define it here -// --------------------------------------------------------------------------------------------------------------------------------- - -#ifndef __FUNCTION__ -#define __FUNCTION__ "??" -#endif - // --------------------------------------------------------------------------------------------------------------------------------- // Types // --------------------------------------------------------------------------------------------------------------------------------- @@ -79,7 +71,7 @@ SG_EXPORT extern const unsigned int m_alloc_free; // Used by the macros // --------------------------------------------------------------------------------------------------------------------------------- -SG_EXPORT extern void m_setOwner(const char *file, const unsigned int line, const char *func); +SG_EXPORT extern void m_setOwner(const char *file, const unsigned int line); // --------------------------------------------------------------------------------------------------------------------------------- // Allocation breakpoints @@ -93,11 +85,11 @@ SG_EXPORT extern void m_breakOnAllocation(unsigned int count); // The meat of the memory tracking software // --------------------------------------------------------------------------------------------------------------------------------- -SG_EXPORT extern void *m_allocator(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc, +SG_EXPORT extern void *m_allocator(const char *sourceFile, const unsigned int sourceLine, const unsigned int allocationType, const size_t reportedSize); -SG_EXPORT extern void *m_reallocator(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc, +SG_EXPORT extern void *m_reallocator(const char *sourceFile, const unsigned int sourceLine, const unsigned int reallocationType, const size_t reportedSize, void *reportedAddress); -SG_EXPORT extern void m_deallocator(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc, +SG_EXPORT extern void m_deallocator(const char *sourceFile, const unsigned int sourceLine, const unsigned int deallocationType, const void *reportedAddress); // --------------------------------------------------------------------------------------------------------------------------------- @@ -140,12 +132,12 @@ SG_EXPORT extern sMStats m_getMemoryStatistics(); // Macros -- "Kids, please don't try this at home. We're trained professionals here." :) // --------------------------------------------------------------------------------------------------------------------------------- - #define osgNew (m_setOwner (__FILE__,__LINE__,__FUNCTION__),false) ? NULL : new - #define osgDelete (m_setOwner (__FILE__,__LINE__,__FUNCTION__),false) ? m_setOwner("",0,"") : delete - #define osgMalloc(sz) m_allocator (__FILE__,__LINE__,__FUNCTION__,m_alloc_malloc,sz) - #define osgCalloc(sz) m_allocator (__FILE__,__LINE__,__FUNCTION__,m_alloc_calloc,sz) - #define osgRealloc(ptr,sz) m_reallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_realloc,sz,ptr) - #define osgFree(ptr) m_deallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_free,ptr) + #define osgNew (m_setOwner (__FILE__,__LINE__),false) ? NULL : new + #define osgDelete (m_setOwner (__FILE__,__LINE__),false) ? m_setOwner("",0) : delete + #define osgMalloc(sz) m_allocator (__FILE__,__LINE__,m_alloc_malloc,sz) + #define osgCalloc(sz) m_allocator (__FILE__,__LINE__,m_alloc_calloc,sz) + #define osgRealloc(ptr,sz) m_reallocator(__FILE__,__LINE__,m_alloc_realloc,sz,ptr) + #define osgFree(ptr) m_deallocator(__FILE__,__LINE__,m_alloc_free,ptr) #else diff --git a/src/osg/MemoryManager.cpp b/src/osg/MemoryManager.cpp index d418b4316..f0f0fab3b 100644 --- a/src/osg/MemoryManager.cpp +++ b/src/osg/MemoryManager.cpp @@ -192,7 +192,6 @@ static unsigned int currentAllocationCount = 0; static unsigned int breakOnAllocationCount = 0; static sMStats stats; static const char *sourceFile = "??"; -static const char *sourceFunc = "??"; static unsigned int sourceLine = 0; static bool staticDeinitTime = false; static sAllocUnit **reservoirBuffer = NULL; @@ -279,11 +278,11 @@ static const char *sourceFileStripper(const char *sourceFile) // --------------------------------------------------------------------------------------------------------------------------------- -static const char *ownerString(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc) +static const char *ownerString(const char *sourceFile, const unsigned int sourceLine) { static char str[90]; memset(str, 0, sizeof(str)); - sprintf(str, "%s(%05d)::%s", sourceFileStripper(sourceFile), sourceLine, sourceFunc); + sprintf(str, "%s(%05d)", sourceFileStripper(sourceFile), sourceLine); return str; } @@ -444,7 +443,6 @@ static void resetGlobals() { sourceFile = "??"; sourceLine = 0; - sourceFunc = "??"; } // --------------------------------------------------------------------------------------------------------------------------------- @@ -501,7 +499,7 @@ static void dumpAllocations(FILE *fp) allocationTypes[ptr->allocationType], ptr->breakOnDealloc ? 'Y':'N', ptr->breakOnRealloc ? 'Y':'N', - ownerString(ptr->sourceFile, ptr->sourceLine, ptr->sourceFunc)); + ownerString(ptr->sourceFile, ptr->sourceLine)); ptr = ptr->next; } } @@ -656,11 +654,10 @@ void m_breakOnAllocation(unsigned int count) // Used by the macros // --------------------------------------------------------------------------------------------------------------------------------- -void m_setOwner(const char *file, const unsigned int line, const char *func) +void m_setOwner(const char *file, const unsigned int line) { sourceFile = file; sourceLine = line; - sourceFunc = func; } // --------------------------------------------------------------------------------------------------------------------------------- @@ -690,7 +687,7 @@ void *operator new(size_t reportedSize) throw (std::bad_alloc) { // Try the allocation - void *ptr = m_allocator(sourceFile, sourceLine, sourceFunc, m_alloc_new, reportedSize); + void *ptr = m_allocator(sourceFile, sourceLine, m_alloc_new, reportedSize); if (ptr) { #ifdef TEST_MEMORY_MANAGER @@ -742,7 +739,7 @@ void *operator new[](size_t reportedSize) throw (std::bad_alloc) { // Try the allocation - void *ptr = m_allocator(sourceFile, sourceLine, sourceFunc, m_alloc_new_array, reportedSize); + void *ptr = m_allocator(sourceFile, sourceLine, m_alloc_new_array, reportedSize); if (ptr) { #ifdef TEST_MEMORY_MANAGER @@ -800,7 +797,7 @@ void *operator new(size_t reportedSize, const char *sourceFile, int sourceLin { // Try the allocation - void *ptr = m_allocator(sourceFile, sourceLine, "??", m_alloc_new, reportedSize); + void *ptr = m_allocator(sourceFile, sourceLine, m_alloc_new, reportedSize); if (ptr) { #ifdef TEST_MEMORY_MANAGER @@ -852,7 +849,7 @@ void *operator new[](size_t reportedSize, const char *sourceFile, int sourceL { // Try the allocation - void *ptr = m_allocator(sourceFile, sourceLine, "??", m_alloc_new_array, reportedSize); + void *ptr = m_allocator(sourceFile, sourceLine, m_alloc_new_array, reportedSize); if (ptr) { #ifdef TEST_MEMORY_MANAGER @@ -903,7 +900,7 @@ void operator delete(void *reportedAddress) throw () if (!reportedAddress) return; - m_deallocator(sourceFile, sourceLine, sourceFunc, m_alloc_delete, reportedAddress); + m_deallocator(sourceFile, sourceLine, m_alloc_delete, reportedAddress); #ifdef TEST_MEMORY_MANAGER log("EXIT : delete"); @@ -922,7 +919,7 @@ void operator delete[](void *reportedAddress) throw () if (!reportedAddress) return; - m_deallocator(sourceFile, sourceLine, sourceFunc, m_alloc_delete_array, reportedAddress); + m_deallocator(sourceFile, sourceLine, m_alloc_delete_array, reportedAddress); #ifdef TEST_MEMORY_MANAGER log("EXIT : delete[]"); @@ -936,7 +933,7 @@ void operator delete[](void *reportedAddress) throw () // Allocate memory and track it // --------------------------------------------------------------------------------------------------------------------------------- -void *m_allocator(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc, const unsigned int allocationType, const size_t reportedSize) +void *m_allocator(const char *sourceFile, const unsigned int sourceLine, const unsigned int allocationType, const size_t reportedSize) { try { @@ -950,7 +947,7 @@ void *m_allocator(const char *sourceFile, const unsigned int sourceLine, cons // Log the request - if (alwaysLogAll) log("%05d %-40s %8s : %s", currentAllocationCount, ownerString(sourceFile, sourceLine, sourceFunc), allocationTypes[allocationType], memorySizeString(reportedSize)); + if (alwaysLogAll) log("%05d %-40s %8s : %s", currentAllocationCount, ownerString(sourceFile, sourceLine), allocationTypes[allocationType], memorySizeString(reportedSize)); // If you hit this assert, you requested a breakpoint on a specific allocation count m_assert(currentAllocationCount != breakOnAllocationCount); @@ -1024,8 +1021,6 @@ void *m_allocator(const char *sourceFile, const unsigned int sourceLine, cons au->allocationNumber = currentAllocationCount; if (sourceFile) strncpy(au->sourceFile, sourceFileStripper(sourceFile), sizeof(au->sourceFile) - 1); else strcpy (au->sourceFile, "??"); - if (sourceFunc) strncpy(au->sourceFunc, sourceFunc, sizeof(au->sourceFunc) - 1); - else strcpy (au->sourceFunc, "??"); // We don't want to assert with random failures, because we want the application to deal with them. @@ -1115,7 +1110,7 @@ void *m_allocator(const char *sourceFile, const unsigned int sourceLine, cons // Reallocate memory and track it // --------------------------------------------------------------------------------------------------------------------------------- -void *m_reallocator(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc, const unsigned int reallocationType, const size_t reportedSize, void *reportedAddress) +void *m_reallocator(const char *sourceFile, const unsigned int sourceLine, const unsigned int reallocationType, const size_t reportedSize, void *reportedAddress) { try { @@ -1127,7 +1122,7 @@ void *m_reallocator(const char *sourceFile, const unsigned int sourceLine, co if (!reportedAddress) { - return m_allocator(sourceFile, sourceLine, sourceFunc, reallocationType, reportedSize); + return m_allocator(sourceFile, sourceLine, reallocationType, reportedSize); } // Increase our allocation count @@ -1139,7 +1134,7 @@ void *m_reallocator(const char *sourceFile, const unsigned int sourceLine, co // Log the request - if (alwaysLogAll) log("%05d %-40s %8s(%010p): %s", currentAllocationCount, ownerString(sourceFile, sourceLine, sourceFunc), allocationTypes[reallocationType], reportedAddress, memorySizeString(reportedSize)); + if (alwaysLogAll) log("%05d %-40s %8s(%010p): %s", currentAllocationCount, ownerString(sourceFile, sourceLine), allocationTypes[reallocationType], reportedAddress, memorySizeString(reportedSize)); // Locate the existing allocation unit @@ -1219,8 +1214,6 @@ void *m_reallocator(const char *sourceFile, const unsigned int sourceLine, co au->allocationNumber = currentAllocationCount; if (sourceFile) strncpy(au->sourceFile, sourceFileStripper(sourceFile), sizeof(au->sourceFile) - 1); else strcpy (au->sourceFile, "??"); - if (sourceFunc) strncpy(au->sourceFunc, sourceFunc, sizeof(au->sourceFunc) - 1); - else strcpy (au->sourceFunc, "??"); // The reallocation may cause the address to change, so we should relocate our allocation unit within the hash table @@ -1312,7 +1305,7 @@ void *m_reallocator(const char *sourceFile, const unsigned int sourceLine, co // Deallocate memory and track it // --------------------------------------------------------------------------------------------------------------------------------- -void m_deallocator(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc, const unsigned int deallocationType, const void *reportedAddress) +void m_deallocator(const char *sourceFile, const unsigned int sourceLine, const unsigned int deallocationType, const void *reportedAddress) { try { @@ -1322,7 +1315,7 @@ void m_deallocator(const char *sourceFile, const unsigned int sourceLine, con // Log the request - if (alwaysLogAll) log(" %-40s %8s(%010p)", ownerString(sourceFile, sourceLine, sourceFunc), allocationTypes[deallocationType], reportedAddress); + if (alwaysLogAll) log(" %-40s %8s(%010p)", ownerString(sourceFile, sourceLine), allocationTypes[deallocationType], reportedAddress); // Go get the allocation unit @@ -1564,7 +1557,7 @@ void m_dumpAllocUnit(const sAllocUnit *allocUnit, const char *prefix) log("%sAddress (actual) : %010p", prefix, allocUnit->actualAddress); log("%sSize (reported) : 0x%08X (%s)", prefix, allocUnit->reportedSize, memorySizeString(allocUnit->reportedSize)); log("%sSize (actual) : 0x%08X (%s)", prefix, allocUnit->actualSize, memorySizeString(allocUnit->actualSize)); - log("%sOwner : %s(%d)::%s", prefix, allocUnit->sourceFile, allocUnit->sourceLine, allocUnit->sourceFunc); + log("%sOwner : %s(%d)", prefix, allocUnit->sourceFile, allocUnit->sourceLine); log("%sAllocation type : %s", prefix, allocationTypes[allocUnit->allocationType]); log("%sAllocation number : %d", prefix, allocUnit->allocationNumber); } diff --git a/src/osg/Notify.cpp b/src/osg/Notify.cpp index 75127fc27..9d8845e78 100644 --- a/src/osg/Notify.cpp +++ b/src/osg/Notify.cpp @@ -39,7 +39,8 @@ bool osg::initNotifyLevel() g_NotifyLevel = osg::NOTICE; // Default value - char *OSGNOTIFYLEVEL=getenv("OSGNOTIFYLEVEL"); + char* OSGNOTIFYLEVEL=getenv("OSG_NOTIFY_LEVEL"); + if (!OSGNOTIFYLEVEL) OSGNOTIFYLEVEL=getenv("OSGNOTIFYLEVEL"); if(OSGNOTIFYLEVEL) { diff --git a/src/osgDB/FileUtils_Mac.cpp b/src/osgDB/FileUtils_Mac.cpp index be8bb8704..8e79a474e 100644 --- a/src/osgDB/FileUtils_Mac.cpp +++ b/src/osgDB/FileUtils_Mac.cpp @@ -250,7 +250,12 @@ static char *getPathOfApplicationResource(const std::string& resourceName) void osgDB::initFilePath( void ) { char *ptr; - if( (ptr = getenv( "OSGFILEPATH" )) ) + if( (ptr = getenv( "OSG_FILE_PATH" )) ) + { + notify(DEBUG_INFO) << "osgDB::Init("<