changeset 26883:a2aed4b49be3

fix const-ness of feval arguments * parse.h, oct-parse.yy (feval (const char *...)): New overload. (feval (const octave_value&...)): Declare first arg const.
author John W. Eaton <jwe@octave.org>
date Sat, 09 Mar 2019 10:25:11 +0000
parents 6e019db9c0a6
children e201cf0c7360
files libinterp/parse-tree/oct-parse.yy libinterp/parse-tree/parse.h
diffstat 2 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.yy	Mon Mar 11 11:49:24 2019 -0700
+++ b/libinterp/parse-tree/oct-parse.yy	Sat Mar 09 10:25:11 2019 +0000
@@ -5170,6 +5170,12 @@
   //!         necessarily the same as @c nargout.
 
   octave_value_list
+  feval (const char *name, const octave_value_list& args, int nargout)
+  {
+    return feval (std::string (name), args, nargout);
+  }
+
+  octave_value_list
   feval (const std::string& name, const octave_value_list& args, int nargout)
   {
     octave_value_list retval;
@@ -5208,7 +5214,7 @@
   }
 
   octave_value_list
-  feval (octave_value& val, const octave_value_list& args, int nargout)
+  feval (const octave_value& val, const octave_value_list& args, int nargout)
   {
     if (val.is_function ())
       {
@@ -5222,7 +5228,14 @@
         std::list<octave_value_list> arg_list;
         arg_list.push_back (args);
 
-        return val.subsref ("(", arg_list, nargout);
+        // FIXME: could we make octave_value::subsref a const method?
+        // It would be difficult because there are instances of
+        // incrementing the reference count inside subsref methods,
+        // which means they can't be const with the current way of
+        // handling reference counting.
+
+        octave_value xval = val;
+        return xval.subsref ("(", arg_list, nargout);
       }
     else if (val.is_string ())
       {
--- a/libinterp/parse-tree/parse.h	Mon Mar 11 11:49:24 2019 -0700
+++ b/libinterp/parse-tree/parse.h	Sat Mar 09 10:25:11 2019 +0000
@@ -564,6 +564,11 @@
                const std::string& warn_for = "");
 
   extern OCTINTERP_API octave_value_list
+  feval (const char *name,
+         const octave_value_list& args = octave_value_list (),
+         int nargout = 0);
+
+  extern OCTINTERP_API octave_value_list
   feval (const std::string& name,
          const octave_value_list& args = octave_value_list (),
          int nargout = 0);
@@ -574,7 +579,7 @@
          int nargout = 0);
 
   extern OCTINTERP_API octave_value_list
-  feval (octave_value& val,
+  feval (const octave_value& val,
          const octave_value_list& args = octave_value_list (),
          int nargout = 0);