# HG changeset patch # User John W. Eaton # Date 1645154463 18000 # Node ID 076e19eac74ad741bd93646a35093ce76562efd2 # Parent e00154c0a71b246995d180d20a3409304d4d65d4 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. diff -r e00154c0a71b -r 076e19eac74a libinterp/corefcn/interpreter.cc --- 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 (); } diff -r e00154c0a71b -r 076e19eac74a libinterp/parse-tree/pt-eval.cc --- 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&) diff -r e00154c0a71b -r 076e19eac74a liboctave/util/oct-shlib.cc --- 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 #include extern "C" @@ -59,6 +60,20 @@ namespace octave { + std::list 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) diff -r e00154c0a71b -r 076e19eac74a liboctave/util/oct-shlib.h --- 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