diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2023-04-20 09:16:47 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2023-04-20 13:28:49 +0300 |
commit | 06ffb93814a97d08fce62e2f3ce3135bc2473e59 (patch) | |
tree | 9d5d86d65d5de49630ad2833fe3bea1d3d4036d1 /gc_cpp.cc | |
parent | 906c14ec7907c28b5652ed253f7a48b259ee84e5 (diff) | |
download | bdwgc-06ffb93814a97d08fce62e2f3ce3135bc2473e59.tar.gz |
Provide global non-throwing operator new/delete in gccpp library
Note: this might require define GC_INCLUDE_NEW by client before
include gc_cpp.h on Windows hosts (to have nothrow_t declared before
the global inline operator new and delete are defined).
* gc_cpp.cc [(!_MSC_VER && !__DMC__ || GC_NO_INLINE_STD_NEW)
&& !GC_INLINE_STD_NEW && GC_OPERATOR_NEW_NOTHROW] (operator new,
operator delete): Define with nothrow_t argument.
* gc_cpp.cc [(!_MSC_VER && !__DMC__ || GC_NO_INLINE_STD_NEW)
&& !GC_INLINE_STD_NEW && GC_OPERATOR_NEW_ARRAY && !CPPCHECK
&& GC_OPERATOR_NEW_NOTHROW] (operator new[], operator delete[]):
Likewise.
* include/gc/gc_cpp.h [GC_INLINE_STD_NEW && GC_OPERATOR_NEW_ARRAY
&& GC_OPERATOR_NEW_NOTHROW] (operator new[], operator delete[]):
Likewise.
* include/gc/gc_cpp.h [GC_INLINE_STD_NEW && GC_OPERATOR_NEW_NOTHROW]
(operator new, operator delete): Likewise.
* include/gc/gc_cpp.h [!GC_OPERATOR_NEW_NOTHROW
&& !GC_NO_OPERATOR_NEW_NOTHROW && (GC_INCLUDE_NEW
&& (__cplusplus>=201103L || _MSVC_LANG>=201103L)
|| __NOTHROW_T_DEFINED)] (GC_OPERATOR_NEW_NOTHROW): Define macro;
add comment.
* include/gc/gc_cpp.h [!GC_INLINE_STD_NEW && GC_NO_INLINE_STD_NEW
&& _MSC_VER && GC_OPERATOR_NEW_ARRAY && GC_OPERATOR_NEW_NOTHROW]
(operator new[], operator delete[]): Add prototype with nothrow_t
argument (with commented out GC_ATTR_MALLOC).
* include/gc/gc_cpp.h [!GC_INLINE_STD_NEW && GC_NO_INLINE_STD_NEW
&& _MSC_VER && GC_OPERATOR_NEW_NOTHROW] (operator new,
operator delete): Likewise.
Diffstat (limited to 'gc_cpp.cc')
-rw-r--r-- | gc_cpp.cc | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -78,6 +78,18 @@ built-in "new" and "delete". GC_FREE(obj); } +# ifdef GC_OPERATOR_NEW_NOTHROW + void* operator new(GC_SIZE_T size, const std::nothrow_t&) GC_NOEXCEPT + { + return GC_MALLOC_UNCOLLECTABLE(size); + } + + void operator delete(void* obj, const std::nothrow_t&) GC_NOEXCEPT + { + GC_FREE(obj); + } +# endif // GC_OPERATOR_NEW_NOTHROW + # if defined(GC_OPERATOR_NEW_ARRAY) && !defined(CPPCHECK) void* operator new[](GC_SIZE_T size) GC_DECL_NEW_THROW { @@ -100,6 +112,18 @@ built-in "new" and "delete". { GC_FREE(obj); } + +# ifdef GC_OPERATOR_NEW_NOTHROW + void* operator new[](GC_SIZE_T size, const std::nothrow_t&) GC_NOEXCEPT + { + return GC_MALLOC_UNCOLLECTABLE(size); + } + + void operator delete[](void* obj, const std::nothrow_t&) GC_NOEXCEPT + { + GC_FREE(obj); + } +# endif // GC_OPERATOR_NEW_NOTHROW # endif // GC_OPERATOR_NEW_ARRAY # ifdef GC_OPERATOR_SIZED_DELETE |