Ping: [PATCH] Install error handler for out-of-memory when using STL containers
Tobias Schlüter
tobias.schlueter@physik.uni-muenchen.de
Sun Oct 28 15:50:00 GMT 2012
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.
-------------- next part --------------
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 ();
More information about the Gcc-patches
mailing list