Upgrade Boehm GC to 7.2alpha4.
[cacao.git] / src / mm / boehm-gc / include / gc_cpp.h
index d3df21121038b4b6e66000f49a475d98ab2c67ea..a1eabe3df56906eb28ec8f6735bc73355798337d 100644 (file)
@@ -1,21 +1,23 @@
+/*
+ * Copyright (c) 1994 by Xerox Corporation.  All rights reserved.
+ *
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
+ * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
+ *
+ * Permission is hereby granted to use or copy this program for any
+ * purpose, provided the above notices are retained on all copies.
+ * Permission to modify the code and to distribute modified code is
+ * granted, provided the above notices are retained, and a notice that
+ * the code was modified is included with the above copyright notice.
+ */
+
 #ifndef GC_CPP_H
 #define GC_CPP_H
-/****************************************************************************
-Copyright (c) 1994 by Xerox Corporation.  All rights reserved.
-THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
-OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
-Permission is hereby granted to use or copy this program for any
-purpose, provided the above notices are retained on all copies.
-Permission to modify the code and to distribute modified code is
-granted, provided the above notices are retained, and a notice that
-the code was modified is included with the above copyright notice.
-****************************************************************************
 
+/****************************************************************************
 C++ Interface to the Boehm Collector
 
-    John R. Ellis and Jesse Hull 
+    John R. Ellis and Jesse Hull
 
 This interface provides access to the Boehm collector.  It provides
 basic facilities similar to those described in "Safe, Efficient
@@ -34,7 +36,7 @@ Objects allocated with the built-in "::operator new" are uncollectable.
 Objects derived from class "gc" are collectable.  For example:
 
     class A: public gc {...};
-    A* a = new A;       // a is collectable. 
+    A* a = new A;       // a is collectable.
 
 Collectable instances of non-class types can be allocated using the GC
 (or UseGC) placement:
@@ -141,7 +143,7 @@ by UseGC.  GC is an alias for UseGC, unless GC_NAME_CONFLICT is defined.
 #include "gc.h"
 
 #ifndef THINK_CPLUS
-#  define GC_cdecl
+#  define GC_cdecl GC_CALLBACK
 #else
 #  define GC_cdecl _cdecl
 #endif
@@ -149,9 +151,9 @@ by UseGC.  GC is an alias for UseGC, unless GC_NAME_CONFLICT is defined.
 #if ! defined( GC_NO_OPERATOR_NEW_ARRAY ) \
     && !defined(_ENABLE_ARRAYNEW) /* Digimars */ \
     && (defined(__BORLANDC__) && (__BORLANDC__ < 0x450) \
-       || (defined(__GNUC__) && \
-           (__GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 6)) \
-       || (defined(__WATCOMC__) && __WATCOMC__ < 1050))
+        || (defined(__GNUC__) && \
+            (__GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 6)) \
+        || (defined(__WATCOMC__) && __WATCOMC__ < 1050))
 #   define GC_NO_OPERATOR_NEW_ARRAY
 #endif
 
@@ -160,13 +162,14 @@ by UseGC.  GC is an alias for UseGC, unless GC_NAME_CONFLICT is defined.
 #endif
 
 #if    ! defined ( __BORLANDC__ )  /* Confuses the Borland compiler. */ \
-    && ! defined ( __sgi )
+    && ! defined ( __sgi ) && ! defined( __WATCOMC__ ) \
+    && (!defined(_MSC_VER) || _MSC_VER > 1020)
 #  define GC_PLACEMENT_DELETE
 #endif
 
 enum GCPlacement {UseGC,
 #ifndef GC_NAME_CONFLICT
-                 GC=UseGC,
+                  GC=UseGC,
 #endif
                   NoGC, PointerFreeGC};
 
@@ -174,10 +177,12 @@ class gc {public:
     inline void* operator new( size_t size );
     inline void* operator new( size_t size, GCPlacement gcp );
     inline void* operator new( size_t size, void *p );
-       /* Must be redefined here, since the other overloadings */
-       /* hide the global definition.                          */
+        /* Must be redefined here, since the other overloadings */
+        /* hide the global definition.                          */
     inline void operator delete( void* obj );
-#   ifdef GC_PLACEMENT_DELETE  
+#   ifdef GC_PLACEMENT_DELETE
+      inline void operator delete( void*, GCPlacement );
+        /* called if construction fails.        */
       inline void operator delete( void*, void* );
 #   endif
 
@@ -187,12 +192,13 @@ class gc {public:
     inline void* operator new[]( size_t size, void *p );
     inline void operator delete[]( void* obj );
 #   ifdef GC_PLACEMENT_DELETE
+      inline void operator delete[]( void*, GCPlacement );
       inline void operator delete[]( void*, void* );
 #   endif
 #endif /* GC_OPERATOR_NEW_ARRAY */
-    };    
+    };
     /*
-    Instances of classes derived from "gc" will be allocated in the 
+    Instances of classes derived from "gc" will be allocated in the
     collected heap by default, unless an explicit NoGC placement is
     specified. */
 
@@ -208,7 +214,9 @@ private:
     member derived from "gc_cleanup", its destructors will be
     invoked. */
 
-extern "C" {typedef void (*GCCleanUpFunc)( void* obj, void* clientData );}
+extern "C" {
+    typedef void (GC_CALLBACK * GCCleanUpFunc)( void* obj, void* clientData );
+}
 
 #ifdef _MSC_VER
   // Disable warning that "no matching operator delete found; memory will
@@ -216,8 +224,8 @@ extern "C" {typedef void (*GCCleanUpFunc)( void* obj, void* clientData );}
 # pragma warning(disable:4291)
 #endif
 
-inline void* operator new( 
-    size_t size, 
+inline void* operator new(
+    size_t size,
     GCPlacement gcp,
     GCCleanUpFunc cleanup = 0,
     void* clientData = 0 );
@@ -235,17 +243,22 @@ inline void* operator new(
     classes derived from "gc_cleanup" or containing members derived
     from "gc_cleanup". */
 
+#   ifdef GC_PLACEMENT_DELETE
+      inline void operator delete( void*, GCPlacement, GCCleanUpFunc, void * );
+#   endif
 
 #ifdef _MSC_VER
  /** This ensures that the system default operator new[] doesn't get
   *  undefined, which is what seems to happen on VC++ 6 for some reason
   *  if we define a multi-argument operator new[].
-  *  There seems to be really redirect new in this environment without
-  *  including this everywhere. 
+  *  There seems to be no way to redirect new in this environment without
+  *  including this everywhere.
   */
+#if _MSC_VER > 1020
  void *operator new[]( size_t size );
+
  void operator delete[](void* obj);
+#endif
 
  void* operator new( size_t size);
 
@@ -253,16 +266,16 @@ inline void* operator new(
 
  // This new operator is used by VC++ in case of Debug builds !
  void* operator new(  size_t size,
-                     int ,//nBlockUse,
-                     const char * szFileName,
-                     int nLine );
+                      int ,//nBlockUse,
+                      const char * szFileName,
+                      int nLine );
 #endif /* _MSC_VER */
 
 
 #ifdef GC_OPERATOR_NEW_ARRAY
 
 inline void* operator new[](
-    size_t size, 
+    size_t size,
     GCPlacement gcp,
     GCCleanUpFunc cleanup = 0,
     void* clientData = 0 );
@@ -279,12 +292,12 @@ Inline implementation
 
 inline void* gc::operator new( size_t size ) {
     return GC_MALLOC( size );}
-    
+
 inline void* gc::operator new( size_t size, GCPlacement gcp ) {
-    if (gcp == UseGC) 
+    if (gcp == UseGC)
         return GC_MALLOC( size );
     else if (gcp == PointerFreeGC)
-       return GC_MALLOC_ATOMIC( size );
+        return GC_MALLOC_ATOMIC( size );
     else
         return GC_MALLOC_UNCOLLECTABLE( size );}
 
@@ -293,16 +306,20 @@ inline void* gc::operator new( size_t size, void *p ) {
 
 inline void gc::operator delete( void* obj ) {
     GC_FREE( obj );}
-    
+
 #ifdef GC_PLACEMENT_DELETE
   inline void gc::operator delete( void*, void* ) {}
+
+  inline void gc::operator delete( void* p, GCPlacement gcp ) {
+    GC_FREE(p);
+  }
 #endif
 
 #ifdef GC_OPERATOR_NEW_ARRAY
 
 inline void* gc::operator new[]( size_t size ) {
     return gc::operator new( size );}
-    
+
 inline void* gc::operator new[]( size_t size, GCPlacement gcp ) {
     return gc::operator new( size, gcp );}
 
@@ -314,15 +331,19 @@ inline void gc::operator delete[]( void* obj ) {
 
 #ifdef GC_PLACEMENT_DELETE
   inline void gc::operator delete[]( void*, void* ) {}
+
+  inline void gc::operator delete[]( void* p, GCPlacement gcp ) {
+    gc::operator delete(p); }
+
 #endif
-    
+
 #endif /* GC_OPERATOR_NEW_ARRAY */
 
 
 inline gc_cleanup::~gc_cleanup() {
     GC_register_finalizer_ignore_self( GC_base(this), 0, 0, 0, 0 );}
 
-inline void gc_cleanup::cleanup( void* obj, void* displ ) {
+inline void GC_CALLBACK gc_cleanup::cleanup( void* obj, void* displ ) {
     ((gc_cleanup*) ((char*) obj + (ptrdiff_t) displ))->~gc_cleanup();}
 
 inline gc_cleanup::gc_cleanup() {
@@ -331,14 +352,14 @@ inline gc_cleanup::gc_cleanup() {
     void* base = GC_base( (void *) this );
     if (0 != base)  {
       // Don't call the debug version, since this is a real base address.
-      GC_register_finalizer_ignore_self( 
-        base, (GC_finalization_proc)cleanup, (void*) ((char*) this - (char*) base), 
+      GC_register_finalizer_ignore_self(
+        base, (GC_finalization_proc)cleanup, (void*) ((char*) this - (char*) base),
         &oldProc, &oldData );
       if (0 != oldProc) {
         GC_register_finalizer_ignore_self( base, oldProc, oldData, 0, 0 );}}}
 
-inline void* operator new( 
-    size_t size, 
+inline void* operator new(
+    size_t size,
     GCPlacement gcp,
     GCCleanUpFunc cleanup,
     void* clientData )
@@ -347,20 +368,30 @@ inline void* operator new(
 
     if (gcp == UseGC) {
         obj = GC_MALLOC( size );
-        if (cleanup != 0) 
-            GC_REGISTER_FINALIZER_IGNORE_SELF( 
+        if (cleanup != 0)
+            GC_REGISTER_FINALIZER_IGNORE_SELF(
                 obj, cleanup, clientData, 0, 0 );}
     else if (gcp == PointerFreeGC) {
         obj = GC_MALLOC_ATOMIC( size );}
     else {
         obj = GC_MALLOC_UNCOLLECTABLE( size );};
     return obj;}
-        
+
+# ifdef GC_PLACEMENT_DELETE
+inline void operator delete (
+    void *p,
+    GCPlacement gcp,
+    GCCleanUpFunc cleanup,
+    void* clientData )
+{
+    GC_FREE(p);
+}
+# endif
 
 #ifdef GC_OPERATOR_NEW_ARRAY
 
-inline void* operator new[]( 
-    size_t size, 
+inline void* operator new[](
+    size_t size,
     GCPlacement gcp,
     GCCleanUpFunc cleanup,
     void* clientData )
@@ -369,6 +400,4 @@ inline void* operator new[](
 
 #endif /* GC_OPERATOR_NEW_ARRAY */
 
-
 #endif /* GC_CPP_H */
-