diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-06-01 10:45:55 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2024-06-03 21:17:54 +0100 |
commit | 2a83084ce5536353ceb8554e906f87273a59c4fd (patch) | |
tree | ccbfad5c73358e6046a43c45c54f23e13ea42a10 | |
parent | b0efdcbf58a76af3b8fff75f1d53d334fb5b46ee (diff) | |
download | gcc-2a83084ce5536353ceb8554e906f87273a59c4fd.zip gcc-2a83084ce5536353ceb8554e906f87273a59c4fd.tar.gz gcc-2a83084ce5536353ceb8554e906f87273a59c4fd.tar.bz2 |
libstdc++: Reuse temporary buffer utils in <stacktrace>
The non-throwing allocation logic in std::stacktrace duplicates the
logic in <bits/stl_tempbuf.h>, so we can just reuse those utilities.
libstdc++-v3/ChangeLog:
* include/std/stacktrace (basic_stacktrace::_Impl::_M_allocate):
Use __detail::__get_temporary_buffer.
(basic_stacktrace::_Impl::_M_deallocate): Use
__detail::__return_temporary_buffer.
-rw-r--r-- | libstdc++-v3/include/std/stacktrace | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace index 962dbed..e0a5439 100644 --- a/libstdc++-v3/include/std/stacktrace +++ b/libstdc++-v3/include/std/stacktrace @@ -45,6 +45,7 @@ #include <bits/stl_algo.h> #include <bits/stl_iterator.h> #include <bits/stl_uninitialized.h> +#include <bits/stl_tempbuf.h> // __get_temporary_buffer #include <ext/numeric_traits.h> namespace std _GLIBCXX_VISIBILITY(default) @@ -545,21 +546,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return std::min(__size_max, __alloc_max); } -#if __has_builtin(__builtin_operator_new) >= 201802L -# define _GLIBCXX_OPERATOR_NEW __builtin_operator_new -# define _GLIBCXX_OPERATOR_DELETE __builtin_operator_delete -#else -# define _GLIBCXX_OPERATOR_NEW ::operator new -# define _GLIBCXX_OPERATOR_DELETE ::operator delete -#endif - -#if __cpp_sized_deallocation -# define _GLIBCXX_SIZED_DELETE(T, p, n) \ - _GLIBCXX_OPERATOR_DELETE((p), (n) * sizeof(T)) -#else -# define _GLIBCXX_SIZED_DELETE(T, p, n) _GLIBCXX_OPERATOR_DELETE(p) -#endif - // Precondition: _M_frames == nullptr && __n != 0 pointer _M_allocate(allocator_type& __alloc, size_type __n) noexcept @@ -570,11 +556,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { // For std::allocator we use nothrow-new directly so we // don't need to handle bad_alloc exceptions. - size_t __nb = __n * sizeof(value_type); - void* const __p = _GLIBCXX_OPERATOR_NEW (__nb, nothrow_t{}); + auto __p = __detail::__get_temporary_buffer<value_type>(__n); if (__p == nullptr) [[unlikely]] return nullptr; - _M_frames = static_cast<pointer>(__p); + _M_frames = __p; } else { @@ -599,9 +584,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (_M_capacity) { if constexpr (is_same_v<allocator_type, allocator<value_type>>) - _GLIBCXX_SIZED_DELETE(value_type, - static_cast<void*>(_M_frames), - _M_capacity); + __detail::__return_temporary_buffer(_M_frames, _M_capacity); else __alloc.deallocate(_M_frames, _M_capacity); _M_frames = nullptr; @@ -609,10 +592,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } } -#undef _GLIBCXX_SIZED_DELETE -#undef _GLIBCXX_OPERATOR_DELETE -#undef _GLIBCXX_OPERATOR_NEW - // Precondition: __n <= _M_size void _M_resize(size_type __n, allocator_type& __alloc) noexcept |