# HG changeset patch # User Max Brister # Date 1343044389 18000 # Node ID 1f5dbfc23fc2c61b29d1594ba0cb8399c77b699d # Parent 3172d791615890f9fe3ee645e8545907e208f2b2 'clear -f' does not work for command line functions (bug #34497) * src/symtab.cc: Added a test case for bug 34497. * src/symtab.h (fcn_info::fcn_info_rep::clear_cmdline_function): Removed method. (fcn_info::fcn_info_rep::clear_user_function): Also clear cmdline function. (fcn_info::fcn_info_rep::clear): Do not call clear_cmdline_function. diff --git a/src/symtab.cc b/src/symtab.cc --- a/src/symtab.cc +++ b/src/symtab.cc @@ -1713,3 +1713,32 @@ return retval; } #endif + + +/* +bug #34497: 'clear -f' does not work for command line functions + +This test relies on bar being a core function that is implemented in an m-file. +If the first assert fails, this is no longer the case and the tests need to be +updated to use some other function. + +%!assert (! strcmp (which ("bar"), "")); + +%!function x = bar () +%! x = 5; +%!endfunction +%!test +%! assert (bar == 5); +%! assert (strcmp (which ("bar"), "")); +%! clear -f bar; +%! assert (! strcmp (which ("bar"), "")); + +%!function x = bar () +%! x = 5; +%!endfunction +%!test +%! assert (bar == 5); +%! assert (strcmp (which ("bar"), "")); +%! clear bar; +%! assert (! strcmp (which ("bar"), "")); + */ diff --git a/src/symtab.h b/src/symtab.h --- a/src/symtab.h +++ b/src/symtab.h @@ -768,20 +768,14 @@ } } - void clear_cmdline_function (void) - { - if (! cmdline_function.islocked ()) - cmdline_function = octave_value (); - } - void clear_autoload_function (void) { if (! autoload_function.islocked ()) autoload_function = octave_value (); } - // FIXME -- should this also clear the cmdline and other "user - // defined" functions? + // We also clear command line functions here, as these are both + // "user defined" void clear_user_function (void) { if (! function_on_path.islocked ()) @@ -790,6 +784,9 @@ function_on_path = octave_value (); } + + if (! cmdline_function.islocked ()) + cmdline_function = octave_value (); } void clear_mex_function (void) @@ -804,7 +801,6 @@ clear_unlocked (private_functions); clear_unlocked (class_constructors); clear_unlocked (class_methods); - clear_cmdline_function (); clear_autoload_function (); clear_user_function (); }