changeset 9260:9c2349a51218

properly unmark forced variables
author John W. Eaton <jwe@octave.org>
date Tue, 26 May 2009 11:20:40 -0400
parents 75c502937d2c
children 95445f9f5976
files src/ChangeLog src/input.cc src/octave.cc src/parse.y src/symtab.h src/toplev.cc src/variables.cc
diffstat 7 files changed, 76 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,20 @@
+2009-05-26  John W. Eaton  <jwe@octave.org>
+
+	* symtab.h
+	(symbol_table::symbol_record::symbol_record_rep::is_variable):
+	Use "! is_local ()" instead of storage_class != local.
+	(symbol_table::do_variable_names): Only add variables to the list.
+	(symbol_table::unmark_forced_variables): New static function
+	* variables.cc (do_who): Use is_variable instead of is_defined.
+	Also limit output to variables when using regexp pattern.
+	* octave.cc (unmark_forced_vars): Delete.
+	(execute_eval_option_code): Don't add unmark_forced_vars to 
+	unwind_protect stack here.
+	* toplev.cc (main_loop): Add symbol_table::unmark_forced_variables
+	to the unwind_protect stack here.
+	* input.cc (get_debug_input): Likewise.
+	* parse.y (parse_fcn_file, eval_string): Likewise.
+
 2009-05-25  Jaroslav Hajek  <highegg@gmail.com>
 
 	* toplev.h (quit_allowed): New global variable.
--- a/src/input.cc
+++ b/src/input.cc
@@ -666,6 +666,11 @@
       // Save current value of global_command.
       unwind_protect_ptr (global_command);
 
+      // Do this with an unwind-protect cleanup function so that the
+      // forced variables will be unmarked in the event of an interrupt.
+      symbol_table::scope_id scope = symbol_table::top_scope ();
+      unwind_protect::add (symbol_table::unmark_forced_variables, &scope);
+
       // This is the same as yyparse in parse.y.
       int retval = octave_parse ();
 
@@ -687,6 +692,9 @@
 	    octave_completion_matches_called = false;	    
 	}
 
+      // Unmark forced variables.
+      unwind_protect::run ();
+
       // Restore previous value of global_command.
       unwind_protect::run ();
 
--- a/src/octave.cc
+++ b/src/octave.cc
@@ -367,18 +367,6 @@
   unwind_protect::run_frame ("execute_startup_files");
 }
 
-static void
-unmark_forced_vars (void *arg)
-{
-  // Unmark any symbols that may have been tagged as local variables
-  // while parsing (for example, by force_local_variable in lex.l).
-
-  symbol_table::scope_id *pscope = static_cast <symbol_table::scope_id *> (arg);
-
-  if (pscope)
-    symbol_table::unmark_forced_variables (*pscope);
-}
-
 static int
 execute_eval_option_code (const std::string& code)
 {
@@ -398,11 +386,6 @@
 
   unwind_protect_bool (interactive);
 
-  // Do this with an unwind-protect cleanup function so that the
-  // forced variables will be unmarked in the event of an interrupt.
-  symbol_table::scope_id scope = symbol_table::top_scope ();
-  unwind_protect::add (unmark_forced_vars, &scope);
-
   interactive = false;
 
   int parse_status = 0;
--- a/src/parse.y
+++ b/src/parse.y
@@ -3258,6 +3258,12 @@
 
 	  reset_parser ();
 
+	  // Do this with an unwind-protect cleanup function so that
+	  // the forced variables will be unmarked in the event of an
+	  // interrupt. 
+	  symbol_table::scope_id scope = symbol_table::top_scope ();
+	  unwind_protect::add (symbol_table::unmark_forced_variables, &scope);
+
 	  if (! help_txt.empty ())
 	    help_buf.push (help_txt);
 
@@ -3905,10 +3911,19 @@
 
       unwind_protect_ptr (global_command);
 
+      // Do this with an unwind-protect cleanup function so that the
+      // forced variables will be unmarked in the event of an
+      // interrupt.
+      symbol_table::scope_id scope = symbol_table::top_scope ();
+      unwind_protect::add (symbol_table::unmark_forced_variables, &scope);
+
       parse_status = yyparse ();
 
       tree_statement_list *command_list = global_command;
 
+      // Unmark forced variables.
+      unwind_protect::run ();
+
       // Restore previous value of global_command.
       unwind_protect::run ();
 
--- a/src/symtab.h
+++ b/src/symtab.h
@@ -297,7 +297,7 @@
 
       bool is_variable (context_id context) const
       {
-	return (storage_class != local || is_defined (context) || is_forced ());
+	return (! is_local () || is_defined (context) || is_forced ());
       }
 
       bool is_local (void) const { return storage_class & local; }
@@ -1335,6 +1335,19 @@
   }
 
   // For unwind_protect.
+  static void unmark_forced_variables (void *arg)
+  {
+    // Unmark any symbols that may have been tagged as local variables
+    // while parsing (for example, by force_local_variable in lex.l).
+
+    symbol_table::scope_id *p = static_cast <symbol_table::scope_id *> (arg);
+
+  if (p)
+    unmark_forced_variables (*p);
+}
+
+
+  // For unwind_protect.
   static void clear_variables (void *) { clear_variables (); }
 
   static void clear_functions (void)
@@ -2289,7 +2302,10 @@
     std::list<std::string> retval;
 
     for (table_const_iterator p = table.begin (); p != table.end (); p++)
-      retval.push_back (p->first);
+      {
+	if (p->second.is_variable ())
+	  retval.push_back (p->first);
+      }
 
     retval.sort ();
 
--- a/src/toplev.cc
+++ b/src/toplev.cc
@@ -548,10 +548,18 @@
     {
       try
 	{
+	  unwind_protect::begin_frame ("main_loop");
+
 	  reset_error_handler ();
 
 	  reset_parser ();
 
+	  // Do this with an unwind-protect cleanup function so that
+	  // the forced variables will be unmarked in the event of an
+	  // interrupt.
+	  symbol_table::scope_id scope = symbol_table::top_scope ();
+	  unwind_protect::add (symbol_table::unmark_forced_variables, &scope);
+
 	  // This is the same as yyparse in parse.y.
 	  retval = octave_parse ();
 
@@ -602,6 +610,8 @@
 	      else if (parser_end_of_input)
 		break;
 	    }
+
+	  unwind_protect::run_frame ("main_loop");
 	}
       catch (octave_quit_exception e)
         {
--- a/src/variables.cc
+++ b/src/variables.cc
@@ -1453,10 +1453,13 @@
 	  for (std::list<symbol_table::symbol_record>::const_iterator p = tmp.begin ();
 	       p != tmp.end (); p++)
 	    {
-	      if (verbose)
-		symbol_stats.append (*p);
-	      else
-		symbol_names.push_back (p->name ());
+	      if (p->is_variable ())
+		{
+		  if (verbose)
+		    symbol_stats.append (*p);
+		  else
+		    symbol_names.push_back (p->name ());
+		}
 	    }
 	}
       else
@@ -1505,7 +1508,7 @@
 	      for (std::list<symbol_table::symbol_record>::const_iterator p = tmp.begin ();
 		   p != tmp.end (); p++)
 		{
-                  if (p->is_defined ())
+                  if (p->is_variable ())
                     {
                       if (verbose)
                         symbol_stats.append (*p);