changeset 25345:ce6f7a5cd68e

avoid global access of load path in interpreter class * interpreter.h, interpreter.cc (execute_pkg_add): Now a member function in the interpreter class. (interpreter::initialize_load_path): Use lambda expression to wrap interpreter::execute_pkg_add and set as load_path add_hook function.
author John W. Eaton <jwe@octave.org>
date Thu, 03 May 2018 01:51:04 -0400
parents 4d3ce214da32
children dd416c31761e
files libinterp/corefcn/interpreter.cc libinterp/corefcn/interpreter.h
diffstat 2 files changed, 20 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/interpreter.cc	Thu May 03 01:40:27 2018 -0400
+++ b/libinterp/corefcn/interpreter.cc	Thu May 03 01:51:04 2018 -0400
@@ -317,27 +317,6 @@
   return 0;
 }
 
-static void
-execute_pkg_add (const std::string& dir)
-{
-  std::string file_name = octave::sys::file_ops::concat (dir, "PKG_ADD");
-
-  octave::load_path& lp = octave::__get_load_path__ ("execute_pkg_add");
-
-  try
-    {
-      lp.execute_pkg_add (dir);
-    }
-  catch (const octave::interrupt_exception&)
-    {
-      octave::interpreter::recover_from_exception ();
-    }
-  catch (const octave::execution_exception&)
-    {
-      octave::interpreter::recover_from_exception ();
-    }
-}
-
 namespace octave
 {
   // Create an interpreter object and perform initialization up to the
@@ -604,7 +583,8 @@
         frame.add_method (m_load_path, &load_path::set_add_hook,
                           m_load_path.get_add_hook ());
 
-        m_load_path.set_add_hook (execute_pkg_add);
+        m_load_path.set_add_hook ([this] (const std::string& dir)
+                                  { this->execute_pkg_add (dir); });
 
         m_load_path.initialize (set_initial_path);
 
@@ -1307,4 +1287,20 @@
     disable_warning ("Octave:function-name-clash");
     disable_warning ("Octave:possible-matlab-short-circuit-operator");
   }
+
+  void interpreter::execute_pkg_add (const std::string& dir)
+  {
+    try
+      {
+        m_load_path.execute_pkg_add (dir);
+      }
+    catch (const octave::interrupt_exception&)
+      {
+        octave::interpreter::recover_from_exception ();
+      }
+    catch (const octave::execution_exception&)
+      {
+        octave::interpreter::recover_from_exception ();
+      }
+  }
 }
--- a/libinterp/corefcn/interpreter.h	Thu May 03 01:40:27 2018 -0400
+++ b/libinterp/corefcn/interpreter.h	Thu May 03 01:51:04 2018 -0400
@@ -295,6 +295,8 @@
     bool m_initialized;
 
     void maximum_braindamage (void);
+
+    void execute_pkg_add (const std::string& dir);
   };
 }