summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2023-04-14 09:42:28 +0300
committerIvan Maidanski <ivmai@mail.ru>2023-04-17 12:05:54 +0300
commit08eb0da6f5dbc9de1c0bf6e2ad7a7dedb24ac551 (patch)
tree0959a07b12aea8f30cf38911ddb710eb68787bed /include
parentd1bc109ec4d548a6977060affe0012b1643bedf5 (diff)
downloadbdwgc-08eb0da6f5dbc9de1c0bf6e2ad7a7dedb24ac551.tar.gz
Prefix size_t and ptrdiff_t with namespace 'std' in C++ files
Note: this affects gc_cpp.h only if GC_INCLUDE_NEW is defined (i.e. "new" header is included). * gc_cpp.cc (operator new, operator delete): Use std::size_t instead of size_t. * include/gc/gc_allocator.h (GC_selective_alloc, gc_allocator.size_type, gc_allocator.max_size, gc_allocator_ignore_off_page.size_type, gc_allocator_ignore_off_page.max_size, traceable_allocator.size_type, traceable_allocator.max_size): Likewise. * gc_cpp.cc (operator delete): Remove name of unused argument (and cast to void). * include/gc/gc_cpp.h (operator new, operator delete): Likewise. * gc_cpp.cc: Reformat code. * include/gc/gc_cpp.h: Likewise. * include/gc/gc_allocator.h (gc_allocator.difference_type, gc_allocator_ignore_off_page.difference_type, traceable_allocator.difference_type): Use std::ptrdiff_t instead of ptrdiff_t. * include/gc/gc_cpp.h (GC_PTRDIFF_T, GC_SIZE_T): New macro (depending on GC_INCLUDE_NEW). * include/gc/gc_cpp.h (operator new, operator delete): Use GC_SIZE_T instead of size_t. * include/gc/gc_cpp.h (gc_cleanup): Reformat comments. * include/gc/gc_cpp.h (gc_cleanup::cleanup): Use GC_PTRDIFF_T instead of ptrdiff_t. * include/gc/gc_cpp.h [!GC_NO_INLINE_STD_NEW && _MSC_VER] (operator new): Remove duplicate code.
Diffstat (limited to 'include')
-rw-r--r--include/gc/gc_allocator.h34
-rw-r--r--include/gc/gc_cpp.h217
2 files changed, 123 insertions, 128 deletions
diff --git a/include/gc/gc_allocator.h b/include/gc/gc_allocator.h
index 89152f90..5787d170 100644
--- a/include/gc/gc_allocator.h
+++ b/include/gc/gc_allocator.h
@@ -92,7 +92,7 @@ GC_DECLARE_PTRFREE(long double);
// In the following GC_Tp is GC_true_type if we are allocating a pointer-free
// object.
template <class GC_Tp>
-inline void * GC_selective_alloc(size_t n, GC_Tp, bool ignore_off_page) {
+inline void * GC_selective_alloc(std::size_t n, GC_Tp, bool ignore_off_page) {
void *obj = ignore_off_page ? GC_MALLOC_IGNORE_OFF_PAGE(n) : GC_MALLOC(n);
if (0 == obj)
GC_ALLOCATOR_THROW_OR_ABORT();
@@ -102,7 +102,7 @@ inline void * GC_selective_alloc(size_t n, GC_Tp, bool ignore_off_page) {
#if !defined(__WATCOMC__)
// Note: template-id not supported in this context by Watcom compiler.
template <>
- inline void * GC_selective_alloc<GC_true_type>(size_t n, GC_true_type,
+ inline void * GC_selective_alloc<GC_true_type>(std::size_t n, GC_true_type,
bool ignore_off_page) {
void *obj = ignore_off_page ? GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(n)
: GC_MALLOC_ATOMIC(n);
@@ -116,8 +116,8 @@ inline void * GC_selective_alloc(size_t n, GC_Tp, bool ignore_off_page) {
template <class GC_Tp>
class gc_allocator {
public:
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
typedef GC_Tp* pointer;
typedef const GC_Tp* const_pointer;
typedef GC_Tp& reference;
@@ -152,7 +152,7 @@ public:
{ GC_FREE(__p); }
size_type max_size() const GC_NOEXCEPT
- { return static_cast<size_t>(-1) / sizeof(GC_Tp); }
+ { return static_cast<std::size_t>(-1) / sizeof(GC_Tp); }
void construct(pointer __p, const GC_Tp& __val) { new(__p) GC_Tp(__val); }
void destroy(pointer __p) { __p->~GC_Tp(); }
@@ -160,8 +160,8 @@ public:
template<>
class gc_allocator<void> {
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
@@ -189,8 +189,8 @@ inline bool operator!=(const gc_allocator<GC_T1>&,
template <class GC_Tp>
class gc_allocator_ignore_off_page {
public:
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
typedef GC_Tp* pointer;
typedef const GC_Tp* const_pointer;
typedef GC_Tp& reference;
@@ -227,7 +227,7 @@ public:
{ GC_FREE(__p); }
size_type max_size() const GC_NOEXCEPT
- { return static_cast<size_t>(-1) / sizeof(GC_Tp); }
+ { return static_cast<std::size_t>(-1) / sizeof(GC_Tp); }
void construct(pointer __p, const GC_Tp& __val) { new(__p) GC_Tp(__val); }
void destroy(pointer __p) { __p->~GC_Tp(); }
@@ -235,8 +235,8 @@ public:
template<>
class gc_allocator_ignore_off_page<void> {
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
@@ -269,8 +269,8 @@ inline bool operator!=(const gc_allocator_ignore_off_page<GC_T1>&,
template <class GC_Tp>
class traceable_allocator {
public:
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
typedef GC_Tp* pointer;
typedef const GC_Tp* const_pointer;
typedef GC_Tp& reference;
@@ -305,7 +305,7 @@ public:
{ GC_FREE(__p); }
size_type max_size() const GC_NOEXCEPT
- { return static_cast<size_t>(-1) / sizeof(GC_Tp); }
+ { return static_cast<std::size_t>(-1) / sizeof(GC_Tp); }
void construct(pointer __p, const GC_Tp& __val) { new(__p) GC_Tp(__val); }
void destroy(pointer __p) { __p->~GC_Tp(); }
@@ -313,8 +313,8 @@ public:
template<>
class traceable_allocator<void> {
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
diff --git a/include/gc/gc_cpp.h b/include/gc/gc_cpp.h
index 60281c0b..0f9ed90d 100644
--- a/include/gc/gc_cpp.h
+++ b/include/gc/gc_cpp.h
@@ -85,7 +85,6 @@ handling such cycles of objects with clean-up.
The collector cannot guarantee that it will find all inaccessible
objects. In practice, it finds almost all of them.
-
Cautions:
1. Be sure the collector is compiled with the C++ support
@@ -129,6 +128,11 @@ by UseGC. GC is an alias for UseGC, unless GC_NAME_CONFLICT is defined.
#ifdef GC_INCLUDE_NEW
# include <new> // for std, bad_alloc
+# define GC_PTRDIFF_T std::ptrdiff_t
+# define GC_SIZE_T std::size_t
+#else
+# define GC_PTRDIFF_T ptrdiff_t
+# define GC_SIZE_T size_t
#endif
#ifdef GC_NAMESPACE
@@ -157,7 +161,7 @@ by UseGC. GC is an alias for UseGC, unless GC_NAME_CONFLICT is defined.
#endif
#if (!defined(__BORLANDC__) || __BORLANDC__ > 0x0620) \
- && ! defined (__sgi) && ! defined(__WATCOMC__) \
+ && !defined(__sgi) && !defined(__WATCOMC__) \
&& (!defined(_MSC_VER) || _MSC_VER > 1020)
# define GC_PLACEMENT_DELETE
#endif
@@ -192,18 +196,18 @@ enum GCPlacement
};
/**
- * Instances of classes derived from "gc" will be allocated in the collected
+ * Instances of classes derived from gc will be allocated in the collected
* heap by default, unless an explicit NoGC placement is specified.
*/
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) GC_NOEXCEPT;
+ inline void* operator new(GC_SIZE_T);
+ inline void* operator new(GC_SIZE_T, GCPlacement);
+ inline void* operator new(GC_SIZE_T, void*) GC_NOEXCEPT;
// Must be redefined here, since the other overloadings hide
// the global definition.
- inline void operator delete(void* obj) GC_NOEXCEPT;
+ inline void operator delete(void*) GC_NOEXCEPT;
# ifdef GC_PLACEMENT_DELETE
inline void operator delete(void*, GCPlacement) GC_NOEXCEPT;
@@ -212,10 +216,10 @@ public:
# endif // GC_PLACEMENT_DELETE
# ifdef GC_OPERATOR_NEW_ARRAY
- 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) GC_NOEXCEPT;
- inline void operator delete[](void* obj) GC_NOEXCEPT;
+ inline void* operator new[](GC_SIZE_T);
+ inline void* operator new[](GC_SIZE_T, GCPlacement);
+ inline void* operator new[](GC_SIZE_T, void*) GC_NOEXCEPT;
+ inline void operator delete[](void*) GC_NOEXCEPT;
# ifdef GC_PLACEMENT_DELETE
inline void operator delete[](void*, GCPlacement) GC_NOEXCEPT;
inline void operator delete[](void*, void*) GC_NOEXCEPT;
@@ -224,10 +228,10 @@ public:
};
/**
- * Instances of classes derived from "gc_cleanup" will be allocated
+ * Instances of classes derived from gc_cleanup will be allocated
* in the collected heap by default. When the collector discovers
- * an inaccessible object derived from "gc_cleanup" or containing
- * a member derived from "gc_cleanup", its destructors will be invoked.
+ * an inaccessible object derived from gc_cleanup or containing
+ * a member derived from gc_cleanup, its destructors will be invoked.
*/
class gc_cleanup: virtual public gc
{
@@ -256,21 +260,21 @@ extern "C" {
# pragma warning(disable:4595)
#endif
-inline void* operator new(size_t size, GC_NS_QUALIFY(GCPlacement) gcp,
- GC_NS_QUALIFY(GCCleanUpFunc) /* cleanup */ = 0,
+inline void* operator new(GC_SIZE_T, GC_NS_QUALIFY(GCPlacement),
+ GC_NS_QUALIFY(GCCleanUpFunc) = 0,
void* /* clientData */ = 0);
// Allocates a collectible or uncollectible object, according to the
- // value of "gcp".
+ // value of gcp.
//
- // For collectible objects, if "cleanup" is non-null, then when the
- // allocated object "obj" becomes inaccessible, the collector will
- // invoke the function "cleanup(obj, clientData)" but will not
- // invoke the object's destructors. It is an error to explicitly
- // delete an object allocated with a non-null "cleanup".
+ // For collectible objects, if cleanup is non-null, then when the
+ // allocated object obj becomes inaccessible, the collector will
+ // invoke cleanup(obj,clientData) but will not invoke the object's
+ // destructors. It is an error to explicitly delete an object
+ // allocated with a non-null cleanup.
//
- // It is an error to specify a non-null "cleanup" with NoGC or for
- // classes derived from "gc_cleanup" or containing members derived
- // from "gc_cleanup".
+ // It is an error to specify a non-null cleanup with NoGC or for
+ // classes derived from gc_cleanup or containing members derived
+ // from gc_cleanup.
#ifdef GC_PLACEMENT_DELETE
inline void operator delete(void*, GC_NS_QUALIFY(GCPlacement),
@@ -280,127 +284,118 @@ inline void* operator new(size_t size, GC_NS_QUALIFY(GCPlacement) gcp,
#ifndef GC_NO_INLINE_STD_NEW
-#if defined(_MSC_VER) || defined(__DMC__) \
- || ((defined(__BORLANDC__) || defined(__CYGWIN__) \
- || defined(__CYGWIN32__) || defined(__MINGW32__) \
- || defined(__WATCOMC__)) \
- && !defined(GC_BUILD) && !defined(GC_NOT_DLL))
- // Inlining done to avoid mix up of new and delete operators by VC++ 9 (due
- // to arbitrary ordering during linking).
+# if defined(_MSC_VER) || defined(__DMC__) \
+ || ((defined(__BORLANDC__) || defined(__CYGWIN__) \
+ || defined(__CYGWIN32__) || defined(__MINGW32__) \
+ || defined(__WATCOMC__)) \
+ && !defined(GC_BUILD) && !defined(GC_NOT_DLL))
+ // Inlining done to avoid mix up of new and delete operators by VC++ 9
+ // (due to arbitrary ordering during linking).
+
+# ifdef GC_OPERATOR_NEW_ARRAY
+ inline void* operator new[](GC_SIZE_T size)
+ {
+ void* obj = GC_MALLOC_UNCOLLECTABLE(size);
+ GC_OP_NEW_OOM_CHECK(obj);
+ return obj;
+ }
-# ifdef GC_OPERATOR_NEW_ARRAY
- inline void* operator new[](size_t size)
+ inline void operator delete[](void* obj) GC_NOEXCEPT
+ {
+ GC_FREE(obj);
+ }
+# endif // GC_OPERATOR_NEW_ARRAY
+
+ inline void* operator new(GC_SIZE_T size)
{
void* obj = GC_MALLOC_UNCOLLECTABLE(size);
GC_OP_NEW_OOM_CHECK(obj);
return obj;
}
- inline void operator delete[](void* obj) GC_NOEXCEPT
+ inline void operator delete(void* obj) GC_NOEXCEPT
{
GC_FREE(obj);
}
-# endif
-
- inline void* operator new(size_t size)
- {
- void* obj = GC_MALLOC_UNCOLLECTABLE(size);
- GC_OP_NEW_OOM_CHECK(obj);
- return obj;
- }
-
- inline void operator delete(void* obj) GC_NOEXCEPT
- {
- GC_FREE(obj);
- }
-
-# if __cplusplus >= 201402L || _MSVC_LANG >= 201402L // C++14
- inline void operator delete(void* obj, size_t size) GC_NOEXCEPT {
- (void)size; // size is ignored
- GC_FREE(obj);
- }
-# if defined(GC_OPERATOR_NEW_ARRAY)
- inline void operator delete[](void* obj, size_t size) GC_NOEXCEPT {
- (void)size;
+# if __cplusplus >= 201402L || _MSVC_LANG >= 201402L // C++14
+ inline void operator delete(void* obj, GC_SIZE_T) GC_NOEXCEPT {
GC_FREE(obj);
}
-# endif
-# endif // C++14
-#endif
-#ifdef _MSC_VER
-
- // This new operator is used by VC++ in case of Debug builds:
-# ifdef GC_DEBUG
- inline void* operator new(size_t size, int /* nBlockUse */,
+# if defined(GC_OPERATOR_NEW_ARRAY)
+ inline void operator delete[](void* obj, GC_SIZE_T) GC_NOEXCEPT {
+ GC_FREE(obj);
+ }
+# endif
+# endif // C++14
+# endif // _MSC_VER || __CYGWIN__ && !GC_BUILD && !GC_NOT_DLL
+
+# ifdef _MSC_VER
+ // This new operator is used by VC++ in case of Debug builds.
+ inline void* operator new(GC_SIZE_T size, int /* nBlockUse */,
const char* szFileName, int nLine)
{
- void* obj = GC_debug_malloc_uncollectable(size, szFileName, nLine);
+# ifdef GC_DEBUG
+ void* obj = GC_debug_malloc_uncollectable(size, szFileName, nLine);
+# else
+ void* obj = GC_MALLOC_UNCOLLECTABLE(size);
+ (void)szFileName; (void)nLine;
+# endif
GC_OP_NEW_OOM_CHECK(obj);
return obj;
}
-# else
- inline void* operator new(size_t size, int /* nBlockUse */,
- const char* /* szFileName */, int /* nLine */)
- {
- void* obj = GC_malloc_uncollectable(size);
- GC_OP_NEW_OOM_CHECK(obj);
- return obj;
- }
-# endif /* !GC_DEBUG */
-
-# ifdef GC_OPERATOR_NEW_ARRAY
- // This new operator is used by VC++ 7+ in Debug builds:
- inline void* operator new[](size_t size, int nBlockUse,
- const char* szFileName, int nLine)
- {
- return operator new(size, nBlockUse, szFileName, nLine);
- }
-# endif
-#endif // _MSC_VER
+# ifdef GC_OPERATOR_NEW_ARRAY
+ // This new operator is used by VC++ 7+ in Debug builds.
+ inline void* operator new[](GC_SIZE_T size, int nBlockUse,
+ const char* szFileName, int nLine)
+ {
+ return operator new(size, nBlockUse, szFileName, nLine);
+ }
+# endif
+# endif // _MSC_VER
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) /* && GC_NO_INLINE_STD_NEW */
// The following ensures that the system default operator new[] does not
// 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 no way to redirect new in this environment without
// including this everywhere.
# ifdef GC_OPERATOR_NEW_ARRAY
- void *operator new[](size_t size);
- void operator delete[](void* obj);
+ void* operator new[](GC_SIZE_T);
+ void operator delete[](void*);
# endif
- void* operator new(size_t size);
- void operator delete(void* obj);
+ void* operator new(GC_SIZE_T);
+ void operator delete(void*);
- void* operator new(size_t size, int /* nBlockUse */,
- const char * szFileName, int nLine);
+ void* operator new(GC_SIZE_T, int /* nBlockUse */,
+ const char* /* szFileName */, int /* nLine */);
#endif // GC_NO_INLINE_STD_NEW && _MSC_VER
#ifdef GC_OPERATOR_NEW_ARRAY
// The operator new for arrays, identical to the above.
- inline void* operator new[](size_t size, GC_NS_QUALIFY(GCPlacement) gcp,
- GC_NS_QUALIFY(GCCleanUpFunc) /* cleanup */ = 0,
+ inline void* operator new[](GC_SIZE_T, GC_NS_QUALIFY(GCPlacement),
+ GC_NS_QUALIFY(GCCleanUpFunc) = 0,
void* /* clientData */ = 0);
#endif // GC_OPERATOR_NEW_ARRAY
-/* Inline implementation */
+// Inline implementation.
#ifdef GC_NAMESPACE
namespace boehmgc
{
#endif
-inline void* gc::operator new(size_t size)
+inline void* gc::operator new(GC_SIZE_T size)
{
void* obj = GC_MALLOC(size);
GC_OP_NEW_OOM_CHECK(obj);
return obj;
}
-inline void* gc::operator new(size_t size, GCPlacement gcp)
+inline void* gc::operator new(GC_SIZE_T size, GCPlacement gcp)
{
void* obj;
switch (gcp) {
@@ -423,7 +418,7 @@ inline void* gc::operator new(size_t size, GCPlacement gcp)
return obj;
}
-inline void* gc::operator new(size_t /* size */, void* p) GC_NOEXCEPT
+inline void* gc::operator new(GC_SIZE_T, void* p) GC_NOEXCEPT
{
return p;
}
@@ -436,24 +431,24 @@ inline void gc::operator delete(void* obj) GC_NOEXCEPT
#ifdef GC_PLACEMENT_DELETE
inline void gc::operator delete(void*, void*) GC_NOEXCEPT {}
- inline void gc::operator delete(void* p, GCPlacement /* gcp */) GC_NOEXCEPT
+ inline void gc::operator delete(void* obj, GCPlacement) GC_NOEXCEPT
{
- GC_FREE(p);
+ GC_FREE(obj);
}
#endif // GC_PLACEMENT_DELETE
#ifdef GC_OPERATOR_NEW_ARRAY
- inline void* gc::operator new[](size_t size)
+ inline void* gc::operator new[](GC_SIZE_T size)
{
return gc::operator new(size);
}
- inline void* gc::operator new[](size_t size, GCPlacement gcp)
+ inline void* gc::operator new[](GC_SIZE_T size, GCPlacement gcp)
{
return gc::operator new(size, gcp);
}
- inline void* gc::operator new[](size_t /* size */, void* p) GC_NOEXCEPT
+ inline void* gc::operator new[](GC_SIZE_T, void* p) GC_NOEXCEPT
{
return p;
}
@@ -466,8 +461,7 @@ inline void gc::operator delete(void* obj) GC_NOEXCEPT
# ifdef GC_PLACEMENT_DELETE
inline void gc::operator delete[](void*, void*) GC_NOEXCEPT {}
- inline void gc::operator delete[](void* p,
- GCPlacement /* gcp */) GC_NOEXCEPT
+ inline void gc::operator delete[](void* p, GCPlacement) GC_NOEXCEPT
{
gc::operator delete(p);
}
@@ -486,7 +480,7 @@ inline gc_cleanup::~gc_cleanup()
inline void GC_CALLBACK gc_cleanup::cleanup(void* obj, void* displ)
{
reinterpret_cast<gc_cleanup*>(reinterpret_cast<char*>(obj)
- + reinterpret_cast<ptrdiff_t>(displ))->~gc_cleanup();
+ + reinterpret_cast<GC_PTRDIFF_T>(displ))->~gc_cleanup();
}
inline gc_cleanup::gc_cleanup()
@@ -516,7 +510,7 @@ inline gc_cleanup::gc_cleanup()
}
#endif
-inline void* operator new(size_t size, GC_NS_QUALIFY(GCPlacement) gcp,
+inline void* operator new(GC_SIZE_T size, GC_NS_QUALIFY(GCPlacement) gcp,
GC_NS_QUALIFY(GCCleanUpFunc) cleanup,
void* clientData)
{
@@ -550,16 +544,17 @@ inline void* operator new(size_t size, GC_NS_QUALIFY(GCPlacement) gcp,
}
#ifdef GC_PLACEMENT_DELETE
- inline void operator delete(void* p, GC_NS_QUALIFY(GCPlacement) /* gcp */,
- GC_NS_QUALIFY(GCCleanUpFunc) /* cleanup */,
+ inline void operator delete(void* obj, GC_NS_QUALIFY(GCPlacement),
+ GC_NS_QUALIFY(GCCleanUpFunc),
void* /* clientData */) GC_NOEXCEPT
{
- GC_FREE(p);
+ GC_FREE(obj);
}
#endif // GC_PLACEMENT_DELETE
#ifdef GC_OPERATOR_NEW_ARRAY
- inline void* operator new[](size_t size, GC_NS_QUALIFY(GCPlacement) gcp,
+ inline void* operator new[](GC_SIZE_T size,
+ GC_NS_QUALIFY(GCPlacement) gcp,
GC_NS_QUALIFY(GCCleanUpFunc) cleanup,
void* clientData)
{