This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: When do cleanups happen?


> Daniel Jacobowitz wrote:
>   [cleanups only happen if there is an error]
> 
>> 
>> On Wed, Jan 09, 2002 at 02:18:53PM -0800, Michael Snyder wrote:
> 
>> > Cleanups are always done, no later than
>> > when the command is finished executing (if not earlier).  
> 
>> 
>> Well, the comments in utils.c are wrong, then :)
> 
> 
> 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:

	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.

enjoy,
Andrew






Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]