Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Michael Snyder" <msnyder@sonic.net>
To: "Daniel Jacobowitz" <drow@false.org>
Cc: "Michael Snyder" <Michael.Snyder@access-company.com>,
	        <gdb-patches@sourceware.org>
Subject: Re: [OB] Add cleanup, source.c
Date: Sat, 30 Jun 2007 10:19:00 -0000	[thread overview]
Message-ID: <003201c7ba8c$d6e0e840$677ba8c0@sonic.net> (raw)
In-Reply-To: <20070629113407.GA13561@caradoc.them.org>



> 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.

<ahem>
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}.





  parent reply	other threads:[~2007-06-29 20:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-28 22:35 msnyder
2007-06-28 22:49 ` Daniel Jacobowitz
2007-06-28 23:12   ` msnyder
     [not found]   ` <655C3D4066B7954481633935A40BB36F041427@ussunex02.svl.access-company.com>
2007-06-29  0:24     ` Daniel Jacobowitz
2007-06-29  2:05       ` msnyder
2007-06-29 11:37         ` Daniel Jacobowitz
2007-06-29 17:02           ` Joel Brobecker
2007-06-29 20:34             ` Michael Snyder
2007-06-30 10:19           ` Michael Snyder [this message]
2007-06-30 14:17             ` Eli Zaretskii
2007-06-30 16:39               ` Michael Snyder
2007-06-30 16:40                 ` Daniel Jacobowitz
2007-06-30 18:25                 ` Eli Zaretskii
2007-07-03 18:13                   ` Jim Blandy
2007-07-04 17:35                     ` Joel Brobecker

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='003201c7ba8c$d6e0e840$677ba8c0@sonic.net' \
    --to=msnyder@sonic.net \
    --cc=Michael.Snyder@access-company.com \
    --cc=drow@false.org \
    --cc=gdb-patches@sourceware.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