changeset 15003:1f5dbfc23fc2

'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.
author Max Brister <max@2bass.com>
date Mon, 23 Jul 2012 06:53:09 -0500
parents 3172d7916158
children ea6997657614
files src/symtab.cc src/symtab.h
diffstat 2 files changed, 34 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/symtab.cc	Sun Jul 22 04:16:02 2012 +0200
+++ b/src/symtab.cc	Mon Jul 23 06:53:09 2012 -0500
@@ -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"), ""));
+ */
--- a/src/symtab.h	Sun Jul 22 04:16:02 2012 +0200
+++ b/src/symtab.h	Mon Jul 23 06:53:09 2012 -0500
@@ -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 ();
       }