public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [v3 PATCH] PR libstdc++/68276
@ 2015-12-16 22:12 Ville Voutilainen
  2015-12-16 22:38 ` Ville Voutilainen
  0 siblings, 1 reply; 5+ messages in thread
From: Ville Voutilainen @ 2015-12-16 22:12 UTC (permalink / raw)
  To: gcc-patches, libstdc++

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

Tested on Linux-PPC64.

2015-12-17  Ville Voutilainen  <ville.voutilainen@gmail.com>

    PR libstdc++/68276

    * src/c++11/ios.cc (_M_grow_words): Use nothrow new.
    * testsuite/27_io/ios_base/storage/11584.cc: Adjust.

[-- Attachment #2: 68276.diff --]
[-- Type: text/plain, Size: 1422 bytes --]

diff --git a/libstdc++-v3/src/c++11/ios.cc b/libstdc++-v3/src/c++11/ios.cc
index 4adc701..4241bef 100644
--- a/libstdc++-v3/src/c++11/ios.cc
+++ b/libstdc++-v3/src/c++11/ios.cc
@@ -121,9 +121,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	if (__ix < numeric_limits<int>::max())
 	  {
 	    __newsize = __ix + 1;
-	    __try
-	      { __words = new _Words[__newsize]; }
-	    __catch(const std::bad_alloc&)
+            __words = new (std::nothrow) _Words[__newsize];
+            if (!__words)
 	      {
 		_M_streambuf_state |= badbit;
 		if (_M_streambuf_state & _M_exception)
diff --git a/libstdc++-v3/testsuite/27_io/ios_base/storage/11584.cc b/libstdc++-v3/testsuite/27_io/ios_base/storage/11584.cc
index 0c80795..ae680c7 100644
--- a/libstdc++-v3/testsuite/27_io/ios_base/storage/11584.cc
+++ b/libstdc++-v3/testsuite/27_io/ios_base/storage/11584.cc
@@ -26,14 +26,14 @@
 
 int new_fails;
 
-void* operator new(std::size_t n) throw (std::bad_alloc)
+void* operator new(std::size_t n, const std::nothrow_t&) throw()
 {
   if (new_fails)
-    throw std::bad_alloc();  
+    return 0;
   return malloc(n);
 }
-void* operator new[] (std::size_t n) throw (std::bad_alloc)
-{ return operator new(n); }
+void* operator new[] (std::size_t n, const std::nothrow_t& ntt) throw()
+{ return operator new(n, ntt); }
 
 void operator delete (void *p) throw() { free(p); }
 void operator delete[] (void *p) throw() { operator delete(p); }

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

* Re: [v3 PATCH] PR libstdc++/68276
  2015-12-16 22:12 [v3 PATCH] PR libstdc++/68276 Ville Voutilainen
@ 2015-12-16 22:38 ` Ville Voutilainen
  2015-12-18 14:47   ` Jonathan Wakely
  0 siblings, 1 reply; 5+ messages in thread
From: Ville Voutilainen @ 2015-12-16 22:38 UTC (permalink / raw)
  To: gcc-patches, libstdc++

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

On 17 December 2015 at 00:12, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> Tested on Linux-PPC64.
>
> 2015-12-17  Ville Voutilainen  <ville.voutilainen@gmail.com>
>
>     PR libstdc++/68276
>
>     * src/c++11/ios.cc (_M_grow_words): Use nothrow new.
>     * testsuite/27_io/ios_base/storage/11584.cc: Adjust.

Shock horror, inconsistent indentation introduced by the patch. Fixed by the
attached patch.

[-- Attachment #2: 68276_2.diff --]
[-- Type: text/plain, Size: 1408 bytes --]

diff --git a/libstdc++-v3/src/c++11/ios.cc b/libstdc++-v3/src/c++11/ios.cc
index 4adc701..f701e61 100644
--- a/libstdc++-v3/src/c++11/ios.cc
+++ b/libstdc++-v3/src/c++11/ios.cc
@@ -121,9 +121,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	if (__ix < numeric_limits<int>::max())
 	  {
 	    __newsize = __ix + 1;
-	    __try
-	      { __words = new _Words[__newsize]; }
-	    __catch(const std::bad_alloc&)
+	    __words = new (std::nothrow) _Words[__newsize];
+	    if (!__words)
 	      {
 		_M_streambuf_state |= badbit;
 		if (_M_streambuf_state & _M_exception)
diff --git a/libstdc++-v3/testsuite/27_io/ios_base/storage/11584.cc b/libstdc++-v3/testsuite/27_io/ios_base/storage/11584.cc
index 0c80795..ae680c7 100644
--- a/libstdc++-v3/testsuite/27_io/ios_base/storage/11584.cc
+++ b/libstdc++-v3/testsuite/27_io/ios_base/storage/11584.cc
@@ -26,14 +26,14 @@
 
 int new_fails;
 
-void* operator new(std::size_t n) throw (std::bad_alloc)
+void* operator new(std::size_t n, const std::nothrow_t&) throw()
 {
   if (new_fails)
-    throw std::bad_alloc();  
+    return 0;
   return malloc(n);
 }
-void* operator new[] (std::size_t n) throw (std::bad_alloc)
-{ return operator new(n); }
+void* operator new[] (std::size_t n, const std::nothrow_t& ntt) throw()
+{ return operator new(n, ntt); }
 
 void operator delete (void *p) throw() { free(p); }
 void operator delete[] (void *p) throw() { operator delete(p); }

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

* Re: [v3 PATCH] PR libstdc++/68276
  2015-12-16 22:38 ` Ville Voutilainen
@ 2015-12-18 14:47   ` Jonathan Wakely
  2015-12-18 19:59     ` Ville Voutilainen
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Wakely @ 2015-12-18 14:47 UTC (permalink / raw)
  To: Ville Voutilainen; +Cc: gcc-patches, libstdc++

On 17/12/15 00:38 +0200, Ville Voutilainen wrote:
>On 17 December 2015 at 00:12, Ville Voutilainen
><ville.voutilainen@gmail.com> wrote:
>> Tested on Linux-PPC64.
>>
>> 2015-12-17  Ville Voutilainen  <ville.voutilainen@gmail.com>
>>
>>     PR libstdc++/68276
>>
>>     * src/c++11/ios.cc (_M_grow_words): Use nothrow new.
>>     * testsuite/27_io/ios_base/storage/11584.cc: Adjust.
>
>Shock horror, inconsistent indentation introduced by the patch. Fixed by the
>attached patch.

:-)

It only occurs to me now (rather than when I first suggested this
change) that it changes behaviour for users who have replaced operator
new, but not replaced the nothrow_t version.

But I can't believe that anyone would replace operator new *just* to
alter the behaviour of std::ios pword/iword allocation, and the
precise form of allocation used is unspecified, so I don't think
anyone can reasonably be hurt by this change (and it's good for
people who want to build the library with -fno-exceptions).

OK for trunk, thanks.

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

* Re: [v3 PATCH] PR libstdc++/68276
  2015-12-18 14:47   ` Jonathan Wakely
@ 2015-12-18 19:59     ` Ville Voutilainen
  2015-12-18 21:20       ` Jonathan Wakely
  0 siblings, 1 reply; 5+ messages in thread
From: Ville Voutilainen @ 2015-12-18 19:59 UTC (permalink / raw)
  To: gcc-patches, libstdc++

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

On 18 December 2015 at 16:47, Jonathan Wakely <jwakely@redhat.com> wrote:
> It only occurs to me now (rather than when I first suggested this
> change) that it changes behaviour for users who have replaced operator
> new, but not replaced the nothrow_t version.
>
> But I can't believe that anyone would replace operator new *just* to
> alter the behaviour of std::ios pword/iword allocation, and the
> precise form of allocation used is unspecified, so I don't think
> anyone can reasonably be hurt by this change (and it's good for
> people who want to build the library with -fno-exceptions).
>
> OK for trunk, thanks.

Here's a fix for the regression that the patch introduced. Tested with
-m32 on Linux-X64.

2015-12-18  Ville Voutilainen  <ville.voutilainen@gmail.com>

    Fix a regression introduced by the fix of libstdc++/68276.
    * src/c++11/ios.cc (_M_grow_words): Catch bad_alloc again so that
    bad_array_new_length is handled properly.

[-- Attachment #2: 68276_i32_fix.diff --]
[-- Type: text/plain, Size: 722 bytes --]

diff --git a/libstdc++-v3/src/c++11/ios.cc b/libstdc++-v3/src/c++11/ios.cc
index f701e61..17dad55 100644
--- a/libstdc++-v3/src/c++11/ios.cc
+++ b/libstdc++-v3/src/c++11/ios.cc
@@ -121,7 +121,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	if (__ix < numeric_limits<int>::max())
 	  {
 	    __newsize = __ix + 1;
-	    __words = new (std::nothrow) _Words[__newsize];
+	    /* We still need to catch bad_alloc even though we use
+	       a nothrow new, because the new-expression can throw
+	       a bad_array_new_length.  */
+	    __try
+	      { __words = new (std::nothrow) _Words[__newsize]; }
+	    __catch(const std::bad_alloc&)
+	      { __words = nullptr; }
 	    if (!__words)
 	      {
 		_M_streambuf_state |= badbit;

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

* Re: [v3 PATCH] PR libstdc++/68276
  2015-12-18 19:59     ` Ville Voutilainen
@ 2015-12-18 21:20       ` Jonathan Wakely
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Wakely @ 2015-12-18 21:20 UTC (permalink / raw)
  To: Ville Voutilainen; +Cc: gcc-patches, libstdc++

On 18/12/15 21:59 +0200, Ville Voutilainen wrote:
>Here's a fix for the regression that the patch introduced. Tested with
>-m32 on Linux-X64.

OK, thanks for the quick turnaround.

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

end of thread, other threads:[~2015-12-18 21:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-16 22:12 [v3 PATCH] PR libstdc++/68276 Ville Voutilainen
2015-12-16 22:38 ` Ville Voutilainen
2015-12-18 14:47   ` Jonathan Wakely
2015-12-18 19:59     ` Ville Voutilainen
2015-12-18 21:20       ` 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).