mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-21 23:00:06 +02:00
Loaded modules managed by smart pointers
This commit is contained in:
parent
e0476b5e71
commit
29349fedbb
@ -449,7 +449,7 @@ void ModuleManager::InitializeBuiltins()
|
|||||||
|
|
||||||
ModuleInterface *ModuleManager::LoadModule(const wxString & path)
|
ModuleInterface *ModuleManager::LoadModule(const wxString & path)
|
||||||
{
|
{
|
||||||
wxDynamicLibrary *lib = new wxDynamicLibrary();
|
auto lib = std::make_unique<wxDynamicLibrary>();
|
||||||
|
|
||||||
if (lib->Load(path, wxDL_NOW))
|
if (lib->Load(path, wxDL_NOW))
|
||||||
{
|
{
|
||||||
@ -468,7 +468,7 @@ ModuleInterface *ModuleManager::LoadModule(const wxString & path)
|
|||||||
|
|
||||||
auto module = handle.get();
|
auto module = handle.get();
|
||||||
mDynModules[PluginManager::GetID(module)] = std::move(handle);
|
mDynModules[PluginManager::GetID(module)] = std::move(handle);
|
||||||
mLibs[module] = lib;
|
mLibs[module] = std::move(lib);
|
||||||
|
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
@ -478,8 +478,6 @@ ModuleInterface *ModuleManager::LoadModule(const wxString & path)
|
|||||||
lib->Unload();
|
lib->Unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete lib;
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,11 +488,10 @@ void ModuleInterfaceDeleter::operator() (ModuleInterface *pInterface) const
|
|||||||
pInterface->Terminate();
|
pInterface->Terminate();
|
||||||
|
|
||||||
auto &libs = ModuleManager::Get().mLibs;
|
auto &libs = ModuleManager::Get().mLibs;
|
||||||
if (libs.find(pInterface) != libs.end())
|
|
||||||
{
|
auto iter = libs.find(pInterface);
|
||||||
libs[pInterface]->Unload();
|
if (iter != libs.end())
|
||||||
libs.erase(pInterface);
|
libs.erase(iter); // This causes unloading in ~wxDynamicLibrary
|
||||||
}
|
|
||||||
|
|
||||||
delete pInterface;
|
delete pInterface;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ using ModuleInterfaceHandle = movable_ptr_with_deleter<
|
|||||||
|
|
||||||
typedef std::map<wxString, ModuleMain *> ModuleMainMap;
|
typedef std::map<wxString, ModuleMain *> ModuleMainMap;
|
||||||
typedef std::map<wxString, ModuleInterfaceHandle> ModuleMap;
|
typedef std::map<wxString, ModuleInterfaceHandle> ModuleMap;
|
||||||
typedef std::map<ModuleInterface *, wxDynamicLibrary *> LibraryMap;
|
typedef std::map<ModuleInterface *, movable_ptr<wxDynamicLibrary>> LibraryMap;
|
||||||
|
|
||||||
class ModuleManager final : public ModuleManagerInterface
|
class ModuleManager final : public ModuleManagerInterface
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user