From: "Michael Snyder" <msnyder@sonic.net>
To: "Joel Brobecker" <brobecker@adacore.com>,
"Michael Snyder" <Michael.Snyder@access-company.com>,
<gdb-patches@sourceware.org>
Subject: Re: [OB] Add cleanup, source.c
Date: Fri, 29 Jun 2007 20:34:00 -0000 [thread overview]
Message-ID: <002701c7ba7e$29222e20$677ba8c0@sonic.net> (raw)
In-Reply-To: <20070629161950.GA3609@adacore.com>
> > >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.
>
> Humpf! I think I have contributed loads of patches that do not
> follow this advice. I'll be careful in the future, but sometimes
> it's not easy. For instance, when you have a function that has
> multiple possible exit points...
Yes, I don't feel right about this at all. When was this paragraph
written? It took me a long time to figure out how make_cleanup
worked, but it was also a long time ago, and I have been writing
cleanups without explicitly invoking do_cleanup for many many
years now.
This is how I understand the subsystem:
1) Every invocation of make_cleanup (or variants) throws a callback
onto a queue, that is guaranteed to be executed no later than the end
of the command loop cycle, whether due to error or normal return.
2) When you save an "old_cleanups" pointer, eg.
struct cleanups *old_cleanups = make_cleanup (stuff);
it represents a watermark or bookmark in that queue. Now there are
two things you can do with that watermark.
a) discard_cleanups (old_cleanup) discards all the cleanups made
AFTER that point (including "stuff").
b) do_cleanups invokes all the cleanups made after that point.
3) But both of those actions have always been optional, and in my
understanding, only needed in special circumstances. The normal
flow is to do nothing -- and the cleanups will be done by the
command loop, before the next command.
The whole purpose of this was to PREVENT having to look out
for multiple or abnormal exits from a function, so that you didn't
have to make sure you freed stuff before calling error or something.
Adding a requirement to explicitly call do_cleanups would go
against the original design purpose of the subsystem.
next prev parent reply other threads:[~2007-06-29 18:49 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 [this message]
2007-06-30 10:19 ` Michael Snyder
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='002701c7ba7e$29222e20$677ba8c0@sonic.net' \
--to=msnyder@sonic.net \
--cc=Michael.Snyder@access-company.com \
--cc=brobecker@adacore.com \
--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