diff libinterp/octave-value/cdef-class.cc @ 26847:8bd9fd99c12a

lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802) * ov-fcn-handle.h, ov-fcn-handle.cc (octave_fcn_handle::has_overloads, octave_fcn_handle::builtin_overloads, octave_fcn_handle::overloads): Delete member variables and all uses. (octave_fcn_handle::set_overload, octave_fcn_handle::set_overload, octave_fcn_handle::builtin_type, octave_fcn_handle::is_overloaded): Delete. (octave_fcn_handle::m_scope): New member variable. Store scop where handle is created along with function name to allow proper lookup and overload resolution. (octave_fcn_handle::m_generic_fcn): New member variable. (octave_fcn_handle::function_value, octave_fcn_handle::user_function_value): Store octave_value object containing discovered function in m_generic_fcn so we can safely return a pointer to the underlying function object. (make_fcn_handle, octave_fcn_handle::subsref): Greatly simplify. * pt-eval.cc (tree_evaluator::execute_user_function): Push closure context for any handle created inside a nested function or parent of a nested function. * cellfun.cc (Fcellfun): Eliminate special checks for "overloaded" function handles. * graphics.cc (gh_manager::do_execute_callback): If callback is a function handle, pass it directly to feval instead of extracting function value from it first. * cdef-class.cc (make_fcn_handle): Accept interpreter as argument. Change all uses. Create octave_fcn_handle object with current scope.
author John W. Eaton <jwe@octave.org>
date Tue, 05 Mar 2019 22:30:09 +0000
parents 568c2ab2782d
children 71724787d972
line wrap: on
line diff
--- a/libinterp/octave-value/cdef-class.cc	Tue Mar 05 07:32:38 2019 +0000
+++ b/libinterp/octave-value/cdef-class.cc	Tue Mar 05 22:30:09 2019 +0000
@@ -56,12 +56,19 @@
 namespace octave
 {
   static octave_value
-  make_fcn_handle (const octave_value& fcn, const std::string& nm)
+  make_fcn_handle (interpreter& interp, const octave_value& fcn,
+                   const std::string& nm)
   {
     octave_value retval;
 
     if (fcn.is_defined ())
-      retval = octave_value (new octave_fcn_handle (fcn, nm));
+      {
+        tree_evaluator& tw = interp.get_evaluator ();
+
+        symbol_scope curr_scope = tw.get_current_scope ();
+
+        retval = octave_value (new octave_fcn_handle (curr_scope, fcn, nm));
+      }
 
     return retval;
   }
@@ -946,10 +953,12 @@
 
                     if (mprefix == "get.")
                       get_methods[mname.substr (4)] =
-                        make_fcn_handle (mtd, full_class_name + '>' + mname);
+                        make_fcn_handle (interp, mtd,
+                                         full_class_name + '>' + mname);
                     else if (mprefix == "set.")
                       set_methods[mname.substr (4)] =
-                        make_fcn_handle (mtd, full_class_name + '>' + mname);
+                        make_fcn_handle (interp, mtd,
+                                         full_class_name + '>' + mname);
                     else
                       {
                         cdef_method meth = cdm.make_method (retval, mname, mtd);