changeset 30749:076e19eac74a stable

allow deletion of dynamic_library objects to be delayed * oct-shlib.h, oct-shlib.cc (dynamic_library::delete_later): New function. (possibly_unreferenced_dynamic_libraries): New static object. (release_unreferenced_dynamic_libraries): New function. * interpreter.cc (interpreter::main_loop): Add release_unreferenced_dynamic_libraries as new event_hook. * pt-eval.cc (debugger::server_loop, tree_evaluator::server_loop): Also call release_unreferenced_dynamic_libraries in event loop.
author John W. Eaton <jwe@octave.org>
date Thu, 17 Feb 2022 22:21:03 -0500
parents e00154c0a71b
children b92316e295a2
files libinterp/corefcn/interpreter.cc libinterp/parse-tree/pt-eval.cc liboctave/util/oct-shlib.cc liboctave/util/oct-shlib.h
diffstat 4 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/interpreter.cc	Thu Feb 17 22:19:11 2022 -0500
+++ b/libinterp/corefcn/interpreter.cc	Thu Feb 17 22:21:03 2022 -0500
@@ -1335,6 +1335,8 @@
 
   int interpreter::main_loop (void)
   {
+    command_editor::add_event_hook (release_unreferenced_dynamic_libraries);
+
     return m_evaluator.repl ();
   }
 
--- a/libinterp/parse-tree/pt-eval.cc	Thu Feb 17 22:19:11 2022 -0500
+++ b/libinterp/parse-tree/pt-eval.cc	Thu Feb 17 22:21:03 2022 -0500
@@ -189,6 +189,8 @@
 
             command_editor::run_event_hooks ();
 
+            release_unreferenced_dynamic_libraries ();
+
             sleep (0.1);
           }
         catch (const interrupt_exception&)
@@ -899,6 +901,8 @@
 
             command_editor::run_event_hooks ();
 
+            release_unreferenced_dynamic_libraries ();
+
             sleep (0.1);
           }
         catch (const interrupt_exception&)
--- a/liboctave/util/oct-shlib.cc	Thu Feb 17 22:19:11 2022 -0500
+++ b/liboctave/util/oct-shlib.cc	Thu Feb 17 22:21:03 2022 -0500
@@ -27,6 +27,7 @@
 #  include "config.h"
 #endif
 
+#include <list>
 #include <map>
 
 extern "C"
@@ -59,6 +60,20 @@
 
 namespace octave
 {
+  std::list<dynamic_library> possibly_unreferenced_dynamic_libraries;
+
+  void dynamic_library::delete_later (void)
+  {
+    possibly_unreferenced_dynamic_libraries.push_back (*this);
+  }
+
+  int release_unreferenced_dynamic_libraries (void)
+  {
+    possibly_unreferenced_dynamic_libraries.clear ();
+
+    return 0;
+  }
+
   dynamic_library::dynlib_rep::dynlib_rep (const std::string& f)
     : m_count (1), m_fcn_names (), m_file (f), m_time_loaded (),
       m_search_all_loaded (false)
--- a/liboctave/util/oct-shlib.h	Thu Feb 17 22:19:11 2022 -0500
+++ b/liboctave/util/oct-shlib.h	Thu Feb 17 22:21:03 2022 -0500
@@ -133,6 +133,8 @@
         delete m_rep;
     }
 
+    void delete_later (void);
+
     dynamic_library (const dynamic_library& sl)
       : m_rep (sl.m_rep)
     {
@@ -204,6 +206,11 @@
 
     dynlib_rep *m_rep;
   };
+
+  // FIXME: Currently must return int so that it may be used as an
+  // event_hook function.
+
+  OCTAVE_API int release_unreferenced_dynamic_libraries (void);
 }
 
 #endif