diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2023-04-14 09:42:28 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2023-04-17 12:05:54 +0300 |
commit | 08eb0da6f5dbc9de1c0bf6e2ad7a7dedb24ac551 (patch) | |
tree | 0959a07b12aea8f30cf38911ddb710eb68787bed /gc_cpp.cc | |
parent | d1bc109ec4d548a6977060affe0012b1643bedf5 (diff) | |
download | bdwgc-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 'gc_cpp.cc')
-rw-r--r-- | gc_cpp.cc | 46 |
1 files changed, 21 insertions, 25 deletions
@@ -33,18 +33,18 @@ built-in "new" and "delete". #define GC_DONT_INCL_WINDOWS_H #include "gc/gc.h" -#include <new> // for bad_alloc, precedes include of gc_cpp.h +#include <new> // for std, bad_alloc; precedes include of gc_cpp.h #include "gc/gc_cpp.h" // for GC_OPERATOR_NEW_ARRAY #if !(defined(_MSC_VER) || defined(__DMC__)) || defined(GC_NO_INLINE_STD_NEW) -#if defined(GC_NEW_ABORTS_ON_OOM) || defined(_LIBCPP_NO_EXCEPTIONS) -# define GC_ALLOCATOR_THROW_OR_ABORT() GC_abort_on_oom() -#else -// Use bad_alloc() directly instead of GC_throw_bad_alloc() call. -# define GC_ALLOCATOR_THROW_OR_ABORT() throw std::bad_alloc() -#endif +# if defined(GC_NEW_ABORTS_ON_OOM) || defined(_LIBCPP_NO_EXCEPTIONS) +# define GC_ALLOCATOR_THROW_OR_ABORT() GC_abort_on_oom() +# else + // Use bad_alloc() directly instead of GC_throw_bad_alloc() call. +# define GC_ALLOCATOR_THROW_OR_ABORT() throw std::bad_alloc() +# endif # if !defined(GC_NEW_DELETE_THROW_NOT_NEEDED) \ && !defined(GC_NEW_DELETE_NEED_THROW) && GC_GNUC_PREREQ(4, 2) \ @@ -52,19 +52,17 @@ built-in "new" and "delete". # define GC_NEW_DELETE_NEED_THROW # endif -# ifdef GC_NEW_DELETE_NEED_THROW -# if __cplusplus >= 201703L || _MSVC_LANG >= 201703L - // The "dynamic exception" syntax had been deprecated in C++11 - // and was removed in C++17. -# define GC_DECL_NEW_THROW noexcept(false) -# else -# define GC_DECL_NEW_THROW throw(std::bad_alloc) -# endif -# else +# ifndef GC_NEW_DELETE_NEED_THROW # define GC_DECL_NEW_THROW /* empty */ -# endif +# elif __cplusplus >= 201703L || _MSVC_LANG >= 201703L + // The "dynamic exception" syntax had been deprecated in C++11 + // and was removed in C++17. +# define GC_DECL_NEW_THROW noexcept(false) +# else +# define GC_DECL_NEW_THROW throw(std::bad_alloc) +# endif // GC_NEW_DELETE_NEED_THROW - void* operator new(size_t size) GC_DECL_NEW_THROW { + void* operator new(std::size_t size) GC_DECL_NEW_THROW { void* obj = GC_MALLOC_UNCOLLECTABLE(size); if (0 == obj) GC_ALLOCATOR_THROW_OR_ABORT(); @@ -73,7 +71,7 @@ built-in "new" and "delete". # ifdef _MSC_VER // This new operator is used by VC++ in case of Debug builds. - void* operator new(size_t size, int /* nBlockUse */, + void* operator new(std::size_t size, int /* nBlockUse */, const char* szFileName, int nLine) { # ifdef GC_DEBUG @@ -93,7 +91,7 @@ built-in "new" and "delete". } # if defined(GC_OPERATOR_NEW_ARRAY) && !defined(CPPCHECK) - void* operator new[](size_t size) GC_DECL_NEW_THROW { + void* operator new[](std::size_t size) GC_DECL_NEW_THROW { void* obj = GC_MALLOC_UNCOLLECTABLE(size); if (0 == obj) GC_ALLOCATOR_THROW_OR_ABORT(); @@ -102,7 +100,7 @@ built-in "new" and "delete". # ifdef _MSC_VER // This new operator is used by VC++ 7+ in Debug builds. - void* operator new[](size_t size, int nBlockUse, + void* operator new[](std::size_t size, int nBlockUse, const char* szFileName, int nLine) { return operator new(size, nBlockUse, szFileName, nLine); @@ -115,14 +113,12 @@ built-in "new" and "delete". # endif // GC_OPERATOR_NEW_ARRAY # if __cplusplus >= 201402L || _MSVC_LANG >= 201402L // C++14 - void operator delete(void* obj, size_t size) GC_NOEXCEPT { - (void)size; // size is ignored + void operator delete(void* obj, std::size_t) GC_NOEXCEPT { GC_FREE(obj); } # if defined(GC_OPERATOR_NEW_ARRAY) && !defined(CPPCHECK) - void operator delete[](void* obj, size_t size) GC_NOEXCEPT { - (void)size; + void operator delete[](void* obj, std::size_t) GC_NOEXCEPT { GC_FREE(obj); } # endif |