changeset 22999:f4781639f847

convert octave_shlib_list from singleton to ordinary object * dynamic-ld.h, dynamic-ld.cc (octave_dynamic_loader::loaded_shlibs_list): Rename from octave_shlib_list. Convert from singleton to ordinary object. Change all uses. (octave_dynamic_loader::loaded_shlibs): New data member. The octave_dynamic_loader object now owns the list of loaded shared libraries.
author John W. Eaton <jwe@octave.org>
date Wed, 04 Jan 2017 23:09:46 -0500
parents 4abd1ae61a79
children f981282a3bd0
files libinterp/corefcn/dynamic-ld.cc libinterp/corefcn/dynamic-ld.h
diffstat 2 files changed, 60 insertions(+), 116 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/dynamic-ld.cc	Thu Jan 05 11:06:27 2017 +0100
+++ b/libinterp/corefcn/dynamic-ld.cc	Wed Jan 04 23:09:46 2017 -0500
@@ -47,65 +47,17 @@
 #define STRINGIFY(s) STRINGIFY1(s)
 #define STRINGIFY1(s) #s
 
-class
-octave_shlib_list
-{
-public:
-
-  typedef std::list<octave::dynamic_library>::iterator iterator;
-  typedef std::list<octave::dynamic_library>::const_iterator const_iterator;
-
-  static void append (const octave::dynamic_library& shl);
-
-  static void remove (octave::dynamic_library& shl,
-                      octave::dynamic_library::close_hook cl_hook = 0);
-
-  static octave::dynamic_library find_file (const std::string& file_name);
-
-  static void display (void);
-
-private:
-
-  octave_shlib_list (void) : lib_list () { }
-
-  // No copying!
-
-  octave_shlib_list (const octave_shlib_list&) = delete;
-
-  octave_shlib_list& operator = (const octave_shlib_list&) = delete;
-
-  ~octave_shlib_list (void) = default;
-
-  void do_append (const octave::dynamic_library& shl);
-
-  void do_remove (octave::dynamic_library& shl,
-                  octave::dynamic_library::close_hook cl_hook = 0);
-
-  octave::dynamic_library do_find_file (const std::string& file_name) const;
-
-  void do_display (void) const;
-
-  static octave_shlib_list *instance;
-
-  static void cleanup_instance (void) { delete instance; instance = 0; }
-
-  static bool instance_ok (void);
-
-  // List of libraries we have loaded.
-  std::list<octave::dynamic_library> lib_list;
-};
-
-octave_shlib_list *octave_shlib_list::instance = 0;
-
 void
-octave_shlib_list::do_append (const octave::dynamic_library& shl)
+octave_dynamic_loader::loaded_shlibs_list::append
+  (const octave::dynamic_library& shl)
 {
   lib_list.push_back (shl);
 }
 
 void
-octave_shlib_list::do_remove (octave::dynamic_library& shl,
-                              octave::dynamic_library::close_hook cl_hook)
+octave_dynamic_loader::loaded_shlibs_list::remove
+  (octave::dynamic_library& shl,
+   octave::dynamic_library::close_hook cl_hook)
 {
   for (iterator p = lib_list.begin (); p != lib_list.end (); p++)
     {
@@ -123,7 +75,7 @@
 }
 
 octave::dynamic_library
-octave_shlib_list::do_find_file (const std::string& file_name) const
+octave_dynamic_loader::loaded_shlibs_list::find_file (const std::string& file_name) const
 {
   octave::dynamic_library retval;
 
@@ -140,61 +92,13 @@
 }
 
 void
-octave_shlib_list::do_display (void) const
+octave_dynamic_loader::loaded_shlibs_list::display (void) const
 {
   std::cerr << "current shared libraries:" << std::endl;
   for (const auto& lib : lib_list)
     std::cerr << "  " << lib.file_name () << std::endl;
 }
 
-bool
-octave_shlib_list::instance_ok (void)
-{
-  bool retval = true;
-
-  if (! instance)
-    {
-      instance = new octave_shlib_list ();
-
-      if (instance)
-        singleton_cleanup_list::add (cleanup_instance);
-    }
-
-  if (! instance)
-    error ("unable to create shared library list object!");
-
-  return retval;
-}
-
-void
-octave_shlib_list::append (const octave::dynamic_library& shl)
-{
-  if (instance_ok ())
-    instance->do_append (shl);
-}
-
-void
-octave_shlib_list::remove (octave::dynamic_library& shl,
-                           octave::dynamic_library::close_hook cl_hook)
-{
-  if (instance_ok ())
-    instance->do_remove (shl, cl_hook);
-}
-
-octave::dynamic_library
-octave_shlib_list::find_file (const std::string& file_name)
-{
-  return (instance_ok ())
-         ? instance->do_find_file (file_name) : octave::dynamic_library ();
-}
-
-void
-octave_shlib_list::display (void)
-{
-  if (instance_ok ())
-    instance->do_display ();
-}
-
 octave_dynamic_loader *octave_dynamic_loader::instance = 0;
 
 bool octave_dynamic_loader::doing_load = false;
@@ -226,8 +130,8 @@
   symbol_table::clear_dld_function (fcn_name);
 }
 
-static void
-clear (octave::dynamic_library& oct_file)
+void
+octave_dynamic_loader::do_clear (octave::dynamic_library& oct_file)
 {
   if (oct_file.number_of_functions_loaded () > 1)
     {
@@ -235,10 +139,10 @@
                        "reloading %s clears the following functions:",
                        oct_file.file_name ().c_str ());
 
-      octave_shlib_list::remove (oct_file, do_clear_function);
+      loaded_shlibs.remove (oct_file, do_clear_function);
     }
   else
-    octave_shlib_list::remove (oct_file, symbol_table::clear_dld_function);
+    loaded_shlibs.remove (oct_file, symbol_table::clear_dld_function);
 }
 
 octave_function *
@@ -254,17 +158,17 @@
 
   doing_load = true;
 
-  octave::dynamic_library oct_file = octave_shlib_list::find_file (file_name);
+  octave::dynamic_library oct_file = loaded_shlibs.find_file (file_name);
 
   if (oct_file && oct_file.is_out_of_date ())
-    clear (oct_file);
+    do_clear (oct_file);
 
   if (! oct_file)
     {
       oct_file.open (file_name);
 
       if (oct_file)
-        octave_shlib_list::append (oct_file);
+        loaded_shlibs.append (oct_file);
     }
 
   if (! oct_file)
@@ -308,17 +212,17 @@
 
   doing_load = true;
 
-  octave::dynamic_library mex_file = octave_shlib_list::find_file (file_name);
+  octave::dynamic_library mex_file = loaded_shlibs.find_file (file_name);
 
   if (mex_file && mex_file.is_out_of_date ())
-    clear (mex_file);
+    do_clear (mex_file);
 
   if (! mex_file)
     {
       mex_file.open (file_name);
 
       if (mex_file)
-        octave_shlib_list::append (mex_file);
+        loaded_shlibs.append (mex_file);
     }
 
   if (! mex_file)
@@ -368,7 +272,7 @@
       retval = shl.remove (fcn_name);
 
       if (shl.number_of_functions_loaded () == 0)
-        octave_shlib_list::remove (shl);
+        loaded_shlibs.remove (shl);
     }
 
   return retval;
@@ -388,7 +292,7 @@
       retval = shl.remove (fcn_name);
 
       if (shl.number_of_functions_loaded () == 0)
-        octave_shlib_list::remove (shl);
+        loaded_shlibs.remove (shl);
     }
 
   return retval;
--- a/libinterp/corefcn/dynamic-ld.h	Thu Jan 05 11:06:27 2017 +0100
+++ b/libinterp/corefcn/dynamic-ld.h	Wed Jan 04 23:09:46 2017 -0500
@@ -25,6 +25,7 @@
 
 #include "octave-config.h"
 
+#include <list>
 #include <string>
 
 #include "oct-shlib.h"
@@ -34,9 +35,44 @@
 class
 octave_dynamic_loader
 {
+private:
+
+  class
+  loaded_shlibs_list
+  {
+  public:
+
+    typedef std::list<octave::dynamic_library>::iterator iterator;
+    typedef std::list<octave::dynamic_library>::const_iterator const_iterator;
+
+    loaded_shlibs_list (void) : lib_list () { }
+
+    ~loaded_shlibs_list (void) = default;
+
+    void append (const octave::dynamic_library& shl);
+
+    void remove (octave::dynamic_library& shl,
+                 octave::dynamic_library::close_hook cl_hook = 0);
+
+    octave::dynamic_library find_file (const std::string& file_name) const;
+
+    void display (void) const;
+
+  private:
+
+    // No copying!
+
+    loaded_shlibs_list (const loaded_shlibs_list&) = delete;
+
+    loaded_shlibs_list& operator = (const loaded_shlibs_list&) = delete;
+
+    // List of libraries we have loaded.
+    std::list<octave::dynamic_library> lib_list;
+  };
+
 protected:
 
-  octave_dynamic_loader (void) { }
+  octave_dynamic_loader (void) : loaded_shlibs () { }
 
 public:
 
@@ -72,6 +108,8 @@
 
   static bool instance_ok (void);
 
+  void do_clear (octave::dynamic_library& oct_file);
+
   octave_function *
   do_load_oct (const std::string& fcn_name,
                const std::string& file_name = "",
@@ -90,6 +128,8 @@
 
 protected:
 
+  loaded_shlibs_list loaded_shlibs;
+
   static std::string name_mangler (const std::string& name);
 
   static std::string name_uscore_mangler (const std::string& name);