From patchwork Sun Oct 28 15:28:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tobias_Schl=C3=BCter?= X-Patchwork-Id: 194712 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E61CC2C0086 for ; Mon, 29 Oct 2012 02:28:46 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1352042927; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=rxWHBa5+S5PpWU7XgDT+VWgmhWU=; b=MifRNUmCagjyn7E qIf9DseuqIZlyFLZJ0mUpRxUrUzaRO3RecaJrnLfZk7JIOuCxAQP7gzR92qLckua lNOfVcYeT6G8nyaNmm1SDwI6T4dYskFV6Xr3b6cjYmdU7LQ6Hh3UvtSvCZatNkte mlzIAEJiy0kynMoe0LEk9EKJcaPI= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=sy7yIM4MkYeIz/mnDYloCjPwr8ptK7h4TGA9CX4vjRSt0eqqp8Hd4SfiUVCVqU 710E9gqkddYQMlztRmRQ5E9OqSX6BEbnNI3zRFyt6f8y29yTdgjpXtalIGkJj84y ZAJL8NzYAgBfeHUYf5G2IL7qcxrD80A1koHoC3f4mzqkQ=; Received: (qmail 20140 invoked by alias); 28 Oct 2012 15:28:38 -0000 Received: (qmail 20119 invoked by uid 22791); 28 Oct 2012 15:28:36 -0000 X-SWARE-Spam-Status: No, hits=-4.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_THREADED, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mail.physik.uni-muenchen.de (HELO mail.physik.uni-muenchen.de) (192.54.42.129) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 28 Oct 2012 15:28:27 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.physik.uni-muenchen.de (Postfix) with ESMTP id 2E14F27D8A; Sun, 28 Oct 2012 16:28:26 +0100 (CET) Received: from mail.physik.uni-muenchen.de ([127.0.0.1]) by localhost (mail.physik.uni-muenchen.de [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 9m-ErE6R8tNH; Sun, 28 Oct 2012 16:28:25 +0100 (CET) Received: from 68a86d51c8b4.dfn.mwn.de (unknown [IPv6:2001:4ca0:0:f202:a4c7:ef6:998:8203]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.physik.uni-muenchen.de (Postfix) with ESMTP id E903C27CB5; Sun, 28 Oct 2012 16:28:25 +0100 (CET) Message-ID: <508D4F1F.6040301@physik.uni-muenchen.de> Date: Sun, 28 Oct 2012 16:28:31 +0100 From: =?ISO-8859-1?Q?Tobias_Schl=FCter?= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 To: gcc-patches , Fortran List Subject: Ping: [PATCH] Install error handler for out-of-memory when using STL containers In-Reply-To: <507C7739.3070003@physik.uni-muenchen.de> Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 * toplev.c: Add '#include '. (cxx_out_of_memory): New function. (general_init): Install cxx_out_of_memory as handler for out-of-memory condition. 2012-10-15 Tobias Schlüter * toplev.c: Add '#include '. (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 + 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 ();