Przeglądaj źródła

build on gcc 4.0.0

David Rose 20 lat temu
rodzic
commit
15f654b7de

+ 1 - 2
dtool/src/dtoolbase/dallocator.T

@@ -70,8 +70,7 @@ allocate(TYPENAME dallocator<Type>::size_type n, allocator<void>::const_pointer)
 
 template<class Type>
 INLINE void dallocator<Type>::
-//deallocate(dallocator<Type>::pointer p, allocator<Type>::size_type) {
-deallocate(void *p, allocator<Type>::size_type) {
+deallocate(TYPENAME pallocator<Type>::pointer p, TYPENAME pallocator<Type>::size_type) {
   (*global_operator_delete)(p);
 }
 

+ 11 - 1
dtool/src/dtoolbase/dallocator.h

@@ -84,6 +84,7 @@ public:
   typedef TYPENAME allocator<Type>::reference reference;
   typedef TYPENAME allocator<Type>::const_pointer const_pointer;
   typedef TYPENAME allocator<Type>::const_reference const_reference;
+  typedef TYPENAME allocator<Type>::size_type size_type;
 
   INLINE dallocator() throw();
 
@@ -92,7 +93,16 @@ public:
   INLINE dallocator(const dallocator<U> &copy) throw() { }
 
   INLINE pointer allocate(size_type n, allocator<void>::const_pointer hint = 0);
-  INLINE void deallocate(void *p, size_type n);
+  INLINE void deallocate(pointer p, size_type n);
+
+  template<class Subtype>
+  INLINE void destroy(Subtype *p) {
+    p->~Subtype();
+  }
+  template<class Subtype>
+  INLINE void construct(Subtype *p, const Subtype &value) {
+    ::new(p) Subtype(value);
+  }
 
   template<class U> struct rebind { 
     typedef dallocator<U> other; 

+ 1 - 2
dtool/src/dtoolbase/pallocator.T

@@ -85,8 +85,7 @@ allocate(TYPENAME pallocator<Type>::size_type n, TYPENAME allocator<void>::const
 
 template<class Type>
 INLINE void pallocator<Type>::
-//deallocate(pallocator<Type>::pointer p, allocator<Type>::size_type) {
-deallocate(void *p, allocator<Type>::size_type) {
+deallocate(TYPENAME pallocator<Type>::pointer p, TYPENAME pallocator<Type>::size_type) {
   (*global_operator_delete)(p);
 }
 

+ 15 - 3
dtool/src/dtoolbase/pallocator.h

@@ -87,12 +87,13 @@ public:
 template<class Type>
 class pallocator : public allocator<Type> {
 public:
-  // There seems to be a bug in VC++ 2003 that requires these typedefs
-  // to be made explicitly.
+  // Nowadays we cannot implicitly inherit typedefs from base classes
+  // in a template class; we must explicitly copy them here.
   typedef TYPENAME allocator<Type>::pointer pointer;
   typedef TYPENAME allocator<Type>::reference reference;
   typedef TYPENAME allocator<Type>::const_pointer const_pointer;
   typedef TYPENAME allocator<Type>::const_reference const_reference;
+  typedef TYPENAME allocator<Type>::size_type size_type;
 
   INLINE pallocator() throw();
 
@@ -101,7 +102,18 @@ public:
   INLINE pallocator(const pallocator<U> &) throw() { }
 
   INLINE pointer allocate(size_type n, allocator<void>::const_pointer hint = 0);
-  INLINE void deallocate(void *p, size_type n);
+  INLINE void deallocate(pointer p, size_type n);
+
+  // The gcc 4.0 version seems to pass any old type to construct() and
+  // destroy(), so we need template methods.
+  template<class Subtype>
+  INLINE void destroy(Subtype *p) {
+    p->~Subtype();
+  }
+  template<class Subtype>
+  INLINE void construct(Subtype *p, const Subtype &value) {
+    ::new(p) Subtype(value);
+  }
 
   template<class U> struct rebind { 
     typedef pallocator<U> other;