From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26004 invoked by alias); 3 Jun 2013 06:07:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 25995 invoked by uid 89); 3 Jun 2013 06:07:25 -0000 X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_HOSTKARMA_NO autolearn=ham version=3.3.1 Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 03 Jun 2013 06:07:24 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id EC5972EBC4; Mon, 3 Jun 2013 02:07:22 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Eh7d+cUq0qdI; Mon, 3 Jun 2013 02:07:22 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 8115E2E476; Mon, 3 Jun 2013 02:07:22 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 0154EC255A; Mon, 3 Jun 2013 10:07:16 +0400 (RET) Date: Mon, 03 Jun 2013 06:07:00 -0000 From: Joel Brobecker To: Tom Tromey Cc: Pedro Alves , gdb-patches@sourceware.org Subject: Re: RFC: introduce scoped cleanups Message-ID: <20130603060716.GC12363@adacore.com> References: <87li7ohtiu.fsf@fleche.redhat.com> <87ppw8qlgl.fsf@fleche.redhat.com> <20130531061135.GA12363@adacore.com> <87obbrp2hg.fsf@fleche.redhat.com> <51A8CC81.9070509@redhat.com> <8738t2q4o2.fsf@fleche.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8738t2q4o2.fsf@fleche.redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-SW-Source: 2013-06/txt/msg00004.txt.bz2 > My one concern about this code is that, if a stack cleanup should be > leaked, then any future cleanup operation will refer to invalid memory. > > Right now, cleanup failures like this are a memory leak with the > possibility of wrong behavior -- but the new way seems more directly > fatal. > > Another option would be to allocate cleanups on an obstack. > This would often be efficient and would avoid the above problem. A very valid concern, IMO! I've never seen heap allocation as a reason for concern with respect to performance, and thus have never hesitated calling malloc. The only reason I have prefered alloca whenever possible is that it allows me to be lazy :-)! But this made me realize something: Why would someone want to do stack-cleanups instead of just calling alloca directly? Since alloca is basically a call-and-forget, what's the advantage of going through a stack-based cleanup? Regardless of the above, I like the idea of performing the cleanups on an obstack; fast and yet a little more resilient to programming errors. Not sure if that would be something easy to implement or not, though. -- Joel