Re: [patch] Only do shrink_to_fit() when exceptions enabled
On 17/09/15 15:56 +0100, Jonathan Wakely wrote: When exceptions are disabled a failed allocation while trying to shrink_to_fit() will abort the program. Since shrink_to_fit() is a non-binding request we should just ignore it rather than risk taking down the whole process. Tested powerpc64le-linux, committed to trunk. Also committed to gcc-5-branch. commit 13cf19282acf42a52d5eacd2c293a944bd3e5ebe Author: Jonathan WakelyDate: Thu Sep 17 00:07:33 2015 +0100 Only do shrink_to_fit() when exceptions enabled * include/bits/allocator.h (__shrink_to_fit_aux ::_S_do_it): Do nothing if exceptions are disabled. * include/bits/basic_string.h (basic_string::shrink_to_fit): Likewise. diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h index 6fd3214..0131521 100644 --- a/libstdc++-v3/include/bits/allocator.h +++ b/libstdc++-v3/include/bits/allocator.h @@ -209,15 +209,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static bool _S_do_it(_Tp& __c) noexcept { - __try +#if __cpp_exceptions + try { _Tp(__make_move_if_noexcept_iterator(__c.begin()), __make_move_if_noexcept_iterator(__c.end()), __c.get_allocator()).swap(__c); return true; } - __catch(...) + catch(...) { return false; } +#else + return false; +#endif } }; #endif diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index e6e7bb5..b5e7e36 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -833,13 +833,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 void shrink_to_fit() noexcept { +#if __cpp_exceptions if (capacity() > size()) { - __try + try { reserve(0); } - __catch(...) + catch(...) { } } +#endif } #endif @@ -3282,12 +3284,14 @@ _GLIBCXX_END_NAMESPACE_CXX11 void shrink_to_fit() _GLIBCXX_NOEXCEPT { +#if __cpp_exceptions if (capacity() > size()) { - __try + try { reserve(0); } - __catch(...) + catch(...) { } +#endif } } #endif
Re: [patch] Only do shrink_to_fit() when exceptions enabled
Oops. Bootstrapped with --disable-libstdcxx-dual-abi on x86_64-linux, committed to trunk. commit 9b9d9e3a5921f9a5225b466ce9d07b42b72f54dd Author: Jonathan WakelyDate: Mon Sep 21 11:58:41 2015 +0100 Fix bootstrap error introduced in r227870 PR libstdc++/67647 * include/bits/basic_string.h [!_GLIBCXX_USE_CXX11_ABI] (basic_string::shrink_to_fit): Fix #endif placement. diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index b5e7e36..c1689af 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -3291,8 +3291,8 @@ _GLIBCXX_END_NAMESPACE_CXX11 { reserve(0); } catch(...) { } -#endif } +#endif } #endif
[patch] Only do shrink_to_fit() when exceptions enabled
When exceptions are disabled a failed allocation while trying to shrink_to_fit() will abort the program. Since shrink_to_fit() is a non-binding request we should just ignore it rather than risk taking down the whole process. Tested powerpc64le-linux, committed to trunk. commit 13cf19282acf42a52d5eacd2c293a944bd3e5ebe Author: Jonathan WakelyDate: Thu Sep 17 00:07:33 2015 +0100 Only do shrink_to_fit() when exceptions enabled * include/bits/allocator.h (__shrink_to_fit_aux ::_S_do_it): Do nothing if exceptions are disabled. * include/bits/basic_string.h (basic_string::shrink_to_fit): Likewise. diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h index 6fd3214..0131521 100644 --- a/libstdc++-v3/include/bits/allocator.h +++ b/libstdc++-v3/include/bits/allocator.h @@ -209,15 +209,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static bool _S_do_it(_Tp& __c) noexcept { - __try +#if __cpp_exceptions + try { _Tp(__make_move_if_noexcept_iterator(__c.begin()), __make_move_if_noexcept_iterator(__c.end()), __c.get_allocator()).swap(__c); return true; } - __catch(...) + catch(...) { return false; } +#else + return false; +#endif } }; #endif diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index e6e7bb5..b5e7e36 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -833,13 +833,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 void shrink_to_fit() noexcept { +#if __cpp_exceptions if (capacity() > size()) { - __try + try { reserve(0); } - __catch(...) + catch(...) { } } +#endif } #endif @@ -3282,12 +3284,14 @@ _GLIBCXX_END_NAMESPACE_CXX11 void shrink_to_fit() _GLIBCXX_NOEXCEPT { +#if __cpp_exceptions if (capacity() > size()) { - __try + try { reserve(0); } - __catch(...) + catch(...) { } +#endif } } #endif