diff src/symtab.cc @ 7745:0ff0fc033f28

better handling of functions found by relative lookup
author John W. Eaton <jwe@octave.org>
date Wed, 30 Apr 2008 17:51:02 -0400
parents 3e450caf93f2
children 40c428ea3408
line wrap: on
line diff
--- a/src/symtab.cc	Wed Apr 30 14:32:41 2008 -0400
+++ b/src/symtab.cc	Wed Apr 30 17:51:02 2008 -0400
@@ -103,6 +103,26 @@
 // would not check for it when finding symbol definitions.
 
 static inline bool
+load_out_of_date_fcn (const std::string& ff, const std::string& dir_name,
+		      octave_value& function)
+{
+  bool retval = false;
+
+  octave_function *fcn = load_fcn_from_file (ff, dir_name);
+
+  if (fcn)
+    {
+      retval = true;
+
+      function = octave_value (fcn);
+    }
+  else
+    function = octave_value ();
+
+  return retval;
+}
+
+static inline bool
 out_of_date_check_internal (octave_value& function)
 {
   bool retval = false;
@@ -126,9 +146,6 @@
 	      if (tc < Vlast_prompt_time
 		  || (relative && tc < Vlast_chdir_time))
 		{
-		  octave_time ottp = fcn->time_parsed ();
-		  time_t tp = ottp.unix_time ();
-
 		  std::string nm = fcn->name ();
 
 		  int nm_len = nm.length ();
@@ -142,10 +159,16 @@
 			  || (nm_len > 2 && nm.substr (nm_len-4) == ".m")))
 		    file = nm;
 		  else
-		    // FIXME -- this lookup is not right since it doesn't
-		    // account for dispatch type.
-		    file = octave_env::make_absolute (load_path::find_fcn (nm, dir_name),
-						      octave_env::getcwd ());
+		    {
+		      // FIXME -- this lookup is not right since it doesn't
+		      // account for dispatch type.
+
+		      // We don't want to make this an absolute name,
+		      // because load_fcn_file looks at the name to
+		      // decide whether it came from a relative lookup.
+
+		      file = load_path::find_fcn (nm, dir_name);
+		    }
 
 		  if (file.empty ())
 		    {
@@ -156,6 +179,11 @@
 		    }
 		  else if (same_file (file, ff))
 		    {
+		      // Same file.  If it is out of date, then reload it.
+
+		      octave_time ottp = fcn->time_parsed ();
+		      time_t tp = ottp.unix_time ();
+
 		      fcn->mark_fcn_file_up_to_date (octave_time ());
 
 		      if (! (Vignore_function_time_stamp == 2
@@ -167,23 +195,20 @@
 			  if (fs)
 			    {
 			      if (fs.is_newer (tp))
-				{
-				  fcn = load_fcn_from_file (ff, dir_name);
-
-				  if (fcn)
-				    {
-				      retval = true;
-
-				      function = octave_value (fcn);
-				    }
-				  else
-				    function = octave_value ();
-				}				
+				retval = load_out_of_date_fcn (ff, dir_name,
+							       function);
 			    }
 			  else
 			    function = octave_value ();
 			}
 		    }
+		  else
+		    {
+		      // Not the same file, so load the new file in
+		      // place of the old.
+
+		      retval = load_out_of_date_fcn (file, dir_name, function);
+		    }
 		}
 	    }
 	}