help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

quit() implementation


From: Jaroslav Hajek
Subject: quit() implementation
Date: Tue, 26 May 2009 09:23:18 +0200

hi all,

I just feel that maybe a discussion should be raised about this topic.
A few days ago there was some discussion about the behaviour of
quit(),
which until recently simply called Octave cleanup actions and then
system exit(). The problem is that if you embed Octave in another C++
application, this behavior is seldom desired. You often want to do
other cleanup before quitting, or not quit at all (Pytave is an
example).

I solved this problem by having quit() actually raise an exception
(octave_quit_exception) which in normal Octave run is caught in
main_loop and reacted upon. This allows implementing a custom reaction
to quit() when octave is embedded in C++, by embedding calls to, say,
feval in a try-catch block and catching the exceptions.

The drawback, however, is that probably few C++ apps will be ready for
this; so instead of unwanted (yet relatively clean) exits via system
exit() we will get unhandled exceptions resulting usually in abort()
(and, I believe, confused mails :). I believe that most embedding
applications simply don't want quit() at all, because it makes no good
sense. That's why I have made another change: when octave is run in
embedded mode (octave_main is called with the "embedded" flag), the
built-in function quit() is disabled by default (calling it results in
an error). This is controllable by the global flag quit_allowed in
toplev.h. After all, interrupts are allowed neither (by default) in
embedded mode, and quit() can be seen as a kind of interrupt.

I think the current solution is definitely best than the previous
state (where you simply had no choice), and it seems a reasonable
compromise to me.
But maybe someone has a better idea how to do the whole thing, or a
good argument why I completely screwed things up with this.

I'd like to note that for normal, unembedded Octave runs, quit() works
as before, with the exception that it no longer ignores
unwind_protect_cleanup blocks
(which I think was a bug).

opinions?

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]