diff --git a/dtool/Config.Irix.pp b/dtool/Config.Irix.pp index d1ea9521e9..825bac1f57 100644 --- a/dtool/Config.Irix.pp +++ b/dtool/Config.Irix.pp @@ -105,5 +105,6 @@ // Must global operator new and delete functions throw exceptions? #define GLOBAL_OPERATOR_NEW_EXCEPTIONS -// Do we expect the old STL allocator? -#define OLD_STYLE_ALLOCATOR 1 +// What is the syntax of the STL allocator declaration? See +// LocalSetup.pp for allowable values. +#define STL_ALLOCATOR OLD diff --git a/dtool/Config.Linux.pp b/dtool/Config.Linux.pp index 7efff23330..9ca5050fc4 100644 --- a/dtool/Config.Linux.pp +++ b/dtool/Config.Linux.pp @@ -105,5 +105,6 @@ // Must global operator new and delete functions throw exceptions? #define GLOBAL_OPERATOR_NEW_EXCEPTIONS 1 -// What style STL allocator should we declare? -#define GNU_STYLE_ALLOCATOR 1 +// What is the syntax of the STL allocator declaration? See +// LocalSetup.pp for allowable values. +#define STL_ALLOCATOR GNU diff --git a/dtool/Config.Win32.pp b/dtool/Config.Win32.pp index 89794d35bd..455ffa8ff1 100644 --- a/dtool/Config.Win32.pp +++ b/dtool/Config.Win32.pp @@ -105,12 +105,10 @@ // Must global operator new and delete functions throw exceptions? #define GLOBAL_OPERATOR_NEW_EXCEPTIONS -// Do we expect the old STL allocator? -// this indicates OLD_STYLE_ALLOCATOR is NOT used (defined as the empty string) -#define OLD_STYLE_ALLOCATOR - -// this is reqd for msvc 7.0 to build (beta-only, havent tested final). Default on for Opt4, off otherwise -//#define USE_UNKNOWN_ALLOCATOR 1 +// What is the syntax of the STL allocator declaration? See +// LocalSetup.pp for allowable values. +//#define STL_ALLOCATOR VC6 +#define STL_ALLOCATOR MODERN // can Intel C++ build this directory successfully (if not, change CC to msvc) #define NOT_INTEL_BUILDABLE false diff --git a/dtool/Config.pp b/dtool/Config.pp index 43aaf36f18..22d2f36df9 100644 --- a/dtool/Config.pp +++ b/dtool/Config.pp @@ -91,7 +91,7 @@ // 3 - Full compiler optimizations, no debug symbols // 4 - Full optimizations, no debug symbols, and asserts removed // - +#define OPTIMIZE 3 // NOTE: In the following, to indicate "yes" to a yes/no question, // define the variable to be a nonempty string. To indicate "no", @@ -154,6 +154,13 @@ // to enable it only for optimize levels 1 and 2. #defer TRACK_IN_INTERPRETER $[<= $[OPTIMIZE], 2] +// Do you want to compile in support for tracking memory usage? This +// enables you to define the variable "track-memory-usage" at runtime +// to help track memory leaks, and also report total memory usage on +// PStats. There is some small overhead for having this ability +// available, even if it is unused. +#defer DO_MEMORY_USAGE $[<= $[OPTIMIZE], 3] + // Do you want to compile in support for pipelining? This enables // setting and accessing multiple different copies of frame-specific // data stored in nodes, etc. At the moment, Panda cannot actually diff --git a/dtool/LocalSetup.pp b/dtool/LocalSetup.pp index d7ce2777e1..d875f4ee9b 100644 --- a/dtool/LocalSetup.pp +++ b/dtool/LocalSetup.pp @@ -38,6 +38,9 @@ $[cdefine HAVE_PYTHON] /* Define if we want to track callbacks from within the show code. */ $[cdefine TRACK_IN_INTERPRETER] +/* Define if we want to enable track-memory-usage. */ +$[cdefine DO_MEMORY_USAGE] + /* Define if we want to compile in support for pipelining. */ $[cdefine DO_PIPELINING] @@ -212,13 +215,36 @@ $[cdefine HAVE_RTTI] $[cdefine GLOBAL_OPERATOR_NEW_EXCEPTIONS] /* What style STL allocator should we declare? */ - -// Use this to force UNKNOWN_ALLOCATOR for non-Opt4 (it is already default for Opt4 using /DUNKNOWN_ALLOCATOR) -// see dtoolbase.h -$[cdefine USE_UNKNOWN_ALLOCATOR] - +#define OLD_STYLE_ALLOCATOR +#define GNU_STYLE_ALLOCATOR +#define VC6_STYLE_ALLOCATOR +#define MODERN_STYLE_ALLOCATOR +#define NO_STYLE_ALLOCATOR +#if $[eq $[OPTIMIZE], 4] + // In optimize level 4, we never try to use custom allocators. + #define NO_STYLE_ALLOCATOR 1 +#elif $[eq $[STL_ALLOCATOR], OLD] + // "OLD": Irix 6.2-era STL. + #set OLD_STYLE_ALLOCATOR 1 +#elif $[eq $[STL_ALLOCATOR], ECGS] + // "GNU": gcc 2.95-era. + #set GNU_STYLE_ALLOCATOR 1 +#elif $[eq $[STL_ALLOCATOR], VC6] + // "VC6": Microsoft Visual C++ 6. + #set VC6_STYLE_ALLOCATOR 1 +#elif $[eq $[STL_ALLOCATOR], MODERN] + // "MODERN": Have we finally come to a standard? + #set MODERN_STYLE_ALLOCATOR 1 +#else + // Anything else is "unknown". We won't try to define allocators at + // all. + #set NO_STYLE_ALLOCATOR 1 +#endif $[cdefine OLD_STYLE_ALLOCATOR] $[cdefine GNU_STYLE_ALLOCATOR] +$[cdefine VC6_STYLE_ALLOCATOR] +$[cdefine MODERN_STYLE_ALLOCATOR] +$[cdefine NO_STYLE_ALLOCATOR] #end dtool_config.h diff --git a/dtool/pptempl/compilerSettings.pp b/dtool/pptempl/compilerSettings.pp index 9a8f821b26..8f29744f1b 100644 --- a/dtool/pptempl/compilerSettings.pp +++ b/dtool/pptempl/compilerSettings.pp @@ -15,8 +15,6 @@ #define RELEASEFLAGS /MD #define WARNING_LEVEL_FLAG /W3 - #define CDEFINES_OPT4 UNKNOWN_ALLOCATOR - // NODEFAULTLIB ensures static libs linked in will connect to the correct msvcrt, so no debug/release mixing occurs #define LDFLAGS_OPT1 /NODEFAULTLIB:MSVCRT.LIB #define LDFLAGS_OPT2 /NODEFAULTLIB:MSVCRT.LIB @@ -61,11 +59,10 @@ #endif #endif - // remove 1-3 when allocator stuff is rewritten to build with VC7 STL - #define CDEFINES_OPT1 UNKNOWN_ALLOCATOR - #define CDEFINES_OPT2 UNKNOWN_ALLOCATOR - #define CDEFINES_OPT3 UNKNOWN_ALLOCATOR - #define CDEFINES_OPT4 UNKNOWN_ALLOCATOR + #define CDEFINES_OPT1 + #define CDEFINES_OPT2 + #define CDEFINES_OPT3 + #define CDEFINES_OPT4 // NODEFAULTLIB ensures static libs linked in will connect to the correct msvcrt, so no debug/release mixing occurs #define LDFLAGS_OPT1 /NODEFAULTLIB:MSVCRT.LIB @@ -126,8 +123,6 @@ #define LDFLAGS_OPT4 /Qipo #endif - #define CDEFINES_OPT4 UNKNOWN_ALLOCATOR - // NODEFAULTLIB ensures static libs linked in will connect to the correct msvcrt, so no debug/release mixing occurs #define LDFLAGS_OPT1 /NODEFAULTLIB:MSVCRT.LIB #define LDFLAGS_OPT2 /NODEFAULTLIB:MSVCRT.LIB diff --git a/dtool/src/dconfig/symbolEnt.h b/dtool/src/dconfig/symbolEnt.h index 92263c2af0..19493f3be6 100644 --- a/dtool/src/dconfig/symbolEnt.h +++ b/dtool/src/dconfig/symbolEnt.h @@ -22,8 +22,7 @@ #include #include "config_setup.h" - -#include +#include "pvector.h" namespace Config { @@ -67,7 +66,7 @@ class EXPCL_DTOOLCONFIG SymbolEnt { namespace Config { -typedef std::vector vector_SymbolEnt; +typedef ::vector_SymbolEnt vector_SymbolEnt; #include "symbolEnt.I" diff --git a/dtool/src/dtoolbase/dallocator.T b/dtool/src/dtoolbase/dallocator.T index d945b96f4b..789100020e 100644 --- a/dtool/src/dtoolbase/dallocator.T +++ b/dtool/src/dtoolbase/dallocator.T @@ -18,7 +18,6 @@ #if defined(OLD_STYLE_ALLOCATOR) -#ifndef NDEBUG template INLINE Type *dallocator:: allocate(size_t n) { @@ -30,7 +29,6 @@ INLINE void dallocator:: deallocate(void *p, size_t) { default_operator_delete(p); } -#endif // NDEBUG #elif defined(GNU_STYLE_ALLOCATOR) @@ -45,7 +43,6 @@ INLINE dallocator:: dallocator(const dallocator<_Tp1> &) { } -#ifndef NDEBUG template INLINE Type *dallocator:: allocate(size_t n) { @@ -57,11 +54,19 @@ INLINE void dallocator:: deallocate(void *p, size_t) { default_operator_delete(p); } -#endif // NDEBUG -#else // *_STYLE_ALLOCATOR +#elif MODERN_STYLE_ALLOCATOR + +template +INLINE dallocator:: +dallocator() { +} + +template +INLINE dallocator:: +dallocator(const allocator ©) { +} -#ifndef NDEBUG template INLINE dallocator::pointer dallocator:: allocate(dallocator::size_type n, allocator::const_pointer) { @@ -74,6 +79,5 @@ INLINE void dallocator:: deallocate(void *p, allocator::size_type) { default_operator_delete(p); } -#endif // NDEBUG #endif // *_STYLE_ALLOCATOR diff --git a/dtool/src/dtoolbase/dallocator.h b/dtool/src/dtoolbase/dallocator.h index 76c9149e2a..812c593c5d 100644 --- a/dtool/src/dtoolbase/dallocator.h +++ b/dtool/src/dtoolbase/dallocator.h @@ -35,20 +35,22 @@ // within the MemoryUsage class itself. //////////////////////////////////////////////////////////////////// -#if defined(UNKNOWN_ALLOCATOR) +#if defined(NO_STYLE_ALLOCATOR) +// If we're not trying to make custom allocators (either we don't know +// what kind of syntax this STL library wants, or we're compiling with +// OPTIMIZE 4), then simply use the standard allocator. #define dallocator allocator + #elif defined(OLD_STYLE_ALLOCATOR) -// Early versions of gcc wanted to use its own kind of allocator, +// Early versions of gcc wanted to use their own kind of allocator, // somewhat different from the STL standard. Irix uses this one too. // It might be inherited from an early draft of the STL standard. template class dallocator : public alloc { public: -#ifndef NDEBUG INLINE static Type *allocate(size_t n); INLINE static void deallocate(void *p, size_t n); -#endif // NDEBUG }; #elif defined(GNU_STYLE_ALLOCATOR) @@ -62,31 +64,31 @@ public: template INLINE dallocator(const dallocator<_Tp1> &other); -#ifndef NDEBUG INLINE Type *allocate(size_t n); INLINE void deallocate(void *p, size_t n); -#endif // NDEBUG template struct rebind { typedef dallocator<_Tp1> other; }; }; -#else // *_STYLE_ALLOCATOR +#elif defined(MODERN_STYLE_ALLOCATOR) -// This is the correct allocator declaration as the current C++ -// standard defines it. +// The final specification? template class dallocator : public allocator { public: -#ifndef NDEBUG + INLINE dallocator(); + INLINE dallocator(const allocator ©); INLINE pointer allocate(size_type n, allocator::const_pointer hint = 0); INLINE void deallocate(void *p, size_type n); -#endif // NDEBUG }; + +#else +#error Unrecognized allocator symbol defined! #endif // *_STYLE_ALLOCATOR -#if !defined(UNKNOWN_ALLOCATOR) +#ifndef NO_STYLE_ALLOCATOR #include "dallocator.T" #endif diff --git a/dtool/src/dtoolbase/dtoolbase.h b/dtool/src/dtoolbase/dtoolbase.h index ce7e4682d3..1b423e4b25 100644 --- a/dtool/src/dtoolbase/dtoolbase.h +++ b/dtool/src/dtoolbase/dtoolbase.h @@ -71,10 +71,6 @@ #endif #endif /* WIN32_VC */ -#if defined(USE_UNKNOWN_ALLOCATOR) && !defined(UNKNOWN_ALLOCATOR) -#define UNKNOWN_ALLOCATOR 1 -#endif - #include "dtoolsymbols.h" #ifdef HAVE_MALLOC_H diff --git a/dtool/src/dtoolbase/pallocator.T b/dtool/src/dtoolbase/pallocator.T index bbb351f0e3..46ecd722af 100644 --- a/dtool/src/dtoolbase/pallocator.T +++ b/dtool/src/dtoolbase/pallocator.T @@ -18,7 +18,6 @@ #if defined(OLD_STYLE_ALLOCATOR) -#ifndef NDEBUG template INLINE Type *pallocator:: allocate(size_t n) { @@ -30,7 +29,6 @@ INLINE void pallocator:: deallocate(void *p, size_t) { (*global_operator_delete)(p); } -#endif // NDEBUG #elif defined(GNU_STYLE_ALLOCATOR) @@ -45,7 +43,6 @@ INLINE pallocator:: pallocator(const pallocator<_Tp1> &) { } -#ifndef NDEBUG template INLINE Type *pallocator:: allocate(size_t n) { @@ -57,11 +54,29 @@ INLINE void pallocator:: deallocate(void *p, size_t) { (*global_operator_delete)(p); } -#endif // NDEBUG -#else // *_STYLE_ALLOCATOR +#elif VC6_STYLE_ALLOCATOR + +template +INLINE pallocator::pointer pallocator:: +allocate(pallocator::size_type n, allocator::const_pointer) { + return (pallocator::pointer)(*global_operator_new)(n * sizeof(Type)); +} + +template +INLINE void pallocator:: +//deallocate(pallocator::pointer p, allocator::size_type) { +deallocate(void *p, allocator::size_type) { + (*global_operator_delete)(p); +} + +#elif MODERN_STYLE_ALLOCATOR + +template +INLINE pallocator:: +pallocator() throw() { +} -#ifndef NDEBUG template INLINE pallocator::pointer pallocator:: allocate(pallocator::size_type n, allocator::const_pointer) { @@ -74,6 +89,5 @@ INLINE void pallocator:: deallocate(void *p, allocator::size_type) { (*global_operator_delete)(p); } -#endif // NDEBUG #endif // *_STYLE_ALLOCATOR diff --git a/dtool/src/dtoolbase/pallocator.h b/dtool/src/dtoolbase/pallocator.h index 4745dbead0..4eac30e222 100644 --- a/dtool/src/dtoolbase/pallocator.h +++ b/dtool/src/dtoolbase/pallocator.h @@ -34,21 +34,22 @@ // to use a pallocator. //////////////////////////////////////////////////////////////////// -#if defined(UNKNOWN_ALLOCATOR) +#if defined(NO_STYLE_ALLOCATOR) +// If we're not trying to make custom allocators (either we don't know +// what kind of syntax this STL library wants, or we're compiling with +// OPTIMIZE 4), then simply use the standard allocator. #define pallocator allocator #elif defined(OLD_STYLE_ALLOCATOR) -// Early versions of gcc wanted to use its own kind of allocator, +// Early versions of gcc wanted to use their own kind of allocator, // somewhat different from the STL standard. Irix uses this one too. // It might be inherited from an early draft of the STL standard. template class pallocator : public alloc { public: -#ifndef NDEBUG INLINE static Type *allocate(size_t n); INLINE static void deallocate(void *p, size_t n); -#endif // NDEBUG }; #elif defined(GNU_STYLE_ALLOCATOR) @@ -62,31 +63,48 @@ public: template INLINE pallocator(const pallocator<_Tp1> &other); -#ifndef NDEBUG INLINE Type *allocate(size_t n); INLINE void deallocate(void *p, size_t n); -#endif // NDEBUG template struct rebind { typedef pallocator<_Tp1> other; }; }; -#else // *_STYLE_ALLOCATOR +#elif defined(VC6_STYLE_ALLOCATOR) -// This is the correct allocator declaration as the current C++ -// standard defines it. +// The VC6-era definition. template class pallocator : public allocator { public: -#ifndef NDEBUG INLINE pointer allocate(size_type n, allocator::const_pointer hint = 0); INLINE void deallocate(void *p, size_type n); -#endif // NDEBUG }; + +#elif defined(MODERN_STYLE_ALLOCATOR) + +// The final specification? +template +class pallocator : public allocator { +public: + INLINE pallocator() throw(); + + // template member functions in VC++ can only be defined in-class. + template + INLINE pallocator(const pallocator ©) throw() { } + + INLINE pointer allocate(size_type n, allocator::const_pointer hint = 0); + INLINE void deallocate(void *p, size_type n); + + template + struct rebind { typedef pallocator other; }; +}; + +#else +#error Unrecognized allocator symbol defined! #endif // *_STYLE_ALLOCATOR -#if !defined(UNKNOWN_ALLOCATOR) +#ifndef NO_STYLE_ALLOCATOR #include "pallocator.T" #endif diff --git a/dtool/src/dtoolbase/pdeque.h b/dtool/src/dtoolbase/pdeque.h index e129bab9cd..6949898a43 100644 --- a/dtool/src/dtoolbase/pdeque.h +++ b/dtool/src/dtoolbase/pdeque.h @@ -23,7 +23,9 @@ #include "pallocator.h" #include -#ifdef UNKNOWN_ALLOCATOR +#ifdef NO_STYLE_ALLOCATOR +// If we're not using custom allocators, just use the standard class +// definition. #define pdeque deque #else @@ -44,5 +46,5 @@ public: pdeque(size_type n, const Type &value) : deque >(n, value) { } }; -#endif +#endif // NO_STYLE_ALLOCATOR #endif diff --git a/dtool/src/dtoolbase/plist.h b/dtool/src/dtoolbase/plist.h index 91d4ea2733..3ac13c3e07 100644 --- a/dtool/src/dtoolbase/plist.h +++ b/dtool/src/dtoolbase/plist.h @@ -23,7 +23,9 @@ #include "pallocator.h" #include -#ifdef UNKNOWN_ALLOCATOR +#ifdef NO_STYLE_ALLOCATOR +// If we're not using custom allocators, just use the standard class +// definition. #define plist list #else @@ -50,5 +52,5 @@ public: typedef list >::const_reverse_iterator const_reverse_iterator; }; -#endif +#endif // NO_STYLE_ALLOCATOR #endif diff --git a/dtool/src/dtoolbase/pmap.h b/dtool/src/dtoolbase/pmap.h index 8c9342ff17..ad82d6771d 100644 --- a/dtool/src/dtoolbase/pmap.h +++ b/dtool/src/dtoolbase/pmap.h @@ -24,7 +24,9 @@ #include -#ifdef UNKNOWN_ALLOCATOR +#ifdef NO_STYLE_ALLOCATOR +// If we're not using custom allocators, just use the standard class +// definition. #define pmap map #define pmultimap multimap #else @@ -59,5 +61,5 @@ public: pmultimap(const Compare &comp) : multimap >(comp) { } }; -#endif +#endif // NO_STYLE_ALLOCATOR #endif diff --git a/dtool/src/dtoolbase/pset.h b/dtool/src/dtoolbase/pset.h index cbb52fe3c9..99874f549e 100644 --- a/dtool/src/dtoolbase/pset.h +++ b/dtool/src/dtoolbase/pset.h @@ -24,7 +24,9 @@ #include -#ifdef UNKNOWN_ALLOCATOR +#ifdef NO_STYLE_ALLOCATOR +// If we're not using custom allocators, just use the standard class +// definition. #define pset set #define pmultiset multiset #else @@ -59,5 +61,5 @@ public: pmultiset(const Compare &comp) : multiset >(comp) { } }; -#endif +#endif // NO_STYLE_ALLOCATOR #endif diff --git a/dtool/src/dtoolbase/pvector.h b/dtool/src/dtoolbase/pvector.h index 8aa9412103..317c33c42e 100644 --- a/dtool/src/dtoolbase/pvector.h +++ b/dtool/src/dtoolbase/pvector.h @@ -24,8 +24,11 @@ #include "dtoolbase.h" #include "pallocator.h" -#ifdef UNKNOWN_ALLOCATOR +#ifdef NO_STYLE_ALLOCATOR +// If we're not using custom allocators, just use the standard class +// definition. #define pvector vector + #else //////////////////////////////////////////////////////////////////// @@ -45,6 +48,6 @@ public: pvector(const Type *begin, const Type *end) : vector >(begin, end) { } }; -#endif +#endif // NO_STYLE_ALLOCATOR #endif diff --git a/dtool/src/dtoolutil/Sources.pp b/dtool/src/dtoolutil/Sources.pp index 193d9b9736..5b269bad7f 100644 --- a/dtool/src/dtoolutil/Sources.pp +++ b/dtool/src/dtoolutil/Sources.pp @@ -11,7 +11,7 @@ vector_string.h gnu_getopt.c gnu_getopt.h gnu_getopt1.c \ pfstreamBuf.h vector_src.h - #define INCLUDED_SOURCES \ + #define INCLUDED_SOURCES \ executionEnvironment.cxx filename.cxx load_dso.cxx \ dSearchPath.cxx vector_string.cxx \ pfstreamBuf.cxx pfstream.cxx diff --git a/dtool/src/dtoolutil/vector_src.h b/dtool/src/dtoolutil/vector_src.h index 79c52c3650..9c1a39bf45 100644 --- a/dtool/src/dtoolutil/vector_src.h +++ b/dtool/src/dtoolutil/vector_src.h @@ -52,7 +52,7 @@ #ifdef HAVE_DINKUM // With the Dinkum library, we must first export the base class, // _Vector_val. - #define VV_BASE std::_Vector_val > + #define VV_BASE std::_Vector_val > #pragma warning (disable : 4231) EXPORT_TEMPLATE_CLASS(EXPCL, EXPTP, VV_BASE) #undef VV_BASE diff --git a/dtool/src/dtoolutil/vector_string.h b/dtool/src/dtoolutil/vector_string.h index ac1498aae1..50f99cd4a5 100644 --- a/dtool/src/dtoolutil/vector_string.h +++ b/dtool/src/dtoolutil/vector_string.h @@ -19,9 +19,7 @@ #ifndef VECTOR_STRING_H #define VECTOR_STRING_H -#include - -#include +#include "dtoolbase.h" //////////////////////////////////////////////////////////////////// // Class : vector_string