diff --git a/dtool/Config.Linux.pp b/dtool/Config.Linux.pp index 5ff746151b..344449bbb6 100644 --- a/dtool/Config.Linux.pp +++ b/dtool/Config.Linux.pp @@ -97,5 +97,5 @@ // Must global operator new and delete functions throw exceptions? #define GLOBAL_OPERATOR_NEW_EXCEPTIONS 1 -// Do we expect the old STL allocator? -#define OLD_STYLE_ALLOCATOR 1 +// What style STL allocator should we declare? +#define GNU_STYLE_ALLOCATOR 1 diff --git a/dtool/LocalSetup.pp b/dtool/LocalSetup.pp index bb9f621c13..15b45b5a7c 100644 --- a/dtool/LocalSetup.pp +++ b/dtool/LocalSetup.pp @@ -190,8 +190,9 @@ $[cdefine HAVE_RTTI] /* Must global operator new and delete functions throw exceptions? */ $[cdefine GLOBAL_OPERATOR_NEW_EXCEPTIONS] -/* Do we expect the old style STL allocator? */ +/* What style STL allocator should we declare? */ $[cdefine OLD_STYLE_ALLOCATOR] +$[cdefine GNU_STYLE_ALLOCATOR] #end dtool_config.h diff --git a/dtool/src/dtoolbase/pallocator.T b/dtool/src/dtoolbase/pallocator.T index fb38e34686..47489202ad 100644 --- a/dtool/src/dtoolbase/pallocator.T +++ b/dtool/src/dtoolbase/pallocator.T @@ -16,13 +16,13 @@ // //////////////////////////////////////////////////////////////////// -#ifdef OLD_STYLE_ALLOCATOR +#if defined(OLD_STYLE_ALLOCATOR) #ifndef NDEBUG template -INLINE void *pallocator:: +INLINE Type *pallocator:: allocate(size_t n) { - return (*global_operator_new)(n); + return (Type *)(*global_operator_new)(n); } template @@ -32,7 +32,23 @@ deallocate(void *p, size_t) { } #endif // NDEBUG -#else // OLD_STYLE_ALLOCATOR +#elif defined(GNU_STYLE_ALLOCATOR) + +#ifndef NDEBUG +template +INLINE Type *pallocator:: +allocate(size_t n) { + return (Type *)(*global_operator_new)(n); +} + +template +INLINE void pallocator:: +deallocate(void *p, size_t) { + (*global_operator_delete)(p); +} +#endif // NDEBUG + +#else // *_STYLE_ALLOCATOR #ifndef NDEBUG template @@ -49,4 +65,4 @@ deallocate(void *p, allocator::size_type) { } #endif // NDEBUG -#endif // OLD_STYLE_ALLOCATOR +#endif // *_STYLE_ALLOCATOR diff --git a/dtool/src/dtoolbase/pallocator.h b/dtool/src/dtoolbase/pallocator.h index 7f0356d7d4..e877bca56c 100644 --- a/dtool/src/dtoolbase/pallocator.h +++ b/dtool/src/dtoolbase/pallocator.h @@ -34,21 +34,41 @@ // to use a pallocator. //////////////////////////////////////////////////////////////////// -#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 pallocator : 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 pallocator : public allocator { +public: +#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 + +// This is the correct allocator declaration as the current C++ +// standard defines it. template class pallocator : public allocator { public: @@ -57,8 +77,16 @@ 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 // OLD_STYLE_ALLOCATOR +#endif // *_STYLE_ALLOCATOR #include "pallocator.T"