From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30427 invoked by alias); 29 Jun 2007 20:34:05 -0000 Received: (qmail 30404 invoked by uid 22791); 29 Jun 2007 20:33:57 -0000 X-Spam-Check-By: sourceware.org Received: from a.mail.sonic.net (HELO a.mail.sonic.net) (64.142.16.245) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 29 Jun 2007 20:33:55 +0000 Received: from snyder (209-204-172-156.dsl.dynamic.sonic.net [209.204.172.156]) by a.mail.sonic.net (8.13.8.Beta0-Sonic/8.13.7) with SMTP id l5TKXpxq024526; Fri, 29 Jun 2007 13:33:51 -0700 Message-ID: <003201c7ba8c$d6e0e840$677ba8c0@sonic.net> Reply-To: "Michael Snyder" From: "Michael Snyder" To: "Daniel Jacobowitz" Cc: "Michael Snyder" , References: <9270.12.7.175.2.1183069663.squirrel@webmail.sonic.net> <20070628224815.GC12578@caradoc.them.org> <655C3D4066B7954481633935A40BB36F041427@ussunex02.svl.access-company.com> <20070628231153.GA14231@caradoc.them.org> <11470.12.7.175.2.1183080998.squirrel@webmail.sonic.net> <20070629113407.GA13561@caradoc.them.org> Subject: Re: [OB] Add cleanup, source.c Date: Sat, 30 Jun 2007 10:19:00 -0000 X-Mailer: Microsoft Outlook Express 6.00.2800.1437 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 X-SW-Source: 2007-06/txt/msg00534.txt.bz2 > We're both right. Cleanups do get discarded, and cleanups that aren't > discarded are called at the top level. Every cleanup I've written > since I started working on GDB at 2001 has been freed locally rather > than at the top level, though. I think it's very confusing if the > cleanups are not locally paired. > > From gdbint.texinfo: > > Your function should explicitly do or discard the cleanups it > creates. Failing to do this leads to non-deterministic behavior since > the caller will arbitrarily do or discard your functions cleanups. > This need leads to two common cleanup styles. Yeah, that text was written by Andrew in 2003. Before that we had some text written by Eli in about 2001, also saying that you should call do_cleanups. Don't mean to be a curmudgeon, but I go back way before that. ;-) Here's how version 1.1 of the document read: @section Cleanups Cleanups are a structured way to deal with things that need to be done later. When your code does something (like @code{malloc} some memory, or open a file) that needs to be undone later (e.g. free the memory or close the file), it can make a cleanup. The cleanup will be done at some future point: when the command is finished, when an error occurs, or when your code decides it's time to do cleanups. You can also discard cleanups, that is, throw them away without doing what they say. This is only done if you ask that it be done. Syntax: @table @code @item struct cleanup *@var{old_chain}; Declare a variable which will hold a cleanup chain handle. @item @var{old_chain} = make_cleanup (@var{function}, @var{arg}); Make a cleanup which will cause @var{function} to be called with @var{arg} (a @code{char *}) later. The result, @var{old_chain}, is a handle that can be passed to @code{do_cleanups} or @code{discard_cleanups} later. Unless you are going to call @code{do_cleanups} or @code{discard_cleanups} yourself, you can ignore the result from @code{make_cleanup}.