Skip to content

Commit f6d8ccc

Browse files
committed
bugfix: enable on-demand loading/unloading with MultiClassLoader
- enforce loading of library in loadLibrary(), otherwise we cannot know - don't unload libraries in destructor when on-demand-unloading is enabled
1 parent 8a816d7 commit f6d8ccc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

include/class_loader/multi_library_class_loader.h

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class MultiLibraryClassLoader
7373
for(unsigned int c = 0; c < active_loaders.size(); c++)
7474
{
7575
ClassLoader* current = active_loaders.at(c);
76+
if (!current->isLibraryLoaded())
77+
current->loadLibrary();
7678
if(current->isClassAvailable<Base>(class_name))
7779
return(current->createInstance<Base>(class_name));
7880
}
@@ -113,6 +115,8 @@ class MultiLibraryClassLoader
113115
for(unsigned int c = 0; c < active_loaders.size(); c++)
114116
{
115117
ClassLoader* current = active_loaders.at(c);
118+
if (!current->isLibraryLoaded())
119+
current->loadLibrary();
116120
if(current->isClassAvailable<Base>(class_name))
117121
return(current->createUnmanagedInstance<Base>(class_name));
118122
}

src/multi_library_class_loader.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ enable_ondemand_loadunload_(enable_ondemand_loadunload)
3939

4040
MultiLibraryClassLoader::~MultiLibraryClassLoader()
4141
{
42-
shutdownAllClassLoaders();
42+
if (!isOnDemandLoadUnloadEnabled())
43+
shutdownAllClassLoaders(); // don't unload libs to avoid SEVERE WARNING
44+
// TODO: free ClassLoaders in active_class_loaders_
45+
// However, we still need them in on-demand-load-unload mode. Otherwise we risk seg-faults.
4346
}
4447

4548
std::vector<std::string> MultiLibraryClassLoader::getRegisteredLibraries()

0 commit comments

Comments
 (0)