changeset 26525:0d3eca5955dc stable

Backed out changeset 920a4ad8043b (bug #54995)
author John W. Eaton <jwe@octave.org>
date Sat, 12 Jan 2019 08:09:02 -0500
parents 027f3c884763
children 75c7aafca6bb
files libinterp/octave-value/ov-base.cc libinterp/octave-value/ov-base.h libinterp/octave-value/ov-class.cc libinterp/octave-value/ov-classdef.cc
diffstat 4 files changed, 27 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-base.cc	Fri Jan 11 21:57:36 2019 -0500
+++ b/libinterp/octave-value/ov-base.cc	Sat Jan 12 08:09:02 2019 -0500
@@ -1461,6 +1461,22 @@
   return m;
 }
 
+bool
+called_from_builtin (void)
+{
+  octave::call_stack& cs = octave::__get_call_stack__ ("called_from_builtin");
+
+  octave_function *fcn = cs.caller ();
+
+  // FIXME: we probably need a better check here, or some other
+  // mechanism to avoid overloaded functions when builtin is used.
+  // For example, what if someone overloads the builtin function?
+  // Also, are there other places where using builtin is not properly
+  // avoiding dispatch?
+
+  return (fcn && fcn->name () == "builtin");
+}
+
 void
 install_base_type_conversions (octave::type_info& ti)
 {
--- a/libinterp/octave-value/ov-base.h	Fri Jan 11 21:57:36 2019 -0500
+++ b/libinterp/octave-value/ov-base.h	Sat Jan 12 08:09:02 2019 -0500
@@ -888,4 +888,8 @@
                const std::list<octave_value_list>& idx,
                const std::string& who);
 
+// Tells whether some regular octave_value_base methods are being called from
+// within the "builtin" function.
+extern OCTINTERP_API bool called_from_builtin (void);
+
 #endif
--- a/libinterp/octave-value/ov-class.cc	Fri Jan 11 21:57:36 2019 -0500
+++ b/libinterp/octave-value/ov-class.cc	Sat Jan 12 08:09:02 2019 -0500
@@ -294,7 +294,7 @@
 Matrix
 octave_class::size (void)
 {
-  if (in_class_method ())
+  if (in_class_method () || called_from_builtin ())
     return octave_base_value::size ();
 
   Matrix retval (1, 2, 1.0);
@@ -334,7 +334,7 @@
 octave_idx_type
 octave_class::numel (const octave_value_list& idx)
 {
-  if (in_class_method ())
+  if (in_class_method () || called_from_builtin ())
     return octave_base_value::numel (idx);
 
   octave_idx_type retval = -1;
@@ -374,7 +374,7 @@
 {
   octave_value_list retval;
 
-  if (in_class_method ())
+  if (in_class_method () || called_from_builtin ())
     {
       // FIXME: this block of code is the same as the body of
       // octave_struct::subsref.  Maybe it could be shared instead of
@@ -535,7 +535,7 @@
 {
   octave_value retval;
 
-  if (! in_class_method ())
+  if (! (in_class_method () || called_from_builtin ()))
     {
       octave::symbol_table& symtab
         = octave::__get_symbol_table__ ("octave_class::subsasgn_common");
--- a/libinterp/octave-value/ov-classdef.cc	Fri Jan 11 21:57:36 2019 -0500
+++ b/libinterp/octave-value/ov-classdef.cc	Sat Jan 12 08:09:02 2019 -0500
@@ -865,7 +865,7 @@
 
   cdef_class cls = object.get_class ();
 
-  if (! in_class_method (cls))
+  if (! in_class_method (cls) && ! called_from_builtin ())
     {
       cdef_method meth = cls.find_method ("subsref");
 
@@ -924,7 +924,7 @@
 
   cdef_class cls = object.get_class ();
 
-  if (! in_class_method (cls))
+  if (! in_class_method (cls) && ! called_from_builtin ())
     {
       cdef_method meth = cls.find_method ("subsasgn");
 
@@ -979,7 +979,7 @@
 
   cdef_class cls = object.get_class ();
 
-  if (! in_class_method (cls))
+  if (! in_class_method (cls) && ! called_from_builtin ())
     {
       cdef_method meth = cls.find_method ("numel");