public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Tobias Schlüter" <tobias.schlueter@physik.uni-muenchen.de>
To: gcc-patches <gcc-patches@gcc.gnu.org>,
	 Fortran List <fortran@gcc.gnu.org>
Subject: Ping: [PATCH] Install error handler for out-of-memory when using STL containers
Date: Sun, 28 Oct 2012 15:50:00 -0000	[thread overview]
Message-ID: <508D4F1F.6040301@physik.uni-muenchen.de> (raw)
In-Reply-To: <507C7739.3070003@physik.uni-muenchen.de>

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


Ping.  This issue stands in the way of a very simple solution of PR 
fortran/51727.  I've re-attached the patch for your convenience.

On 15 Oct 2012 at 22:51:05 +0200 Tobias Schlüter wrote:
> The attached patch adds out-of-memory diagnostics for code using STL
> containers by using set_new_handler. Since the intended allocation
> size is not available to a new_handler, I had to forego a more
> detailed error message such as the one from xmalloc_failed().
> fatal_error() and abort() don't give a meaningful location when the
> new_handler is called, so I chose to put together the error message
> manually as is done in xmalloc_failed(). I would have found it more
> appealing to have operator new call xmalloc() unless a custom
> allocator is given, but I don't think there's a standard way of doing
> this.
>
> Built and tested on the C and Fortran testsuites. Ok for trunk?

Best regards,
- Tobi

2012-10-15  Tobias Schlüter  <tobi@gcc.gnu.org>

	* toplev.c: Add '#include <new>'.
	(cxx_out_of_memory): New function.
	(general_init): Install cxx_out_of_memory as handler for
	out-of-memory condition.

[-- Attachment #2: new_handler.diff.txt --]
[-- Type: text/plain, Size: 1320 bytes --]

2012-10-15  Tobias Schlüter  <tobi@gcc.gnu.org>

	* toplev.c: Add '#include <new>'.
	(cxx_out_of_memory): New function.
	(general_init): Install cxx_out_of_memory as handler for
	out-of-memory condition.

diff --git a/gcc/toplev.c b/gcc/toplev.c
index 2c9329f..2e6248a 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -89,6 +89,8 @@ along with GCC; see the file COPYING3.  If not see
 				   declarations for e.g. AIX 4.x.  */
 #endif
 
+#include <new>
+
 static void general_init (const char *);
 static void do_compile (void);
 static void process_options (void);
@@ -1061,6 +1063,21 @@ open_auxiliary_file (const char *ext)
   return file;
 }
 
+
+/* Error handler for use with C++ memory allocation.  Will be
+   installed via std::set_new_handler().  */
+
+static void
+cxx_out_of_memory()
+{
+  fprintf (stderr,
+	   "\n%s%sout of memory\n",
+	   progname, *progname ? ": " : "");
+
+  xexit (1);
+}
+
+
 /* Initialization of the front end environment, before command line
    options are parsed.  Signal handlers, internationalization etc.
    ARGV0 is main's argv[0].  */
@@ -1074,6 +1091,8 @@ general_init (const char *argv0)
     --p;
   progname = p;
 
+  std::set_new_handler (cxx_out_of_memory);
+
   xmalloc_set_program_name (progname);
 
   hex_init ();

  reply	other threads:[~2012-10-28 15:28 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-13 13:41 PR fortran/51727: make module files reproducible, question on C++ in gcc Tobias Schlüter
2012-10-13 13:51 ` Tobias Schlüter
2012-10-13 18:21 ` Diego Novillo
2012-10-13 18:23   ` Tobias Schlüter
2012-10-13 18:23     ` Diego Novillo
2012-10-13 22:48       ` Joseph S. Myers
2012-10-14 22:37 ` Janne Blomqvist
2012-10-15  0:31   ` Jakub Jelinek
2012-10-15 12:54     ` Tobias Schlüter
2012-10-15 17:58     ` Tobias Schlüter
2012-10-15 21:06     ` [PATCH] Install error handler for out-of-memory when using STL containers " Tobias Schlüter
2012-10-28 15:50       ` Tobias Schlüter [this message]
2012-10-29  9:48         ` Ping: [PATCH] Install error handler for out-of-memory when using STL containers Paul Richard Thomas
2012-10-29 17:38           ` Mike Stump
2012-11-03  9:17         ` Ping**2: " Tobias Schlüter
2012-10-15 13:12   ` PR fortran/51727: make module files reproducible, question on C++ in gcc Tobias Schlüter
2012-11-08 19:02   ` Tobias Schlüter
2012-11-29 10:40   ` Tobias Schlüter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=508D4F1F.6040301@physik.uni-muenchen.de \
    --to=tobias.schlueter@physik.uni-muenchen.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).