changeset 18316:ff311e5ff6d8

Don't call classdef-overloaded subsref from builtin calls. * ov-class.cc (called_from_builtin): Moved to ov-base.cc. * ov-base.cc (called_from_builtin): Moved from ov-class.cc. * ov-base.h (called_from_builtin): Declare in octave API. * ov-classdef.cc (octave_classdef::subsref): Don't call overloaded subsref when called from "builtin".
author Michael Goffioul <michael.goffioul@gmail.com>
date Mon, 20 Jan 2014 22:16:22 -0500
parents 06eb893b9db6
children 0187ed948627
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, 20 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-base.cc	Mon Jan 20 14:10:42 2014 -0500
+++ b/libinterp/octave-value/ov-base.cc	Mon Jan 20 22:16:22 2014 -0500
@@ -52,6 +52,7 @@
 #include "parse.h"
 #include "pr-output.h"
 #include "utils.h"
+#include "toplev.h"
 #include "variables.h"
 
 builtin_type_t btyp_mixed_numeric (builtin_type_t x, builtin_type_t y)
@@ -1627,6 +1628,20 @@
   return retval;
 }
 
+bool
+called_from_builtin (void)
+{
+  octave_function *fcn = octave_call_stack::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 (void)
 {
--- a/libinterp/octave-value/ov-base.h	Mon Jan 20 14:10:42 2014 -0500
+++ b/libinterp/octave-value/ov-base.h	Mon Jan 20 22:16:22 2014 -0500
@@ -836,4 +836,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	Mon Jan 20 14:10:42 2014 -0500
+++ b/libinterp/octave-value/ov-class.cc	Mon Jan 20 22:16:22 2014 -0500
@@ -307,20 +307,6 @@
   return retval;
 }
 
-static bool
-called_from_builtin (void)
-{
-  octave_function *fcn = octave_call_stack::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");
-}
-
 Matrix
 octave_class::size (void)
 {
--- a/libinterp/octave-value/ov-classdef.cc	Mon Jan 20 14:10:42 2014 -0500
+++ b/libinterp/octave-value/ov-classdef.cc	Mon Jan 20 22:16:22 2014 -0500
@@ -895,7 +895,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");