OSDN Git Service

2004-11-26 Bryce McKinlay <mckinlay@redhat.com>
[pf3gnuchains/gcc-fork.git] / boehm-gc / include / new_gc_alloc.h
index 5771388..f2219b7 100644 (file)
@@ -20,9 +20,9 @@
 // It also doesn't yet understand the new header file names or
 // namespaces.
 //
-// This assumes the collector has been compiled with -DATOMIC_UNCOLLECTABLE
-// and -DALL_INTERIOR_POINTERS.  We also recommend
-// -DREDIRECT_MALLOC=GC_uncollectable_malloc.
+// This assumes the collector has been compiled with -DATOMIC_UNCOLLECTABLE.
+// The user should also consider -DREDIRECT_MALLOC=GC_uncollectable_malloc,
+// to ensure that object allocated through malloc are traced.
 //
 // Some of this could be faster in the explicit deallocation case.
 // In particular, we spend too much time clearing objects on the
 // problems.  The argument for changing it is that the usual default
 // allocator is usually a very bad choice for a garbage collected environment.)
 //
+// This code assumes that the collector itself has been compiled with a
+// compiler that defines __STDC__ .
+//
 
 #ifndef GC_ALLOC_H
 
 #include "gc.h"
-#include <alloc.h>
+
+#if (__GNUC__ < 3)
+# include <stack>  // A more portable way to get stl_alloc.h .
+#else
+# include <bits/stl_alloc.h>
+# ifndef __STL_BEGIN_NAMESPACE
+# define __STL_BEGIN_NAMESPACE namespace std {
+# define __STL_END_NAMESPACE };
+# endif
+#ifndef __STL_USE_STD_ALLOCATORS
+#define __STL_USE_STD_ALLOCATORS
+#endif
+#endif
+
+/* A hack to deal with gcc 3.1.  If you are using gcc3.1 and later,    */
+/* you should probably really use gc_allocator.h instead.              */
+#if defined (__GNUC__) && \
+    (__GNUC > 3 || (__GNUC__ == 3 && (__GNUC_MINOR__ >= 1)))
+# define simple_alloc __simple_alloc
+#endif
+
+
 
 #define GC_ALLOC_H
 
@@ -318,12 +342,10 @@ class traceable_alloc_template {
 
 typedef traceable_alloc_template < 0 > traceable_alloc;
 
-#ifdef _SGI_SOURCE
-
 // We want to specialize simple_alloc so that it does the right thing
 // for all pointerfree types.  At the moment there is no portable way to
 // even approximate that.  The following approximation should work for
-// SGI compilers, and perhaps some others.
+// SGI compilers, and recent versions of g++.
 
 # define __GC_SPECIALIZE(T,alloc) \
 class simple_alloc<T, alloc> { \
@@ -339,6 +361,8 @@ public: \
        { alloc::ptr_free_deallocate(p, sizeof (T)); } \
 };
 
+__STL_BEGIN_NAMESPACE
+
 __GC_SPECIALIZE(char, gc_alloc)
 __GC_SPECIALIZE(int, gc_alloc)
 __GC_SPECIALIZE(unsigned, gc_alloc)
@@ -363,16 +387,18 @@ __GC_SPECIALIZE(unsigned, single_client_traceable_alloc)
 __GC_SPECIALIZE(float, single_client_traceable_alloc)
 __GC_SPECIALIZE(double, single_client_traceable_alloc)
 
+__STL_END_NAMESPACE
+
 #ifdef __STL_USE_STD_ALLOCATORS
 
 __STL_BEGIN_NAMESPACE
 
-template <class _T>
-struct _Alloc_traits<_T, gc_alloc >
+template <class _Tp>
+struct _Alloc_traits<_Tp, gc_alloc >
 {
   static const bool _S_instanceless = true;
-  typedef simple_alloc<_T, gc_alloc > _Alloc_type;
-  typedef __allocator<_T, gc_alloc > allocator_type;
+  typedef simple_alloc<_Tp, gc_alloc > _Alloc_type;
+  typedef __allocator<_Tp, gc_alloc > allocator_type;
 };
 
 inline bool operator==(const gc_alloc&,
@@ -387,12 +413,12 @@ inline bool operator!=(const gc_alloc&,
   return false;
 }
 
-template <class _T>
-struct _Alloc_traits<_T, single_client_gc_alloc >
+template <class _Tp>
+struct _Alloc_traits<_Tp, single_client_gc_alloc >
 {
   static const bool _S_instanceless = true;
-  typedef simple_alloc<_T, single_client_gc_alloc > _Alloc_type;
-  typedef __allocator<_T, single_client_gc_alloc > allocator_type;
+  typedef simple_alloc<_Tp, single_client_gc_alloc > _Alloc_type;
+  typedef __allocator<_Tp, single_client_gc_alloc > allocator_type;
 };
 
 inline bool operator==(const single_client_gc_alloc&,
@@ -407,12 +433,12 @@ inline bool operator!=(const single_client_gc_alloc&,
   return false;
 }
 
-template <class _T>
-struct _Alloc_traits<_T, traceable_alloc >
+template <class _Tp>
+struct _Alloc_traits<_Tp, traceable_alloc >
 {
   static const bool _S_instanceless = true;
-  typedef simple_alloc<_T, traceable_alloc > _Alloc_type;
-  typedef __allocator<_T, traceable_alloc > allocator_type;
+  typedef simple_alloc<_Tp, traceable_alloc > _Alloc_type;
+  typedef __allocator<_Tp, traceable_alloc > allocator_type;
 };
 
 inline bool operator==(const traceable_alloc&,
@@ -427,12 +453,12 @@ inline bool operator!=(const traceable_alloc&,
   return false;
 }
 
-template <class _T>
-struct _Alloc_traits<_T, single_client_traceable_alloc >
+template <class _Tp>
+struct _Alloc_traits<_Tp, single_client_traceable_alloc >
 {
   static const bool _S_instanceless = true;
-  typedef simple_alloc<_T, single_client_traceable_alloc > _Alloc_type;
-  typedef __allocator<_T, single_client_traceable_alloc > allocator_type;
+  typedef simple_alloc<_Tp, single_client_traceable_alloc > _Alloc_type;
+  typedef __allocator<_Tp, single_client_traceable_alloc > allocator_type;
 };
 
 inline bool operator==(const single_client_traceable_alloc&,
@@ -451,6 +477,4 @@ __STL_END_NAMESPACE
 
 #endif /* __STL_USE_STD_ALLOCATORS */
 
-#endif /* _SGI_SOURCE */
-
 #endif /* GC_ALLOC_H */