# HG changeset patch # User Jaroslav Hajek # Date 1265010513 -3600 # Node ID a9d6b860d9e593ee3729a843def48b390caf0a66 # Parent cb7d1b220f1cc029ec08a9987e116665654b90e5 warn when core functions are shadowed diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -0,0 +1,6 @@ +2010-02-01 Jaroslav Hajek + + * load-path.cc (load_path::add_to_fcn_map): Warn when core library or + built-in functions are being shadowed. + (load_path::do_add): Pass at_end to add_to_fcn_map, add_to_method_map. + diff --git a/src/load-path.cc b/src/load-path.cc --- a/src/load-path.cc +++ b/src/load-path.cc @@ -632,11 +632,11 @@ else dir_info_list.push_front (di); - add_to_fcn_map (di, true); + add_to_fcn_map (di, at_end); add_to_private_fcn_map (di); - add_to_method_map (di, true); + add_to_method_map (di, at_end); if (add_hook) add_hook (dir); @@ -1672,7 +1672,25 @@ if (at_end) file_info_list.push_back (fi); else - file_info_list.push_front (fi); + { + // Warn if a built-in or library function is being shadowed. + if (! file_info_list.empty ()) + { + file_info& old = file_info_list.front (); + if (sys_path.find (old.dir_name) != std::string::npos) + { + std::string fcn_path = file_ops::concat (dir_name, fname); + warning ("function %s shadows a core library function", fcn_path.c_str ()); + } + } + else if (symbol_table::is_built_in_function_name (base)) + { + std::string fcn_path = file_ops::concat (dir_name, fname); + warning ("function %s shadows a built-in function", fcn_path.c_str ()); + } + + file_info_list.push_front (fi); + } } else { # HG changeset patch # User Jaroslav Hajek # Date 1265017472 -3600 # Node ID c6b6ac67b8cbf4b9ee66596cd42c14ee31bc9008 # Parent cb7d1b220f1cc029ec08a9987e116665654b90e5 warn when core functions are shadowed diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -0,0 +1,10 @@ +2010-02-01 Jaroslav Hajek + + * load-path.cc (load_path::add_to_fcn_map): Warn when core library or + built-in functions are being shadowed. + (load_path::do_add): Pass at_end to add_to_fcn_map, add_to_method_map. + Don't abort when "." not yet included. + (load_path::do_clear): Don't append "." here. + (load_path::do_set): Always prepend "." here. + (load_path::initialize): Don't explicitly include "." here. + diff --git a/src/load-path.cc b/src/load-path.cc --- a/src/load-path.cc +++ b/src/load-path.cc @@ -500,13 +500,17 @@ if (tpath.empty ()) tpath = octave_env::getenv ("OCTAVE_PATH"); - std::string xpath = "."; + std::string xpath; if (! tpath.empty ()) - xpath += dir_path::path_sep_str () + tpath; - - if (! sys_path.empty ()) - xpath += dir_path::path_sep_str () + sys_path; + { + xpath = tpath; + + if (! sys_path.empty ()) + xpath += dir_path::path_sep_str () + sys_path; + } + else + xpath = sys_path; do_set (xpath, false); } @@ -518,8 +522,6 @@ fcn_map.clear (); private_fcn_map.clear (); method_map.clear (); - - do_append (".", false); } static std::list @@ -584,6 +586,9 @@ if (add_hook) add_hook (i->dir_name); } + + // Always prepend current directory. + do_prepend (".", warn); } void @@ -632,11 +637,11 @@ else dir_info_list.push_front (di); - add_to_fcn_map (di, true); + add_to_fcn_map (di, at_end); add_to_private_fcn_map (di); - add_to_method_map (di, true); + add_to_method_map (di, at_end); if (add_hook) add_hook (dir); @@ -658,8 +663,6 @@ if (i != dir_info_list.end ()) move (i, false); - else - panic_impossible (); } void @@ -1672,7 +1675,25 @@ if (at_end) file_info_list.push_back (fi); else - file_info_list.push_front (fi); + { + // Warn if a built-in or library function is being shadowed. + if (! file_info_list.empty ()) + { + file_info& old = file_info_list.front (); + if (sys_path.find (old.dir_name) != std::string::npos) + { + std::string fcn_path = file_ops::concat (dir_name, fname); + warning ("function %s shadows a core library function", fcn_path.c_str ()); + } + } + else if (symbol_table::is_built_in_function_name (base)) + { + std::string fcn_path = file_ops::concat (dir_name, fname); + warning ("function %s shadows a built-in function", fcn_path.c_str ()); + } + + file_info_list.push_front (fi); + } } else {