changeset 28435:76a9f31540e3 stable

try harder to find functions in some symbol_table find_* functions * symtab.cc (symbol_table::find_built_in_function, symbol_table::find_autoload, symbol_table::find_user_function, symbol_table::find_cmdline_function): Create a fcn_info object and search again if function is not already cached in m_fcn_table.
author John W. Eaton <jwe@octave.org>
date Tue, 12 May 2020 12:43:42 -0400
parents 48c1e8d88ea2
children 22e90bdcf47f
files libinterp/corefcn/symtab.cc
diffstat 1 files changed, 52 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/symtab.cc	Fri May 01 12:54:30 2020 -0400
+++ b/libinterp/corefcn/symtab.cc	Tue May 12 12:43:42 2020 -0400
@@ -101,8 +101,19 @@
   {
     fcn_table_const_iterator p = m_fcn_table.find (name);
 
-    return (p != m_fcn_table.end ()
-            ? p->second.find_built_in_function () : octave_value ());
+    if (p != m_fcn_table.end ())
+      return p->second.find_built_in_function ();
+    else
+      {
+        fcn_info finfo (name);
+
+        octave_value fcn = finfo.find_built_in_function ();
+
+        if (fcn.is_defined ())
+          m_fcn_table[name] = finfo;
+
+        return fcn;
+      }
   }
 
   octave_value symbol_table::find_autoload (const std::string& name)
@@ -112,8 +123,19 @@
 
     auto p = m_fcn_table.find (name);
 
-    return (p != m_fcn_table.end ()
-            ? p->second.find_autoload () : octave_value ());
+    if (p != m_fcn_table.end ())
+      return p->second.find_autoload ();
+    else
+      {
+        fcn_info finfo (name);
+
+        octave_value fcn = finfo.find_autoload ();
+
+        if (fcn.is_defined ())
+          m_fcn_table[name] = finfo;
+
+        return fcn;
+      }
   }
 
   octave_value
@@ -222,8 +244,19 @@
 
     auto p = m_fcn_table.find (name);
 
-    return (p != m_fcn_table.end ()
-            ? p->second.find_user_function () : octave_value ());
+    if (p != m_fcn_table.end ())
+      return p->second.find_user_function ();
+    else
+      {
+        fcn_info finfo (name);
+
+        octave_value fcn = finfo.find_user_function ();
+
+        if (fcn.is_defined ())
+          m_fcn_table[name] = finfo;
+
+        return fcn;
+      }
   }
 
   octave_value symbol_table::find_cmdline_function (const std::string& name)
@@ -233,8 +266,19 @@
 
     auto p = m_fcn_table.find (name);
 
-    return (p != m_fcn_table.end ()
-            ? p->second.find_cmdline_function () : octave_value ());
+    if (p != m_fcn_table.end ())
+      return p->second.find_cmdline_function ();
+    else
+      {
+        fcn_info finfo (name);
+
+        octave_value fcn = finfo.find_cmdline_function ();
+
+        if (fcn.is_defined ())
+          m_fcn_table[name] = finfo;
+
+        return fcn;
+      }
   }
 
   void symbol_table::install_cmdline_function (const std::string& name,