changeset 15572:859c8bf6d134

Fix saved struct with function handle fails to load (bug #33857) * ov-fcn-handle.cc: Add test. * symtab.h (symbol_table::all_variables, symbol_table::do_all_variables): Support excluding storage classes.
author Max Brister <max@2bass.com>
date Tue, 30 Oct 2012 22:14:05 -0700
parents 7b9551c65b7b
children d20cbfec6df7 6ea536cb7360
files libinterp/interpfcn/symtab.h libinterp/octave-value/ov-fcn-handle.cc
diffstat 2 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/interpfcn/symtab.h	Tue Oct 30 22:10:26 2012 -0700
+++ b/libinterp/interpfcn/symtab.h	Tue Oct 30 22:14:05 2012 -0700
@@ -1772,15 +1772,18 @@
       inst->do_mark_global (name);
   }
 
+  // exclude: Storage classes to exclude, you can OR them together
   static std::list<symbol_record>
   all_variables (scope_id scope = xcurrent_scope,
                  context_id context = xdefault_context,
-                 bool defined_only = true)
+                 bool defined_only = true,
+                 unsigned int exclude = symbol_record::hidden)
   {
     symbol_table *inst = get_instance (scope);
 
     return inst
-      ? inst->do_all_variables (context, defined_only) : std::list<symbol_record> ();
+      ? inst->do_all_variables (context, defined_only, exclude)
+      : std::list<symbol_record> ();
   }
 
   static std::list<symbol_record> glob (const std::string& pattern)
@@ -2538,7 +2541,8 @@
   }
 
   std::list<symbol_record>
-  do_all_variables (context_id context, bool defined_only) const
+  do_all_variables (context_id context, bool defined_only,
+                    unsigned int exclude) const
   {
     std::list<symbol_record> retval;
 
@@ -2546,7 +2550,8 @@
       {
         const symbol_record& sr = p->second;
 
-        if (defined_only && ! sr.is_defined (context))
+        if ((defined_only && ! sr.is_defined (context))
+            || (sr.xstorage_class () & exclude))
           continue;
 
         retval.push_back (sr);
--- a/libinterp/octave-value/ov-fcn-handle.cc	Tue Oct 30 22:10:26 2012 -0700
+++ b/libinterp/octave-value/ov-fcn-handle.cc	Tue Oct 30 22:14:05 2012 -0700
@@ -1311,6 +1311,7 @@
 %!   mode = modes{i};
 %!   nm = tmpnam ();
 %!   unwind_protect
+%!     f2 (1); # bug #33857
 %!     save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2");
 %!     clear f2 g2 hm2 hdld2 hbi2
 %!     load (nm);