changeset 23660:97c3223c17a6

stash directory name in classdef method objects (bug #45444, bug #51276) This change should allow private functions to be found from class methods. * ov-fcn.h (octave_function::stash_dir_name): Now virtual. * ov-classdef.h, ov-classdef.cc (octave_classdef_meta::stash_dir_name, cdef_meta_object::stash_dir_name, cdef_meta_object_rep::stash_dir_name, cdef_class::cdef_class_rep::stash_dir_name, cdef_method::cdef_method_rep::stash_dir_name): New methods. (cdef_class_rep::stash_dir_name): Also stash dir name in methods. Rename existing set_directory methods to stash_dir_name. Rename existing get_directory methods to dir_name.
author John W. Eaton <jwe@octave.org>
date Tue, 20 Jun 2017 17:31:52 -0400
parents 114691e86b99
children 21b2816820cf
files libinterp/octave-value/ov-classdef.cc libinterp/octave-value/ov-classdef.h libinterp/octave-value/ov-fcn.h
diffstat 3 files changed, 40 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-classdef.cc	Tue Jun 20 17:23:19 2017 -0400
+++ b/libinterp/octave-value/ov-classdef.cc	Tue Jun 20 17:31:52 2017 -0400
@@ -1019,6 +1019,8 @@
 
   octave_function * function_value (bool = false) { return this; }
 
+  void stash_dir_name (const std::string& dir) { object.stash_dir_name (dir); }
+
   octave_value_list
   subsref (const std::string& type,
            const std::list<octave_value_list>& idx,
@@ -2214,6 +2216,19 @@
 }
 
 void
+cdef_class::cdef_class_rep::stash_dir_name (const std::string& dir)
+{
+  directory = dir;
+
+  for (auto& it : method_map)
+    {
+      cdef_method& meth = it.second;
+
+      meth.stash_dir_name (dir);
+    }
+}
+
+void
 cdef_class::cdef_class_rep::delete_object (cdef_object obj)
 {
   method_iterator it = method_map.find ("delete");
@@ -3068,6 +3083,15 @@
   return false;
 }
 
+void
+cdef_method::cdef_method_rep::stash_dir_name (const std::string& dir)
+{
+  octave_function *fptr = function.function_value ();
+
+  if (fptr)
+    fptr->stash_dir_name (dir);
+}
+
 bool
 cdef_method::cdef_method_rep::check_access (void) const
 {
--- a/libinterp/octave-value/ov-classdef.h	Tue Jun 20 17:23:19 2017 -0400
+++ b/libinterp/octave-value/ov-classdef.h	Tue Jun 20 17:31:52 2017 -0400
@@ -10,7 +10,7 @@
 (at your option) any later version.
 
 Octave is distributed in the hope that it will be useful, but
-qWITHOUT ANY WARRANTY; without even the implied warranty of
+WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
@@ -538,6 +538,8 @@
 
   virtual bool is_package (void) const { return false; }
 
+  virtual void stash_dir_name (const std::string&) { }
+
   virtual octave_value_list
   meta_subsref (const std::string& /* type */,
                 const std::list<octave_value_list>& /* idx */,
@@ -598,6 +600,9 @@
   bool meta_accepts_postfix_index (char type) const
   { return get_rep ()->meta_accepts_postfix_index (type); }
 
+  void stash_dir_name (const std::string& dir)
+  { get_rep ()->stash_dir_name (dir); }
+
 private:
   cdef_meta_object_rep * get_rep (void)
   { return dynamic_cast<cdef_meta_object_rep *> (cdef_object::get_rep ()); }
@@ -651,9 +656,9 @@
 
     string_vector get_names (void);
 
-    void set_directory (const std::string& dir) { directory = dir; }
+    void stash_dir_name (const std::string& dir);
 
-    std::string get_directory (void) const { return directory; }
+    std::string dir_name (void) const { return directory; }
 
     void delete_object (cdef_object obj);
 
@@ -816,17 +821,17 @@
 
   bool is_sealed (void) const { return get_rep ()->is_sealed (); }
 
-  void set_directory (const std::string& dir)
-  { get_rep ()->set_directory (dir); }
+  void stash_dir_name (const std::string& dir)
+  { get_rep ()->stash_dir_name (dir); }
 
-  std::string get_directory (void) const
-  { return get_rep ()->get_directory (); }
+  std::string dir_name (void) const
+  { return get_rep ()->dir_name (); }
 
   std::string get_name (void) const
   { return get_rep ()->get_name (); }
 
   bool is_builtin (void) const
-  { return get_directory ().empty (); }
+  { return dir_name ().empty (); }
 
   void delete_object (cdef_object obj)
   { get_rep ()->delete_object (obj); }
@@ -1040,6 +1045,8 @@
 
     void set_function (const octave_value& fcn) { function = fcn; }
 
+    void stash_dir_name (const std::string& dir);
+
     bool check_access (void) const;
 
     bool is_external (void) const { return ! dispatch_type.empty (); }
--- a/libinterp/octave-value/ov-fcn.h	Tue Jun 20 17:23:19 2017 -0400
+++ b/libinterp/octave-value/ov-fcn.h	Tue Jun 20 17:31:52 2017 -0400
@@ -142,7 +142,7 @@
 
   std::string dir_name (void) const { return my_dir_name; }
 
-  void stash_dir_name (const std::string& dir) { my_dir_name = dir; }
+  virtual void stash_dir_name (const std::string& dir) { my_dir_name = dir; }
 
   void lock (void)
   {