changeset 7374:4ff9611147ba

[project @ 2008-01-15 00:50:50 by jwe]
author jwe
date Tue, 15 Jan 2008 00:50:50 +0000
parents f350da755600
children 4fbfce35012a
files src/ChangeLog src/load-path.cc src/symtab.h
diffstat 3 files changed, 47 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Jan 14 20:12:42 2008 +0000
+++ b/src/ChangeLog	Tue Jan 15 00:50:50 2008 +0000
@@ -1,3 +1,14 @@
+2008-01-14  John W. Eaton  <jwe@octave.org>
+
+	* load-path.cc (load_path::do_initialize): Start with sys_path empty.
+	(maybe_add_path_elts): Omit path_sep_str if path is empty.
+
+	* symtab.h (symbol_table::do_pop_context): Remove symbol_records
+	which have no more context.
+	(symbol_table::symbol_record::pop_context,
+	(symbol_table::symbol_record::symbol_record_rep::pop_context):
+	Return size of value_stack, or 1 if variable is persistent or global.
+
 2008-01-14  Kai Habel  <kai.habel@gmx.de>
 
 	* graphics.h.in (class patch::properties): New properties:
--- a/src/load-path.cc	Mon Jan 14 20:12:42 2008 +0000
+++ b/src/load-path.cc	Tue Jan 15 00:50:50 2008 +0000
@@ -408,13 +408,18 @@
   std::string tpath = genpath (dir);
 
   if (! tpath.empty ())
-    path += dir_path::path_sep_str + tpath;
+    {
+      if (path.empty ())
+	path = tpath;
+      else
+	path += dir_path::path_sep_str + tpath;
+    }
 }
 
 void
 load_path::do_initialize (bool set_initial_path)
 {
-  sys_path = dir_path::path_sep_str;
+  sys_path = "";
 
   if (set_initial_path)
     {
@@ -438,7 +443,7 @@
   if (! tpath.empty ())
     xpath += dir_path::path_sep_str + tpath;
 
-  if (sys_path != dir_path::path_sep_str)
+  if (! sys_path.empty ())
     xpath += sys_path;
 
   do_set (xpath, false);
--- a/src/symtab.h	Mon Jan 14 20:12:42 2008 +0000
+++ b/src/symtab.h	Tue Jan 15 00:50:50 2008 +0000
@@ -93,7 +93,11 @@
 
       void push_context (void) { value_stack.push (octave_value ()); }
 
-      void pop_context (void) { value_stack.pop (); }
+      size_t pop_context (void)
+      {
+	value_stack.pop ();
+	return value_stack.size ();
+      }
 
       void clear (void)
       {
@@ -254,10 +258,23 @@
 	rep->push_context ();
     }
 
-    void pop_context (void)
+    // If pop_context returns 0, we are out of values and this element
+    // of the symbol table should be deleted.  This can happen for
+    // functions like
+    //
+    //   function foo (n)
+    //     if (n > 0)
+    //       foo (n-1);
+    //     else
+    //       eval ("x = 1");
+    //     endif
+    //   endfunction
+    //
+    // Here, X should only exist in the final stack frame.
+
+    size_t pop_context (void)
     {
-      if (! (is_persistent () || is_global ()))
-	rep->pop_context ();
+      return (is_persistent () || is_global ()) ? 1 : rep->pop_context ();
     }
 
     void clear (void) { rep->clear (); }
@@ -1618,8 +1635,13 @@
 
   void do_pop_context (void)
   {
-    for (table_iterator p = table.begin (); p != table.end (); p++)
-      p->second.pop_context ();
+    for (table_iterator p = table.begin (); p != table.end (); )
+      {
+	if (p->second.pop_context () == 0)
+	  table.erase (p++);
+	else
+	  p++;
+      }
   }
 
   void do_clear_variables (void)