summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2023-04-17 23:53:44 +0300
committerIvan Maidanski <ivmai@mail.ru>2023-04-17 23:53:44 +0300
commit8fe38c6fbd7725fa4c3d4e8132d440251e73e807 (patch)
treea1c8aaed560b0d7bdaafc4a8b296af7fe749b20e
parentd70772a42debc40d4c13fd735913ee6ae322aa9b (diff)
downloadbdwgc-8fe38c6fbd7725fa4c3d4e8132d440251e73e807.tar.gz
Fix 'size_t not found in namespace std' dmc error in gc_allocator.h
(fix of commit 08eb0da6f) * gc_cpp.cc (operator new, operator delete): Use GC_SIZE_T instead of std::size_t. * include/gc/gc_allocator.h (GC_ALCTR_PTRDIFF_T, GC_ALCTR_SIZE_T): Define macro (and undefine it at the end of file). * 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): Use GC_ALCTR_SIZE_T instead of std::size_t. * include/gc/gc_allocator.h (gc_allocator.difference_type, gc_allocator_ignore_off_page.difference_type, traceable_allocator.difference_type): Use GC_ALCTR_PTRDIFF_T instead of std::ptrdiff_t. * include/gc/gc_cpp.h [GC_INCLUDE_NEW] (GC_PTRDIFF_T, GC_SIZE_T): Do not use std:: prefix unless __cplusplus>=201103L.
-rw-r--r--gc_cpp.cc12
-rw-r--r--include/gc/gc_allocator.h47
-rw-r--r--include/gc/gc_cpp.h3
3 files changed, 39 insertions, 23 deletions
diff --git a/gc_cpp.cc b/gc_cpp.cc
index 0600625a..82d93c51 100644
--- a/gc_cpp.cc
+++ b/gc_cpp.cc
@@ -56,7 +56,7 @@ built-in "new" and "delete".
# define GC_DECL_NEW_THROW throw(std::bad_alloc)
# endif // GC_NEW_DELETE_NEED_THROW
- void* operator new(std::size_t size) GC_DECL_NEW_THROW {
+ void* operator new(GC_SIZE_T size) GC_DECL_NEW_THROW {
void* obj = GC_MALLOC_UNCOLLECTABLE(size);
if (0 == obj)
GC_ALLOCATOR_THROW_OR_ABORT();
@@ -65,7 +65,7 @@ built-in "new" and "delete".
# ifdef _MSC_VER
// This new operator is used by VC++ in case of Debug builds.
- void* operator new(std::size_t size, int /* nBlockUse */,
+ void* operator new(GC_SIZE_T size, int /* nBlockUse */,
const char* szFileName, int nLine)
{
# ifdef GC_DEBUG
@@ -85,7 +85,7 @@ built-in "new" and "delete".
}
# if defined(GC_OPERATOR_NEW_ARRAY) && !defined(CPPCHECK)
- void* operator new[](std::size_t size) GC_DECL_NEW_THROW {
+ void* operator new[](GC_SIZE_T size) GC_DECL_NEW_THROW {
void* obj = GC_MALLOC_UNCOLLECTABLE(size);
if (0 == obj)
GC_ALLOCATOR_THROW_OR_ABORT();
@@ -94,7 +94,7 @@ built-in "new" and "delete".
# ifdef _MSC_VER
// This new operator is used by VC++ 7+ in Debug builds.
- void* operator new[](std::size_t size, int nBlockUse,
+ void* operator new[](GC_SIZE_T size, int nBlockUse,
const char* szFileName, int nLine)
{
return operator new(size, nBlockUse, szFileName, nLine);
@@ -107,12 +107,12 @@ built-in "new" and "delete".
# endif // GC_OPERATOR_NEW_ARRAY
# if __cplusplus >= 201402L || _MSVC_LANG >= 201402L // C++14
- void operator delete(void* obj, std::size_t) GC_NOEXCEPT {
+ void operator delete(void* obj, GC_SIZE_T) GC_NOEXCEPT {
GC_FREE(obj);
}
# if defined(GC_OPERATOR_NEW_ARRAY) && !defined(CPPCHECK)
- void operator delete[](void* obj, std::size_t) GC_NOEXCEPT {
+ void operator delete[](void* obj, GC_SIZE_T) GC_NOEXCEPT {
GC_FREE(obj);
}
# endif
diff --git a/include/gc/gc_allocator.h b/include/gc/gc_allocator.h
index 5787d170..34a0f3ab 100644
--- a/include/gc/gc_allocator.h
+++ b/include/gc/gc_allocator.h
@@ -60,6 +60,14 @@ namespace boehmgc
# define GC_ALLOCATOR_THROW_OR_ABORT() throw std::bad_alloc()
#endif
+#if __cplusplus >= 201103L
+# define GC_ALCTR_PTRDIFF_T std::ptrdiff_t
+# define GC_ALCTR_SIZE_T std::size_t
+#else
+# define GC_ALCTR_PTRDIFF_T ptrdiff_t
+# define GC_ALCTR_SIZE_T size_t
+#endif
+
// First some helpers to allow us to dispatch on whether or not a type
// is known to be pointer-free. These are private, except that the client
// may invoke the GC_DECLARE_PTRFREE macro.
@@ -92,7 +100,8 @@ 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(std::size_t n, GC_Tp, bool ignore_off_page) {
+inline void * GC_selective_alloc(GC_ALCTR_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 +111,8 @@ inline void * GC_selective_alloc(std::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>(std::size_t n, GC_true_type,
+ inline void * GC_selective_alloc<GC_true_type>(GC_ALCTR_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 +126,8 @@ inline void * GC_selective_alloc(std::size_t n, GC_Tp, bool ignore_off_page) {
template <class GC_Tp>
class gc_allocator {
public:
- typedef std::size_t size_type;
- typedef std::ptrdiff_t difference_type;
+ typedef GC_ALCTR_SIZE_T size_type;
+ typedef GC_ALCTR_PTRDIFF_T difference_type;
typedef GC_Tp* pointer;
typedef const GC_Tp* const_pointer;
typedef GC_Tp& reference;
@@ -152,7 +162,7 @@ public:
{ GC_FREE(__p); }
size_type max_size() const GC_NOEXCEPT
- { return static_cast<std::size_t>(-1) / sizeof(GC_Tp); }
+ { return static_cast<GC_ALCTR_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 +170,8 @@ public:
template<>
class gc_allocator<void> {
- typedef std::size_t size_type;
- typedef std::ptrdiff_t difference_type;
+ typedef GC_ALCTR_SIZE_T size_type;
+ typedef GC_ALCTR_PTRDIFF_T difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
@@ -189,8 +199,8 @@ inline bool operator!=(const gc_allocator<GC_T1>&,
template <class GC_Tp>
class gc_allocator_ignore_off_page {
public:
- typedef std::size_t size_type;
- typedef std::ptrdiff_t difference_type;
+ typedef GC_ALCTR_SIZE_T size_type;
+ typedef GC_ALCTR_PTRDIFF_T difference_type;
typedef GC_Tp* pointer;
typedef const GC_Tp* const_pointer;
typedef GC_Tp& reference;
@@ -227,7 +237,7 @@ public:
{ GC_FREE(__p); }
size_type max_size() const GC_NOEXCEPT
- { return static_cast<std::size_t>(-1) / sizeof(GC_Tp); }
+ { return static_cast<GC_ALCTR_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 +245,8 @@ public:
template<>
class gc_allocator_ignore_off_page<void> {
- typedef std::size_t size_type;
- typedef std::ptrdiff_t difference_type;
+ typedef GC_ALCTR_SIZE_T size_type;
+ typedef GC_ALCTR_PTRDIFF_T difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
@@ -269,8 +279,8 @@ inline bool operator!=(const gc_allocator_ignore_off_page<GC_T1>&,
template <class GC_Tp>
class traceable_allocator {
public:
- typedef std::size_t size_type;
- typedef std::ptrdiff_t difference_type;
+ typedef GC_ALCTR_SIZE_T size_type;
+ typedef GC_ALCTR_PTRDIFF_T difference_type;
typedef GC_Tp* pointer;
typedef const GC_Tp* const_pointer;
typedef GC_Tp& reference;
@@ -305,7 +315,7 @@ public:
{ GC_FREE(__p); }
size_type max_size() const GC_NOEXCEPT
- { return static_cast<std::size_t>(-1) / sizeof(GC_Tp); }
+ { return static_cast<GC_ALCTR_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 +323,8 @@ public:
template<>
class traceable_allocator<void> {
- typedef std::size_t size_type;
- typedef std::ptrdiff_t difference_type;
+ typedef GC_ALCTR_SIZE_T size_type;
+ typedef GC_ALCTR_PTRDIFF_T difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
@@ -338,6 +348,9 @@ inline bool operator!=(const traceable_allocator<GC_T1>&,
return false;
}
+#undef GC_ALCTR_PTRDIFF_T
+#undef GC_ALCTR_SIZE_T
+
#ifdef GC_NAMESPACE_ALLOCATOR
}
#endif
diff --git a/include/gc/gc_cpp.h b/include/gc/gc_cpp.h
index c6c964ce..99df1aa5 100644
--- a/include/gc/gc_cpp.h
+++ b/include/gc/gc_cpp.h
@@ -128,6 +128,9 @@ by UseGC. GC is an alias for UseGC, unless GC_NAME_CONFLICT is defined.
#ifdef GC_INCLUDE_NEW
# include <new> // for std, bad_alloc
+#endif
+
+#if defined(GC_INCLUDE_NEW) && (__cplusplus >= 201103L)
# define GC_PTRDIFF_T std::ptrdiff_t
# define GC_SIZE_T std::size_t
#else