changeset 9217:ee7cf4d963f3

smarter handling of quit()
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 20 May 2009 09:52:03 +0200
parents 9d4b84b14bf0
children 00ce0ae4ec63
files src/ChangeLog src/octave.cc src/toplev.cc src/toplev.h
diffstat 4 files changed, 47 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
+2009-05-20  Jaroslav Hajek  <highegg@gmail.com>
+
+	* toplev.h (octave_quit_exception): New class.
+	(octave_exit): New global variable.
+	* toplev.cc (octave_exit): Initialize to ::exit.
+	(clean_up_and_exit): Call octave_exit if set.
+	(Fquit): Raise octave_quit_exception to quit.
+	(main_loop): Catch octave_quit_exception.
+	* octave.cc (execute_command_line_file): Ditto.
+	(execute_eval_option_code): Ditto.
+
 2009-05-19  John W. Eaton  <jwe@octave.org>
 
 	* DLD-FUNCTIONS/fltk_backend.cc (F__fltk_redraw__): New function.
--- a/src/octave.cc
+++ b/src/octave.cc
@@ -411,6 +411,11 @@
     {
       eval_string (code, false, parse_status, 0);
     }
+  catch (octave_quit_exception e)
+    {
+      unwind_protect::run_frame ("execute_eval_option_code");
+      clean_up_and_exit (e.status);
+    }
   catch (octave_interrupt_exception)
     {
       recover_from_exception ();
@@ -478,6 +483,11 @@
 
       source_file (fname, context, verbose, require_file, "octave");
     }
+  catch (octave_quit_exception e)
+    {
+      unwind_protect::run_frame ("execute_command_line_file");
+      clean_up_and_exit (e.status);
+    }
   catch (octave_interrupt_exception)
     {
       recover_from_exception ();
--- a/src/toplev.cc
+++ b/src/toplev.cc
@@ -79,6 +79,8 @@
 #include "variables.h"
 #include <version.h>
 
+void (*octave_exit) (int) = ::exit;
+
 // TRUE means we are exiting via the builtin exit or quit functions.
 static bool quitting_gracefully = false;
 
@@ -598,6 +600,11 @@
 		break;
 	    }
 	}
+      catch (octave_quit_exception e)
+        {
+          unwind_protect::run_all ();
+          clean_up_and_exit (e.status);
+        }
       catch (octave_interrupt_exception)
 	{
 	  recover_from_exception ();
@@ -632,7 +639,8 @@
 
   sysdep_cleanup ();
 
-  exit (retval == EOF ? 0 : retval);
+  if (octave_exit)
+    (*octave_exit) (retval == EOF ? 0 : retval);
 }
 
 DEFUN (quit, args, nargout,
@@ -660,7 +668,7 @@
 	    exit_status = tmp;
 	}
 
-      clean_up_and_exit (exit_status);
+      throw octave_quit_exception (exit_status);
     }
   else
     error ("quit: invalid number of output arguments");
--- a/src/toplev.h
+++ b/src/toplev.h
@@ -37,11 +37,26 @@
 class tree_statement_list;
 class charMatrix;
 
+#include "quit.h"
+
 #include "input.h"
 #include "oct-map.h"
 
+
+extern void (*octave_exit) (int);
+
+// quit is a lot like an interrupt, so we subclass it to simplify possible
+// handling.
+class octave_quit_exception 
+: public octave_interrupt_exception
+{
+public:
+  int status;
+  octave_quit_exception (int s) : status (s) { }
+};
+
 extern OCTINTERP_API void
-clean_up_and_exit (int) GCC_ATTR_NORETURN;
+clean_up_and_exit (int);
 
 extern OCTINTERP_API void recover_from_exception (void);