From f5e92eec6c32889cfdc650b8385e29f8ba49f88e Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 14 Sep 2001 16:53:18 +0000 Subject: [PATCH] more fixes for new Linux gcc --- dtool/src/dtoolbase/dallocator.T | 37 ++++++++++++++++++++++++++----- dtool/src/dtoolbase/dallocator.h | 38 ++++++++++++++++++++++++++------ dtool/src/dtoolbase/pallocator.T | 13 ++++++++++- dtool/src/dtoolbase/pallocator.h | 12 ++++------ 4 files changed, 79 insertions(+), 21 deletions(-) diff --git a/dtool/src/dtoolbase/dallocator.T b/dtool/src/dtoolbase/dallocator.T index 7164445a92..d945b96f4b 100644 --- a/dtool/src/dtoolbase/dallocator.T +++ b/dtool/src/dtoolbase/dallocator.T @@ -16,13 +16,13 @@ // //////////////////////////////////////////////////////////////////// -#ifdef OLD_STYLE_ALLOCATOR +#if defined(OLD_STYLE_ALLOCATOR) #ifndef NDEBUG template -INLINE void *dallocator:: +INLINE Type *dallocator:: allocate(size_t n) { - return default_operator_new(n); + return (Type *)default_operator_new(n); } template @@ -32,7 +32,34 @@ deallocate(void *p, size_t) { } #endif // NDEBUG -#else // OLD_STYLE_ALLOCATOR +#elif defined(GNU_STYLE_ALLOCATOR) + +template +INLINE dallocator:: +dallocator() { +} + +template +template +INLINE dallocator:: +dallocator(const dallocator<_Tp1> &) { +} + +#ifndef NDEBUG +template +INLINE Type *dallocator:: +allocate(size_t n) { + return (Type *)default_operator_new(n * sizeof(Type)); +} + +template +INLINE void dallocator:: +deallocate(void *p, size_t) { + default_operator_delete(p); +} +#endif // NDEBUG + +#else // *_STYLE_ALLOCATOR #ifndef NDEBUG template @@ -49,4 +76,4 @@ deallocate(void *p, allocator::size_type) { } #endif // NDEBUG -#endif // OLD_STYLE_ALLOCATOR +#endif // *_STYLE_ALLOCATOR diff --git a/dtool/src/dtoolbase/dallocator.h b/dtool/src/dtoolbase/dallocator.h index 8310fd42a5..faef10b27c 100644 --- a/dtool/src/dtoolbase/dallocator.h +++ b/dtool/src/dtoolbase/dallocator.h @@ -36,21 +36,45 @@ // within the MemoryUsage class itself. //////////////////////////////////////////////////////////////////// -#ifdef OLD_STYLE_ALLOCATOR -// Early versions of gcc used its own kind of allocator, somewhat -// different from the STL standard. +#if defined(OLD_STYLE_ALLOCATOR) +// Early versions of gcc wanted to use its 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 - static void *allocate(size_t n); - static void deallocate(void *p, size_t n); + INLINE static Type *allocate(size_t n); + INLINE static void deallocate(void *p, size_t n); #endif // NDEBUG }; -#else // OLD_STYLE_ALLOCATOR +#elif defined(GNU_STYLE_ALLOCATOR) +// Later versions of gcc want to use a still different, nonstandard +// definition. Sheesh. +template +class dallocator : public allocator { +public: + INLINE dallocator(); + 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 + +// This is the correct allocator declaration as the current C++ +// standard defines it. template class dallocator : public allocator { public: @@ -60,7 +84,7 @@ public: INLINE void deallocate(void *p, size_type n); #endif // NDEBUG }; -#endif // OLD_STYLE_ALLOCATOR +#endif // *_STYLE_ALLOCATOR #include "dallocator.T" diff --git a/dtool/src/dtoolbase/pallocator.T b/dtool/src/dtoolbase/pallocator.T index 47489202ad..bbb351f0e3 100644 --- a/dtool/src/dtoolbase/pallocator.T +++ b/dtool/src/dtoolbase/pallocator.T @@ -34,11 +34,22 @@ deallocate(void *p, size_t) { #elif defined(GNU_STYLE_ALLOCATOR) +template +INLINE pallocator:: +pallocator() { +} + +template +template +INLINE pallocator:: +pallocator(const pallocator<_Tp1> &) { +} + #ifndef NDEBUG template INLINE Type *pallocator:: allocate(size_t n) { - return (Type *)(*global_operator_new)(n); + return (Type *)(*global_operator_new)(n * sizeof(Type)); } template diff --git a/dtool/src/dtoolbase/pallocator.h b/dtool/src/dtoolbase/pallocator.h index e877bca56c..d2c4c347b6 100644 --- a/dtool/src/dtoolbase/pallocator.h +++ b/dtool/src/dtoolbase/pallocator.h @@ -55,6 +55,10 @@ public: template class pallocator : public allocator { public: + INLINE pallocator(); + template + INLINE pallocator(const pallocator<_Tp1> &other); + #ifndef NDEBUG INLINE Type *allocate(size_t n); INLINE void deallocate(void *p, size_t n); @@ -77,14 +81,6 @@ public: // INLINE void deallocate(pointer p, size_type n); INLINE void deallocate(void *p, size_type n); #endif // NDEBUG - -#ifdef __GNUC__ - // Some versions of the gcc library require this structure to be - // declared. I don't know what it's all about. - template struct rebind { - typedef pallocator<_Tp1> other; - }; -#endif }; #endif // *_STYLE_ALLOCATOR