This is the mail archive of the
mailing list for the GDB project.
Re: When do cleanups happen?
- From: "Eli Zaretskii" <eliz at is dot elta dot co dot il>
- To: ac131313 at cygnus dot com
- Cc: msnyder at redhat dot com, gdb at sources dot redhat dot com, drow at mvista dot com
- Date: Thu, 10 Jan 2002 09:27:08 +0200
- Subject: Re: When do cleanups happen?
- References: <20020109151622.A842@nevyn.them.org> <3C3CC1CD.798D57DB@redhat.com> <20020109181030.B6397@nevyn.them.org> <3C3CD52D.E01410D2@redhat.com> <3C3CE214.firstname.lastname@example.org>
- Reply-to: Eli Zaretskii <eliz at is dot elta dot co dot il>
> Date: Wed, 09 Jan 2002 19:36:36 -0500
> From: Andrew Cagney <email@example.com>
> > Hmm! Now I am confused.
> > What do others think? Are cleanups cleaned-up only on error?
> > Or always when a command finishes? I know that I have found
> > that if I make a cleanup that closes a file, then I cannot close
> > that file myself else it will wind up being closed twice.
> Two styles:
Andrew, if Michael got confused by this, our docs needs work. So I
suggest to add the nice explanations below to gdbint.texinfo, as the
first step towards a remedy. There's a section about cleanups there
where these explanations will fit nicely.
> oc = make_cleanup (close, fd); // yes ok that is bad
> ....blah blah
> do_cleanups (oc);
> which always does the close using the cleanup. This is kind of like a
> TRY ... FINALLY .. END construct;
> oc = make_cleanup (close, fd); // ...
> ... blah blah
> discard_cleanups (oc); //* is that the right f name?
> ... blah blah
> close (fd);
> which discards the cleanups so you're free to do the close. This is
> kind of a TRY ... EXCEPT ... END.
> And then there is the truth:
> catch_exceptions() / catch_errors() does a cleanup.
> the main command loop has a do_cleanup() call.