changeset 9156:b2b8ed43b922

ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
author John W. Eaton <jwe@octave.org>
date Mon, 27 Apr 2009 14:22:15 -0400
parents ad20b967e1c9
children fce7315c1eee
files src/ChangeLog src/ov-class.cc
diffstat 2 files changed, 30 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sun Apr 26 22:19:57 2009 -0700
+++ b/src/ChangeLog	Mon Apr 27 14:22:15 2009 -0400
@@ -1,3 +1,10 @@
+2009-04-27  John W. Eaton  <jwe@octave.org>
+
+	* ov-class.cc (octave_class::dotref): Handle empty parent class.
+	(octave_class::get_current_method_class): Allow result to be empty.
+	(called_from_builtin): New static function.
+	(octave_class::subsref, octave_class::subsasgn): Use it.
+
 2009-04-23  John W. Eaton  <jwe@octave.org>
 
 	* ov-class.cc (Fclass): Check newly constructed classes against
--- a/src/ov-class.cc	Sun Apr 26 22:19:57 2009 -0700
+++ b/src/ov-class.cc	Mon Apr 27 14:22:15 2009 -0400
@@ -96,6 +96,8 @@
 static std::string
 get_current_method_class (void)
 {
+  std::string retval;
+
   // FIXME -- is there a better way to do this?
   octave_function *fcn = octave_call_stack::current ();
 
@@ -103,9 +105,10 @@
 
   size_t ipos = my_dir.find_last_of ("@");
 
-  assert (ipos != std::string::npos);
+  if (ipos != std::string::npos)
+    retval = my_dir.substr (ipos+1);
 
-  return my_dir.substr (ipos+1);
+  return retval;
 }
 
 static void
@@ -235,7 +238,8 @@
   // Find the class in which this method resides before attempting to access
   // the requested field.
 
-  octave_base_value *obvp = find_parent_class (method_class);
+  octave_base_value *obvp
+    = method_class.empty () ? 0 : find_parent_class (method_class);
 
   Octave_map my_map;
 
@@ -258,6 +262,20 @@
   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");
+}
+
 octave_value_list
 octave_class::subsref (const std::string& type,
 		       const std::list<octave_value_list>& idx,
@@ -265,7 +283,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
@@ -383,7 +401,7 @@
 {
   octave_value retval;
 
-  if (! in_class_method ())
+  if (! (in_class_method () || called_from_builtin ()))
     {
       octave_value meth = symbol_table::find_method ("subsasgn", class_name ());