changeset 23332:7d4ca8c01bbb

don't call display methods with more than one argument (bug #50640) * pt-output.cc (Fdisplay): Don't document two-argument syntax. * pt-assign.cc (tree_simple_assignment::rvalue1, tree_multi_assignment::rvalue): Call display with just one argument. * pt-id.cc (tree_identifier::rvalue): Likewise.
author John W. Eaton <jwe@octave.org>
date Wed, 29 Mar 2017 14:25:29 -0400
parents 665f0a73429a
children b636f10ce53f
files libinterp/corefcn/pr-output.cc libinterp/corefcn/variables.cc libinterp/parse-tree/pt-assign.cc libinterp/parse-tree/pt-id.cc
diffstat 4 files changed, 18 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.cc	Tue Mar 28 10:04:42 2017 -0700
+++ b/libinterp/corefcn/pr-output.cc	Wed Mar 29 14:25:29 2017 -0400
@@ -3599,9 +3599,7 @@
        classes: cell char double function_handle int8 int16 int32 int64 logical single struct uint8 uint16 uint32 uint64
        doc: /* -*- texinfo -*-
 @deftypefn  {} {} display (@var{obj})
-@deftypefnx {} {} display (@var{obj}, @var{name})
-Display the contents of the object @var{obj} prepended by it's assigned
-variable name @var{name}.
+Display the contents of the object @var{obj} prepended by its name.
 
 The Octave interpreter calls the @code{display} function whenever it needs
 to present a class on-screen.  Typically, this would be a statement which
@@ -3617,10 +3615,9 @@
 myobj = myclass (@dots{})
 @end example
 
-User-defined classes should overload the @code{display} method with two
-input arguments so that something useful is printed for a class object.
-Otherwise, Octave will report only that the object is an instance of its
-class.
+User-defined classes should overload the @code{display} method and use
+@code{inputname} to access the name of the object.  Otherwise, Octave
+will report only that the object is an instance of its class.
 
 @example
 @group
@@ -3634,21 +3631,26 @@
 {
   int nargin = args.length ();
 
+  // Matlab apparently accepts two arguments with the second set to the
+  // inputname of the first.  This is undocumented, but we'll use it.
+  // However, we never call display methods for classes with more than
+  // one argument.
+
   if (nargin < 1 || nargin > 2)
     print_usage ();
 
   std::string name;
 
   if (nargin == 2)
-    name = args(1).xstring_value ("CALLER must be a string");
+    name = args(1).xstring_value ("NAME must be a string");
   else
     {
       string_vector names = args.name_tags ();
       name = names(0);
     }
 
-  // Only reason we got here is that there was no overloaded display
-  // function.  Rely on built-in functions to display whatever obj is.
+  // We are here because there is no overloaded display method for this
+  // object type.
 
   octave_value value = args(0);
 
--- a/libinterp/corefcn/variables.cc	Tue Mar 28 10:04:42 2017 -0700
+++ b/libinterp/corefcn/variables.cc	Wed Mar 29 14:25:29 2017 -0400
@@ -1955,7 +1955,6 @@
             {
               octave_value_list args = ovl (val);
               args.stash_name_tags (string_vector (ans));
-
               octave::feval ("display", args);
             }
         }
--- a/libinterp/parse-tree/pt-assign.cc	Tue Mar 28 10:04:42 2017 -0700
+++ b/libinterp/parse-tree/pt-assign.cc	Wed Mar 29 14:25:29 2017 -0400
@@ -120,11 +120,8 @@
 
                 octave_value lhs_val = ult.value ();
 
-                octave_value_list args = ovl (lhs_val, lhs->name ());
-                string_vector name_tags (2);
-                name_tags(0) = lhs->name ();
-                name_tags(1) = "name";
-                args.stash_name_tags (name_tags);
+                octave_value_list args = ovl (lhs_val);
+                args.stash_name_tags (string_vector (lhs->name ()));
                 octave::feval ("display", args);
               }
           }
@@ -331,11 +328,8 @@
 
                 octave_value lhs_val = ult.value ();
 
-                octave_value_list args = ovl (lhs_val, lhs_elt->name ());
-                string_vector name_tags (2);
-                name_tags(0) = lhs_elt->name ();
-                name_tags(1) = "name";
-                args.stash_name_tags (name_tags);
+                octave_value_list args = ovl (lhs_val);
+                args.stash_name_tags (string_vector (lhs_elt->name ()));
                 octave::feval ("display", args);
               }
           }
--- a/libinterp/parse-tree/pt-id.cc	Tue Mar 28 10:04:42 2017 -0700
+++ b/libinterp/parse-tree/pt-id.cc	Wed Mar 29 14:25:29 2017 -0400
@@ -99,11 +99,8 @@
             if (print_result () && nargout == 0
                 && octave::tree_evaluator::statement_printing_enabled ())
               {
-                octave_value_list args = ovl (val, name ());
-                string_vector name_tags (2);
-                name_tags(0) = name ();
-                name_tags(1) = "name";
-                args.stash_name_tags (name_tags);
+                octave_value_list args = ovl (val);
+                args.stash_name_tags (string_vector (name ()));
                 octave::feval ("display", args);
               }