diff libinterp/corefcn/ls-oct-text.cc @ 28427:7a8c69c4eb55 stable

convert obsolete octave_fcn_inline object to @inline class Use a legacy @class object to provide inline function objects instead of using a built-in class derived from the octave_function_handle class. * scripts/legacy/@inline: New directory containing the following files: argnames.m, char.m, feval.m, formula.m, inline.m, subsref.m, vectorize.m. * scripts/legacy/@inline/module.mk: New file. * scripts/legacy/module.mk, scripts/module.mk: Update. * test/inline-fcn.tst: New tests. * test/module.mk: Update. * ov-fcn-inline.h, ov-fcn-inline.cc: Delete. Remove all uses. * libinterp/octave-value/module.mk: Update. * external.txi, func.txi, octave.texi, plot.txi, quad.txi: Eliminate discusion of inline function objects. * fplot.m, __ezplot__.m: Use isa to identify inline objects instead of instead of checking typeinfo. * ov-fcn-handle.cc, ov-typeinfo.cc: Fix tests. * ov-base.h, ov-base.cc (octave_base_value::fcn_inline_value): Delete. * ov.h, ov.cc (octave_value::fcn_inline_value): Delete. (octave_value::xfcn_inline_value): Delete value extractor. * ov-class.cc, ov-class.h (octave_inline, octave_inline_fcn): New classes that allow us to preserve the is_inline_function and function_value methods that were previously available in the octave_fcn_inline class. (F__inline_ctor__): New function for final construction of inline objects. * ls-hdf5.cc, ls-mat5.cc, ls-oct-binary.cc, ls-oct-text.cc: Handle loading of inline function objects from old files as special cases. New inline function objects will be saved and loaded as ordinary @class objects.
author John W. Eaton <jwe@octave.org>
date Mon, 23 Mar 2020 15:29:49 -0400
parents bea3f8f96f7a
children 0a5b15007766
line wrap: on
line diff
--- a/libinterp/corefcn/ls-oct-text.cc	Sat Apr 25 13:17:11 2020 -0400
+++ b/libinterp/corefcn/ls-oct-text.cc	Mon Mar 23 15:29:49 2020 -0400
@@ -52,6 +52,7 @@
 #include "defun.h"
 #include "error.h"
 #include "errwarn.h"
+#include "interpreter.h"
 #include "interpreter-private.h"
 #include "load-save.h"
 #include "ls-ascii-helper.h"
@@ -235,6 +236,53 @@
 
 #define SUBSTRING_COMPARE_EQ(s, pos, n, t) (s.substr (pos, n) == (t))
 
+static octave_value
+load_inline_fcn (std::istream& is, const std::string& filename)
+{
+  int nargs;
+  if (extract_keyword (is, "nargs", nargs, true))
+    {
+      std::string name;
+      octave_value_list args (nargs+1);
+      for (int i = 0; i < nargs; i++)
+        {
+          std::string tmp;
+          is >> tmp;
+          args(i+1) = tmp;
+        }
+      is >> name;
+      if (name == "0")
+        name = "";
+
+      skip_preceeding_newline (is);
+
+      std::string buf;
+
+      if (is)
+        {
+
+          // Get a line of text whitespace characters included,
+          // leaving newline in the stream.
+          buf = read_until_newline (is, true);
+        }
+
+      if (is)
+        {
+          args(0) = std::string (buf);
+
+          octave::interpreter& interp
+            = octave::__get_interpreter__ ("load_inline_fcn");
+
+          octave_value_list tmp = interp.feval ("inline", args, 1);
+
+          if (tmp.length () > 0)
+            return tmp(0);
+        }
+    }
+
+  error ("load: trouble reading ascii file '%s'", filename.c_str ());
+}
+
 std::string
 read_text_data (std::istream& is, const std::string& filename, bool& global,
                 octave_value& tc, octave_idx_type count,
@@ -280,6 +328,12 @@
   // Special case for backward compatibility.  A small bit of cruft
   if (SUBSTRING_COMPARE_EQ (typ, 0, 12, "string array"))
     tc = charMatrix ();
+  else if (SUBSTRING_COMPARE_EQ (typ, 0, 15, "inline function"))
+    {
+      // Special case for loading old octave_inline_fcn objects.
+      tc = load_inline_fcn (is, filename);
+      return name;
+    }
   else
     {
       octave::type_info& type_info