changeset 7903:8018e10d2b87

save and restore global_command as needed
author John W. Eaton <jwe@octave.org>
date Wed, 09 Jul 2008 10:58:12 -0400
parents c51ae36fcbce
children 1fddd9b8e862
files src/ChangeLog src/input.cc src/parse.y src/toplev.cc
diffstat 4 files changed, 39 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Jul 08 14:22:08 2008 -0400
+++ b/src/ChangeLog	Wed Jul 09 10:58:12 2008 -0400
@@ -1,3 +1,8 @@
+2008-07-09  John W. Eaton  <jwe@octave.org>
+
+	* toplev.cc (main_loop): Unwind-protect global_command.
+	* input.cc (get_debug_input): Likewise.
+
 2008-07-08  John W. Eaton  <jwe@octave.org>
 
 	* graphics.h.in (axes::properties::keypos): Declare as
--- a/src/input.cc	Tue Jul 08 14:22:08 2008 -0400
+++ b/src/input.cc	Wed Jul 09 10:58:12 2008 -0400
@@ -625,16 +625,24 @@
 
       reset_parser ();
 
+      // Save current value of global_command.
+      unwind_protect_ptr (global_command);
+
       // This is the same as yyparse in parse.y.
       int retval = octave_parse ();
 
-      if (retval == 0 && global_command)
-	{
-	  global_command->eval ();
+      tree_statement_list *command = global_command;
+
+      // Restore previous value of global_command.
+      unwind_protect::run ();
 
-	  delete global_command;
+      if (retval == 0 && command)
+	{
+	  command->eval ();
 
-	  global_command = 0;
+	  delete command;
+
+	  command = 0;
 
 	  OCTAVE_QUIT;
 
--- a/src/parse.y	Tue Jul 08 14:22:08 2008 -0400
+++ b/src/parse.y	Wed Jul 09 10:58:12 2008 -0400
@@ -3719,8 +3719,6 @@
 
   current_eval_string = s;
 
-  unwind_protect_ptr (global_command);
-
   YY_BUFFER_STATE old_buf = current_buffer ();
   YY_BUFFER_STATE new_buf = create_buffer (0);
 
@@ -3733,10 +3731,15 @@
     {
       reset_parser ();
 
+      unwind_protect_ptr (global_command);
+
       parse_status = yyparse ();
 
       tree_statement_list *command = global_command;
 
+      // Restore previous value of global_command.
+      unwind_protect::run ();
+
       if (parse_status == 0)
         {
 	  if (command)
--- a/src/toplev.cc	Tue Jul 08 14:22:08 2008 -0400
+++ b/src/toplev.cc	Wed Jul 09 10:58:12 2008 -0400
@@ -543,6 +543,8 @@
 
   octave_initialized = true;
 
+  unwind_protect::begin_frame ("main_loop");
+
   // The big loop.
 
   int retval = 0;
@@ -556,18 +558,26 @@
 
 	  reset_parser ();
 
+	  // Save current value of global_command.
+	  unwind_protect_ptr (global_command);
+
 	  // This is the same as yyparse in parse.y.
 	  retval = octave_parse ();
 
+	  tree_statement_list *command = global_command;
+
+	  // Restore previous value of global_command.
+	  unwind_protect::run ();
+
 	  if (retval == 0)
 	    {
-	      if (global_command)
+	      if (command)
 		{
-		  global_command->eval ();
+		  command->eval ();
 
-		  delete global_command;
+		  delete command;
 
-		  global_command = 0;
+		  command = 0;
 
 		  OCTAVE_QUIT;
 
@@ -622,6 +632,8 @@
     }
   while (retval == 0);
 
+  unwind_protect::run_frame ("main_loop");
+
   return retval;
 }