Browse Source

VC7 allocator support, and *_ALLOCATOR cleanup

David Rose 24 years ago
parent
commit
5146588a8d

+ 3 - 2
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

+ 3 - 2
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

+ 4 - 6
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

+ 8 - 1
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

+ 31 - 5
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
 

+ 4 - 9
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 

+ 2 - 3
dtool/src/dconfig/symbolEnt.h

@@ -22,8 +22,7 @@
 #include <dtoolbase.h>
 
 #include "config_setup.h"
-
-#include <vector>
+#include "pvector.h"
 
 namespace Config {
 
@@ -67,7 +66,7 @@ class EXPCL_DTOOLCONFIG SymbolEnt {
 
 namespace Config {
 
-typedef std::vector<SymbolEnt> vector_SymbolEnt;
+typedef ::vector_SymbolEnt vector_SymbolEnt;
 
 #include "symbolEnt.I"
 

+ 11 - 7
dtool/src/dtoolbase/dallocator.T

@@ -18,7 +18,6 @@
 
 #if defined(OLD_STYLE_ALLOCATOR)
 
-#ifndef NDEBUG
 template<class Type>
 INLINE Type *dallocator<Type>::
 allocate(size_t n) {
@@ -30,7 +29,6 @@ INLINE void dallocator<Type>::
 deallocate(void *p, size_t) {
   default_operator_delete(p);
 }
-#endif  // NDEBUG
 
 #elif defined(GNU_STYLE_ALLOCATOR)
 
@@ -45,7 +43,6 @@ INLINE dallocator<Type>::
 dallocator(const dallocator<_Tp1> &) {
 }
 
-#ifndef NDEBUG
 template<class Type>
 INLINE Type *dallocator<Type>::
 allocate(size_t n) {
@@ -57,11 +54,19 @@ INLINE void dallocator<Type>::
 deallocate(void *p, size_t) {
   default_operator_delete(p);
 }
-#endif  // NDEBUG
 
-#else  // *_STYLE_ALLOCATOR
+#elif MODERN_STYLE_ALLOCATOR
+
+template<class Type>
+INLINE dallocator<Type>::
+dallocator() {
+}
+
+template<class Type>
+INLINE dallocator<Type>::
+dallocator(const allocator<Type> &copy) {
+}
 
-#ifndef NDEBUG
 template<class Type>
 INLINE dallocator<Type>::pointer dallocator<Type>::
 allocate(dallocator<Type>::size_type n, allocator<void>::const_pointer) {
@@ -74,6 +79,5 @@ INLINE void dallocator<Type>::
 deallocate(void *p, allocator<Type>::size_type) {
   default_operator_delete(p);
 }
-#endif  // NDEBUG
 
 #endif  // *_STYLE_ALLOCATOR

+ 14 - 12
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 Type>
 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<class _Tp1>
   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 <class _Tp1> 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 Type>
 class dallocator : public allocator<Type> {
 public:
-#ifndef NDEBUG
+  INLINE dallocator();
+  INLINE dallocator(const allocator<Type> &copy);
   INLINE pointer allocate(size_type n, allocator<void>::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
 

+ 0 - 4
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

+ 21 - 7
dtool/src/dtoolbase/pallocator.T

@@ -18,7 +18,6 @@
 
 #if defined(OLD_STYLE_ALLOCATOR)
 
-#ifndef NDEBUG
 template<class Type>
 INLINE Type *pallocator<Type>::
 allocate(size_t n) {
@@ -30,7 +29,6 @@ INLINE void pallocator<Type>::
 deallocate(void *p, size_t) {
   (*global_operator_delete)(p);
 }
-#endif  // NDEBUG
 
 #elif defined(GNU_STYLE_ALLOCATOR)
 
@@ -45,7 +43,6 @@ INLINE pallocator<Type>::
 pallocator(const pallocator<_Tp1> &) {
 }
 
-#ifndef NDEBUG
 template<class Type>
 INLINE Type *pallocator<Type>::
 allocate(size_t n) {
@@ -57,11 +54,29 @@ INLINE void pallocator<Type>::
 deallocate(void *p, size_t) {
   (*global_operator_delete)(p);
 }
-#endif  // NDEBUG
 
-#else  // *_STYLE_ALLOCATOR
+#elif VC6_STYLE_ALLOCATOR
+
+template<class Type>
+INLINE pallocator<Type>::pointer pallocator<Type>::
+allocate(pallocator<Type>::size_type n, allocator<void>::const_pointer) {
+  return (pallocator<Type>::pointer)(*global_operator_new)(n * sizeof(Type));
+}
+
+template<class Type>
+INLINE void pallocator<Type>::
+//deallocate(pallocator<Type>::pointer p, allocator<Type>::size_type) {
+deallocate(void *p, allocator<Type>::size_type) {
+  (*global_operator_delete)(p);
+}
+
+#elif MODERN_STYLE_ALLOCATOR
+
+template<class Type>
+INLINE pallocator<Type>::
+pallocator() throw() {
+}
 
-#ifndef NDEBUG
 template<class Type>
 INLINE pallocator<Type>::pointer pallocator<Type>::
 allocate(pallocator<Type>::size_type n, allocator<void>::const_pointer) {
@@ -74,6 +89,5 @@ INLINE void pallocator<Type>::
 deallocate(void *p, allocator<Type>::size_type) {
   (*global_operator_delete)(p);
 }
-#endif  // NDEBUG
 
 #endif  // *_STYLE_ALLOCATOR

+ 30 - 12
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 Type>
 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<class _Tp1>
   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 <class _Tp1> 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 Type>
 class pallocator : public allocator<Type> {
 public:
-#ifndef NDEBUG
   INLINE pointer allocate(size_type n, allocator<void>::const_pointer hint = 0);
   INLINE void deallocate(void *p, size_type n);
-#endif  // NDEBUG
 };
+
+#elif defined(MODERN_STYLE_ALLOCATOR)
+
+// The final specification?
+template<class Type>
+class pallocator : public allocator<Type> {
+public:
+  INLINE pallocator() throw();
+
+  // template member functions in VC++ can only be defined in-class.
+  template<class U>
+  INLINE pallocator(const pallocator<U> &copy) throw() { }
+
+  INLINE pointer allocate(size_type n, allocator<void>::const_pointer hint = 0);
+  INLINE void deallocate(void *p, size_type n);
+
+  template<class U>
+  struct rebind { typedef pallocator<U> other; };
+};
+
+#else
+#error Unrecognized allocator symbol defined!
 #endif  // *_STYLE_ALLOCATOR
 
-#if !defined(UNKNOWN_ALLOCATOR)
+#ifndef NO_STYLE_ALLOCATOR
 #include "pallocator.T"
 #endif
 

+ 4 - 2
dtool/src/dtoolbase/pdeque.h

@@ -23,7 +23,9 @@
 #include "pallocator.h"
 #include <deque>
 
-#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<Type, pallocator<Type> >(n, value) { }
 };
 
-#endif
+#endif  // NO_STYLE_ALLOCATOR
 #endif

+ 4 - 2
dtool/src/dtoolbase/plist.h

@@ -23,7 +23,9 @@
 #include "pallocator.h"
 #include <list>
 
-#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<Type, pallocator<Type> >::const_reverse_iterator const_reverse_iterator;
 };
 
-#endif
+#endif  // NO_STYLE_ALLOCATOR
 #endif

+ 4 - 2
dtool/src/dtoolbase/pmap.h

@@ -24,7 +24,9 @@
 
 #include <map>
 
-#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<Key, Value, Compare, pallocator<Value> >(comp) { }
 };
 
-#endif
+#endif  // NO_STYLE_ALLOCATOR
 #endif

+ 4 - 2
dtool/src/dtoolbase/pset.h

@@ -24,7 +24,9 @@
 
 #include <set>
 
-#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<Key, Compare, pallocator<Key> >(comp) { }
 };
 
-#endif
+#endif  // NO_STYLE_ALLOCATOR
 #endif

+ 5 - 2
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<Type, pallocator<Type> >(begin, end) { }
 };
 
-#endif
+#endif  // NO_STYLE_ALLOCATOR
 #endif
 

+ 1 - 1
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 

+ 1 - 1
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<TYPE, std::allocator<TYPE> >
+    #define VV_BASE std::_Vector_val<TYPE, pallocator<TYPE> >
 #pragma warning (disable : 4231)
 EXPORT_TEMPLATE_CLASS(EXPCL, EXPTP, VV_BASE)
     #undef VV_BASE

+ 1 - 3
dtool/src/dtoolutil/vector_string.h

@@ -19,9 +19,7 @@
 #ifndef VECTOR_STRING_H
 #define VECTOR_STRING_H
 
-#include <dtoolbase.h>
-
-#include <vector>
+#include "dtoolbase.h"
 
 ////////////////////////////////////////////////////////////////////
 //       Class : vector_string