+/*
+ * 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
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:
#include "gc.h"
#ifndef THINK_CPLUS
-# define GC_cdecl
+# define GC_cdecl GC_CALLBACK
#else
# define GC_cdecl _cdecl
#endif
#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
#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};
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
inline void operator delete( void*, GCPlacement );
- /* called if construction fails. */
+ /* called if construction fails. */
inline void operator delete( void*, void* );
# endif
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. */
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
# 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 );
* 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 no way to redirect new in this environment without
- * including this everywhere.
+ * 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);
// 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 );
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 );}
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 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 );}
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() {
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 )
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,
+inline void operator delete (
+ void *p,
GCPlacement gcp,
GCCleanUpFunc cleanup,
void* clientData )
#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 )
#endif /* GC_OPERATOR_NEW_ARRAY */
-
#endif /* GC_CPP_H */
-