Mercurial > hg > octave-avbm
changeset 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 | 14b841c47a5f |
children | 95dce69538ec |
files | src/ChangeLog src/dynamic-ld.cc src/ov-fcn-handle.cc src/symtab.cc |
diffstat | 4 files changed, 130 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,15 @@ 2008-04-30 John W. Eaton <jwe@octave.org> + * dynamic-ld.cc (octave_dynamic_loader::do_load_oct): + If function already exists, reload it anyway. Clear existing + oct_file only if reloading a function from the same file. + (octave_shlib_list::display): New static function. + (octave_shlib_list::do_display): New function. + + * symtab.cc (out_of_date_check_internal): Better handling for + functions found in files by relative file names. + (load_out_of_date_fcn): New function. + * ls-oct-ascii.cc (extract_keyword): Return early if first char is not a comment character. (read_ascii_data): Accept .nargin. and .nargout. as valid identifiers.
--- a/src/dynamic-ld.cc +++ b/src/dynamic-ld.cc @@ -58,6 +58,8 @@ static void *search (const std::string& fcn_name, octave_shlib& shl, octave_shlib::name_mangler mangler = 0); + static void display (void); + private: octave_shlib_list (void) { } @@ -71,6 +73,8 @@ void *do_search (const std::string& fcn_name, octave_shlib& shl, octave_shlib::name_mangler mangler = 0); + void do_display (void) const; + static octave_shlib_list *instance; static bool instance_ok (void); @@ -137,6 +141,15 @@ return function; } +void +octave_shlib_list::do_display (void) const +{ + std::cerr << "current shared libraries:" << std::endl; + for (std::list<octave_shlib>::const_iterator p = lib_list.begin (); + p != lib_list.end (); p++) + std::cerr << " " << p->file_name () << std::endl; +} + bool octave_shlib_list::instance_ok (void) { @@ -177,6 +190,13 @@ return (instance_ok ()) ? instance->do_search (fcn_name, shl, mangler) : 0; } +void +octave_shlib_list::display (void) +{ + if (instance_ok ()) + instance->do_display (); +} + class octave_mex_file_list { @@ -332,55 +352,66 @@ if (! error_state) { - if (function - && (! same_file (file_name, oct_file.file_name ()) - || oct_file.is_out_of_date ())) + bool reloading = false; + + if (function) { - clear (oct_file); + // If there is already a function by this name installed + // from the same file, clear the file so we can reload it. + + // If there is already a function by this name installed + // from a different file, leave the other file alone and + // load the function from the new file. + + reloading = same_file (file_name, oct_file.file_name ()); + + if (reloading) + clear (oct_file); + function = 0; } - if (! function) - { - std::string oct_file_name = file_name; + if (! reloading) + oct_file = octave_shlib (); + + std::string oct_file_name = file_name; - if (oct_file_name.empty ()) - { - oct_file_name = oct_file_in_path (fcn_name); + if (oct_file_name.empty ()) + { + oct_file_name = oct_file_in_path (fcn_name); + + if (! oct_file_name.empty ()) + relative = ! octave_env::absolute_pathname (oct_file_name); + } - if (! oct_file_name.empty ()) - relative = ! octave_env::absolute_pathname (oct_file_name); - } - - if (oct_file_name.empty ()) + if (oct_file_name.empty ()) + { + if (oct_file.is_relative ()) { - if (oct_file.is_relative ()) + // Can't see this function from current + // directory, so we should clear it. + clear (oct_file); + function = 0; + } + } + else + { + oct_file.open (oct_file_name); + + if (! error_state) + { + if (oct_file) { - // Can't see this function from current - // directory, so we should clear it. - clear (oct_file); - function = 0; + if (relative) + oct_file.mark_relative (); + + octave_shlib_list::append (oct_file); + + function = oct_file.search (fcn_name, xmangle_name); } - } - else - { - oct_file.open (oct_file_name); - - if (! error_state) - { - if (oct_file) - { - if (relative) - oct_file.mark_relative (); - - octave_shlib_list::append (oct_file); - - function = oct_file.search (fcn_name, xmangle_name); - } - else - ::error ("%s is not a valid shared library", - oct_file_name.c_str ()); - } + else + ::error ("%s is not a valid shared library", + oct_file_name.c_str ()); } } }
--- a/src/ov-fcn-handle.cc +++ b/src/ov-fcn-handle.cc @@ -116,10 +116,10 @@ { bool success = true; - if (octaveroot.length () != 0 && - fpath.length () >= octaveroot.length () && - fpath.substr (0, octaveroot.length ()) == octaveroot && - OCTAVE_EXEC_PREFIX != octaveroot) + if (octaveroot.length () != 0 + && fpath.length () >= octaveroot.length () + && fpath.substr (0, octaveroot.length ()) == octaveroot + && OCTAVE_EXEC_PREFIX != octaveroot) { // First check if just replacing matlabroot is enough std::string str = OCTAVE_EXEC_PREFIX + @@ -1077,7 +1077,7 @@ %! f = @(x) a + x; %! g = @(x) 2 * x; %! hm = @flops; -%! hdld = @time; +%! hdld = @svd; %! hbi = @log2; %! f2 = f; %! g2 = g;
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -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); + } } } }