public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Only do shrink_to_fit() when exceptions enabled
@ 2015-09-17 14:57 Jonathan Wakely
  2015-09-21 11:56 ` Jonathan Wakely
  2015-11-25 16:19 ` Jonathan Wakely
  0 siblings, 2 replies; 3+ messages in thread
From: Jonathan Wakely @ 2015-09-17 14:57 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 274 bytes --]

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.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1829 bytes --]

commit 13cf19282acf42a52d5eacd2c293a944bd3e5ebe
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Sep 17 00:07:33 2015 +0100

    Only do shrink_to_fit() when exceptions enabled
    
    	* include/bits/allocator.h (__shrink_to_fit_aux<T, true>::_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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] Only do shrink_to_fit() when exceptions enabled
  2015-09-17 14:57 [patch] Only do shrink_to_fit() when exceptions enabled Jonathan Wakely
@ 2015-09-21 11:56 ` Jonathan Wakely
  2015-11-25 16:19 ` Jonathan Wakely
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2015-09-21 11:56 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 92 bytes --]

Oops.

Bootstrapped with --disable-libstdcxx-dual-abi on x86_64-linux,
committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 694 bytes --]

commit 9b9d9e3a5921f9a5225b466ce9d07b42b72f54dd
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   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
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] Only do shrink_to_fit() when exceptions enabled
  2015-09-17 14:57 [patch] Only do shrink_to_fit() when exceptions enabled Jonathan Wakely
  2015-09-21 11:56 ` Jonathan Wakely
@ 2015-11-25 16:19 ` Jonathan Wakely
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2015-11-25 16:19 UTC (permalink / raw)
  To: libstdc++, gcc-patches

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 Wakely <jwakely@redhat.com>
>Date:   Thu Sep 17 00:07:33 2015 +0100
>
>    Only do shrink_to_fit() when exceptions enabled
>    
>    	* include/bits/allocator.h (__shrink_to_fit_aux<T, true>::_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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-25 16:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-17 14:57 [patch] Only do shrink_to_fit() when exceptions enabled Jonathan Wakely
2015-09-21 11:56 ` Jonathan Wakely
2015-11-25 16:19 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).