From 0969655eebddb8c6e34f583f7d12d2ba2f79d4c6 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 25 Jun 2021 10:09:36 +0200 Subject: [PATCH 1/8] Improve memory management Signed-off-by: ahcorde --- include/class_loader/class_loader.hpp | 38 +++++++++++++------ .../multi_library_class_loader.hpp | 28 +++++++------- src/class_loader_core.cpp | 1 + src/meta_object.cpp | 3 ++ src/multi_library_class_loader.cpp | 8 ++-- 5 files changed, 49 insertions(+), 29 deletions(-) diff --git a/include/class_loader/class_loader.hpp b/include/class_loader/class_loader.hpp index bda67e56..8083bc24 100644 --- a/include/class_loader/class_loader.hpp +++ b/include/class_loader/class_loader.hpp @@ -76,7 +76,7 @@ std::string systemLibraryFormat(const std::string & library_name); * definitions from which objects can be created/destroyed during runtime (i.e. class_loader). * Libraries loaded by a ClassLoader are only accessible within scope of that ClassLoader object. */ -class ClassLoader +class ClassLoader : public std::enable_shared_from_this { public: template @@ -122,12 +122,20 @@ class ClassLoader * @return A std::shared_ptr to newly created plugin object */ template - std::shared_ptr createInstance(const std::string & derived_class_name) + std::shared_ptr createInstance(const std::string & derived_class_name, + bool is_shared_ptr = false) { - return std::shared_ptr( - createRawInstance(derived_class_name, true), - std::bind(&ClassLoader::onPluginDeletion, this, std::placeholders::_1) - ); + if (is_shared_ptr) { + return std::shared_ptr( + createRawInstance(derived_class_name, true), + std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) + ); + } else { + return std::shared_ptr( + createRawInstance(derived_class_name, true), + std::bind(&ClassLoader::onPluginDeletion, this, std::placeholders::_1) + ); + } } /// Generates an instance of loadable classes (i.e. class_loader). @@ -144,13 +152,21 @@ class ClassLoader * @return A std::unique_ptr to newly created plugin object. */ template - UniquePtr createUniqueInstance(const std::string & derived_class_name) + UniquePtr createUniqueInstance(const std::string & derived_class_name, + bool is_shared_ptr = false) { Base * raw = createRawInstance(derived_class_name, true); - return std::unique_ptr>( - raw, - std::bind(&ClassLoader::onPluginDeletion, this, std::placeholders::_1) - ); + if (is_shared_ptr) { + return std::unique_ptr>( + raw, + std::bind(&ClassLoader::onPluginDeletion, this, std::placeholders::_1) + ); + } else { + return std::unique_ptr>( + raw, + std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) + ); + } } /// Generates an instance of loadable classes (i.e. class_loader). diff --git a/include/class_loader/multi_library_class_loader.hpp b/include/class_loader/multi_library_class_loader.hpp index f04afc8f..c192cd2b 100644 --- a/include/class_loader/multi_library_class_loader.hpp +++ b/include/class_loader/multi_library_class_loader.hpp @@ -56,8 +56,8 @@ namespace class_loader { typedef std::string LibraryPath; -typedef std::map LibraryToClassLoaderMap; -typedef std::vector ClassLoaderVector; +typedef std::map> LibraryToClassLoaderMap; +typedef std::vector> ClassLoaderVector; class MultiLibraryClassLoaderImpl; @@ -96,7 +96,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader "class_loader::MultiLibraryClassLoader: " "Attempting to create instance of class type %s.", class_name.c_str()); - ClassLoader * loader = getClassLoaderForClass(class_name); + std::shared_ptr loader = getClassLoaderForClass(class_name); if (nullptr == loader) { throw class_loader::CreateClassException( "MultiLibraryClassLoader: Could not create object of class type " + @@ -105,7 +105,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader "was explicitly loaded through MultiLibraryClassLoader::loadLibrary()"); } - return loader->createInstance(class_name); + return loader->createInstance(class_name, true); } /** @@ -121,14 +121,14 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader std::shared_ptr createInstance( const std::string & class_name, const std::string & library_path) { - ClassLoader * loader = getClassLoaderForLibrary(library_path); + std::shared_ptr loader = getClassLoaderForLibrary(library_path); if (nullptr == loader) { throw class_loader::NoClassLoaderExistsException( "Could not create instance as there is no ClassLoader in " "MultiLibraryClassLoader bound to library " + library_path + " Ensure you called MultiLibraryClassLoader::loadLibrary()"); } - return loader->createInstance(class_name); + return loader->createInstance(class_name, true); } /// Creates an instance of an object of given class name with ancestor class Base @@ -146,7 +146,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader CONSOLE_BRIDGE_logDebug( "class_loader::MultiLibraryClassLoader: Attempting to create instance of class type %s.", class_name.c_str()); - ClassLoader * loader = getClassLoaderForClass(class_name); + std::shared_ptr loader = getClassLoaderForClass(class_name); if (nullptr == loader) { throw class_loader::CreateClassException( "MultiLibraryClassLoader: Could not create object of class type " + class_name + @@ -170,14 +170,14 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader ClassLoader::UniquePtr createUniqueInstance(const std::string & class_name, const std::string & library_path) { - ClassLoader * loader = getClassLoaderForLibrary(library_path); + std::shared_ptr loader = getClassLoaderForLibrary(library_path); if (nullptr == loader) { throw class_loader::NoClassLoaderExistsException( "Could not create instance as there is no ClassLoader in " "MultiLibraryClassLoader bound to library " + library_path + " Ensure you called MultiLibraryClassLoader::loadLibrary()"); } - return loader->createUniqueInstance(class_name); + return loader->createUniqueInstance(class_name, true); } /** @@ -193,7 +193,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader template Base * createUnmanagedInstance(const std::string & class_name) { - ClassLoader * loader = getClassLoaderForClass(class_name); + std::shared_ptr loader = getClassLoaderForClass(class_name); if (nullptr == loader) { throw class_loader::CreateClassException( "MultiLibraryClassLoader: Could not create class of type " + class_name); @@ -213,7 +213,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader template Base * createUnmanagedInstance(const std::string & class_name, const std::string & library_path) { - ClassLoader * loader = getClassLoaderForLibrary(library_path); + std::shared_ptr loader = getClassLoaderForLibrary(library_path); if (nullptr == loader) { throw class_loader::NoClassLoaderExistsException( "Could not create instance as there is no ClassLoader in MultiLibraryClassLoader " @@ -273,7 +273,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader template std::vector getAvailableClassesForLibrary(const std::string & library_path) { - ClassLoader * loader = getClassLoaderForLibrary(library_path); + std::shared_ptr loader = getClassLoaderForLibrary(library_path); if (nullptr == loader) { throw class_loader::NoClassLoaderExistsException( "There is no ClassLoader in MultiLibraryClassLoader bound to library " + @@ -321,7 +321,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader * @param library_path - the library from which we want to create the plugin * @return A pointer to the ClassLoader*, == nullptr if not found */ - ClassLoader * getClassLoaderForLibrary(const std::string & library_path); + std::shared_ptr getClassLoaderForLibrary(const std::string & library_path); /// Gets a handle to the class loader corresponding to a specific class. /** @@ -329,7 +329,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader * @return A pointer to the ClassLoader, or NULL if not found. */ template - ClassLoader * getClassLoaderForClass(const std::string & class_name) + std::shared_ptr getClassLoaderForClass(const std::string & class_name) { ClassLoaderVector loaders = getAllAvailableClassLoaders(); for (ClassLoaderVector::iterator i = loaders.begin(); i != loaders.end(); ++i) { diff --git a/src/class_loader_core.cpp b/src/class_loader_core.cpp index 56cc7704..335c99bc 100644 --- a/src/class_loader_core.cpp +++ b/src/class_loader_core.cpp @@ -545,6 +545,7 @@ void unloadLibrary(const std::string & library_path, ClassLoader * loader) ", keeping library %s open.", library_path.c_str()); } + purgeGraveyardOfMetaobjects(library_path, loader, true); return; } catch (const std::runtime_error & e) { throw class_loader::LibraryUnloadException( diff --git a/src/meta_object.cpp b/src/meta_object.cpp index 002b55e2..388d0435 100644 --- a/src/meta_object.cpp +++ b/src/meta_object.cpp @@ -71,6 +71,9 @@ AbstractMetaObjectBase::~AbstractMetaObjectBase() "class_loader.impl.AbstractMetaObjectBase: " "Destroying MetaObject %p (base = %s, derived = %s, library path = %s)", this, baseClassName().c_str(), className().c_str(), getAssociatedLibraryPath().c_str()); + for (unsigned int i = 0; i < impl_->associated_class_loaders_.size(); i++) { + delete impl_->associated_class_loaders_[i]; + } delete impl_; } diff --git a/src/multi_library_class_loader.cpp b/src/multi_library_class_loader.cpp index c22f4888..45dc1158 100644 --- a/src/multi_library_class_loader.cpp +++ b/src/multi_library_class_loader.cpp @@ -68,7 +68,8 @@ std::vector MultiLibraryClassLoader::getRegisteredLibraries() const return libraries; } -ClassLoader * MultiLibraryClassLoader::getClassLoaderForLibrary(const std::string & library_path) +std::shared_ptr MultiLibraryClassLoader::getClassLoaderForLibrary( + const std::string & library_path) { return impl_->active_class_loaders_[library_path]; } @@ -93,7 +94,7 @@ void MultiLibraryClassLoader::loadLibrary(const std::string & library_path) { if (!isLibraryAvailable(library_path)) { impl_->active_class_loaders_[library_path] = - new class_loader::ClassLoader(library_path, isOnDemandLoadUnloadEnabled()); + std::make_shared(library_path, isOnDemandLoadUnloadEnabled()); } } @@ -108,11 +109,10 @@ int MultiLibraryClassLoader::unloadLibrary(const std::string & library_path) { int remaining_unloads = 0; if (isLibraryAvailable(library_path)) { - ClassLoader * loader = getClassLoaderForLibrary(library_path); + auto loader = getClassLoaderForLibrary(library_path); remaining_unloads = loader->unloadLibrary(); if (remaining_unloads == 0) { impl_->active_class_loaders_[library_path] = nullptr; - delete (loader); } } return remaining_unloads; From 58d57ed1f97825f516540c24947cc46369ef0b7d Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 25 Jun 2021 11:11:43 +0200 Subject: [PATCH 2/8] some fixes Signed-off-by: ahcorde --- include/class_loader/class_loader.hpp | 10 ++++++---- include/class_loader/multi_library_class_loader.hpp | 5 +++-- src/multi_library_class_loader.cpp | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/class_loader/class_loader.hpp b/include/class_loader/class_loader.hpp index 8083bc24..819fa0c3 100644 --- a/include/class_loader/class_loader.hpp +++ b/include/class_loader/class_loader.hpp @@ -122,7 +122,8 @@ class ClassLoader : public std::enable_shared_from_this * @return A std::shared_ptr to newly created plugin object */ template - std::shared_ptr createInstance(const std::string & derived_class_name, + std::shared_ptr createInstance( + const std::string & derived_class_name, bool is_shared_ptr = false) { if (is_shared_ptr) { @@ -152,19 +153,20 @@ class ClassLoader : public std::enable_shared_from_this * @return A std::unique_ptr to newly created plugin object. */ template - UniquePtr createUniqueInstance(const std::string & derived_class_name, + UniquePtr createUniqueInstance( + const std::string & derived_class_name, bool is_shared_ptr = false) { Base * raw = createRawInstance(derived_class_name, true); if (is_shared_ptr) { return std::unique_ptr>( raw, - std::bind(&ClassLoader::onPluginDeletion, this, std::placeholders::_1) + std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) ); } else { return std::unique_ptr>( raw, - std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) + std::bind(&ClassLoader::onPluginDeletion, this, std::placeholders::_1) ); } } diff --git a/include/class_loader/multi_library_class_loader.hpp b/include/class_loader/multi_library_class_loader.hpp index c192cd2b..907e0a7a 100644 --- a/include/class_loader/multi_library_class_loader.hpp +++ b/include/class_loader/multi_library_class_loader.hpp @@ -154,7 +154,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader "Make sure that the library exists and was explicitly loaded through " "MultiLibraryClassLoader::loadLibrary()"); } - return loader->createUniqueInstance(class_name); + return loader->createUniqueInstance(class_name, true); } /// Creates an instance of an object of given class name with ancestor class Base @@ -321,7 +321,8 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader * @param library_path - the library from which we want to create the plugin * @return A pointer to the ClassLoader*, == nullptr if not found */ - std::shared_ptr getClassLoaderForLibrary(const std::string & library_path); + std::shared_ptr getClassLoaderForLibrary( + const std::string & library_path); /// Gets a handle to the class loader corresponding to a specific class. /** diff --git a/src/multi_library_class_loader.cpp b/src/multi_library_class_loader.cpp index 45dc1158..336564e7 100644 --- a/src/multi_library_class_loader.cpp +++ b/src/multi_library_class_loader.cpp @@ -30,6 +30,7 @@ #include "class_loader/multi_library_class_loader.hpp" #include +#include #include #include #include From 6a800a44a6613fa8c4de88d7efbb07363006f52c Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 25 Jun 2021 16:10:25 +0200 Subject: [PATCH 3/8] Use exceptions Signed-off-by: ahcorde --- include/class_loader/class_loader.hpp | 16 ++++++---------- .../class_loader/multi_library_class_loader.hpp | 8 ++++---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/include/class_loader/class_loader.hpp b/include/class_loader/class_loader.hpp index 819fa0c3..ce8ab9de 100644 --- a/include/class_loader/class_loader.hpp +++ b/include/class_loader/class_loader.hpp @@ -122,16 +122,14 @@ class ClassLoader : public std::enable_shared_from_this * @return A std::shared_ptr to newly created plugin object */ template - std::shared_ptr createInstance( - const std::string & derived_class_name, - bool is_shared_ptr = false) + std::shared_ptr createInstance(const std::string & derived_class_name) { - if (is_shared_ptr) { + try { return std::shared_ptr( createRawInstance(derived_class_name, true), std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) ); - } else { + } catch (std::bad_weak_ptr & e) { // This is not a shared_ptr return std::shared_ptr( createRawInstance(derived_class_name, true), std::bind(&ClassLoader::onPluginDeletion, this, std::placeholders::_1) @@ -153,17 +151,15 @@ class ClassLoader : public std::enable_shared_from_this * @return A std::unique_ptr to newly created plugin object. */ template - UniquePtr createUniqueInstance( - const std::string & derived_class_name, - bool is_shared_ptr = false) + UniquePtr createUniqueInstance(const std::string & derived_class_name) { Base * raw = createRawInstance(derived_class_name, true); - if (is_shared_ptr) { + try { return std::unique_ptr>( raw, std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) ); - } else { + } catch (std::bad_weak_ptr & e) { // This is not a shared_ptr return std::unique_ptr>( raw, std::bind(&ClassLoader::onPluginDeletion, this, std::placeholders::_1) diff --git a/include/class_loader/multi_library_class_loader.hpp b/include/class_loader/multi_library_class_loader.hpp index 907e0a7a..402234c2 100644 --- a/include/class_loader/multi_library_class_loader.hpp +++ b/include/class_loader/multi_library_class_loader.hpp @@ -105,7 +105,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader "was explicitly loaded through MultiLibraryClassLoader::loadLibrary()"); } - return loader->createInstance(class_name, true); + return loader->createInstance(class_name); } /** @@ -128,7 +128,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader "MultiLibraryClassLoader bound to library " + library_path + " Ensure you called MultiLibraryClassLoader::loadLibrary()"); } - return loader->createInstance(class_name, true); + return loader->createInstance(class_name); } /// Creates an instance of an object of given class name with ancestor class Base @@ -154,7 +154,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader "Make sure that the library exists and was explicitly loaded through " "MultiLibraryClassLoader::loadLibrary()"); } - return loader->createUniqueInstance(class_name, true); + return loader->createUniqueInstance(class_name); } /// Creates an instance of an object of given class name with ancestor class Base @@ -177,7 +177,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader "MultiLibraryClassLoader bound to library " + library_path + " Ensure you called MultiLibraryClassLoader::loadLibrary()"); } - return loader->createUniqueInstance(class_name, true); + return loader->createUniqueInstance(class_name); } /** From 97a431344efb62a71d9b73fd2b77d7ab35b7045d Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 17 Sep 2021 16:37:48 +0200 Subject: [PATCH 4/8] Added comments and docs Signed-off-by: ahcorde --- include/class_loader/class_loader.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/class_loader/class_loader.hpp b/include/class_loader/class_loader.hpp index ce8ab9de..293e32fe 100644 --- a/include/class_loader/class_loader.hpp +++ b/include/class_loader/class_loader.hpp @@ -75,6 +75,8 @@ std::string systemLibraryFormat(const std::string & library_name); * @brief This class allows loading and unloading of dynamically linked libraries which contain class * definitions from which objects can be created/destroyed during runtime (i.e. class_loader). * Libraries loaded by a ClassLoader are only accessible within scope of that ClassLoader object. + * This class inherit from enable_shared_from_this which means we must used smart pointers, + * otherwise the code might work but it may run into a leak. */ class ClassLoader : public std::enable_shared_from_this { @@ -130,6 +132,8 @@ class ClassLoader : public std::enable_shared_from_this std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) ); } catch (std::bad_weak_ptr & e) { // This is not a shared_ptr + CONSOLE_BRIDGE_logWarn("class_loader::ClassLoader::createUniqueInstance " + "This class must be used with smart pointer"); return std::shared_ptr( createRawInstance(derived_class_name, true), std::bind(&ClassLoader::onPluginDeletion, this, std::placeholders::_1) @@ -160,6 +164,8 @@ class ClassLoader : public std::enable_shared_from_this std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) ); } catch (std::bad_weak_ptr & e) { // This is not a shared_ptr + CONSOLE_BRIDGE_logWarn("class_loader::ClassLoader::createUniqueInstance " + "This class must be used with smart pointer"); return std::unique_ptr>( raw, std::bind(&ClassLoader::onPluginDeletion, this, std::placeholders::_1) From 6ced46efeb69ecb528690846f0c9411e8d7d39ae Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 20 Sep 2021 10:24:52 +0200 Subject: [PATCH 5/8] make linters happy Signed-off-by: ahcorde --- include/class_loader/class_loader.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/class_loader/class_loader.hpp b/include/class_loader/class_loader.hpp index 293e32fe..9b9fae55 100644 --- a/include/class_loader/class_loader.hpp +++ b/include/class_loader/class_loader.hpp @@ -132,7 +132,8 @@ class ClassLoader : public std::enable_shared_from_this std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) ); } catch (std::bad_weak_ptr & e) { // This is not a shared_ptr - CONSOLE_BRIDGE_logWarn("class_loader::ClassLoader::createUniqueInstance " + CONSOLE_BRIDGE_logWarn( + "class_loader::ClassLoader::createUniqueInstance " "This class must be used with smart pointer"); return std::shared_ptr( createRawInstance(derived_class_name, true), @@ -164,7 +165,8 @@ class ClassLoader : public std::enable_shared_from_this std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) ); } catch (std::bad_weak_ptr & e) { // This is not a shared_ptr - CONSOLE_BRIDGE_logWarn("class_loader::ClassLoader::createUniqueInstance " + CONSOLE_BRIDGE_logWarn( + "class_loader::ClassLoader::createUniqueInstance " "This class must be used with smart pointer"); return std::unique_ptr>( raw, From a17bcc3ec5e8a8660e942f3ac620c8cfbe557766 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 20 Sep 2021 18:09:14 +0200 Subject: [PATCH 6/8] added feedback Signed-off-by: ahcorde --- include/class_loader/class_loader.hpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/include/class_loader/class_loader.hpp b/include/class_loader/class_loader.hpp index 9b9fae55..4858c714 100644 --- a/include/class_loader/class_loader.hpp +++ b/include/class_loader/class_loader.hpp @@ -132,9 +132,14 @@ class ClassLoader : public std::enable_shared_from_this std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) ); } catch (std::bad_weak_ptr & e) { // This is not a shared_ptr - CONSOLE_BRIDGE_logWarn( - "class_loader::ClassLoader::createUniqueInstance " - "This class must be used with smart pointer"); + static bool create_instance_message = false; + if (!create_instance_message) { + CONSOLE_BRIDGE_logWarn( + "To createUniqueInstance() with a class_loader::ClassLoader " + "instance whose lifetime is not managed by an std::shared_ptr " + "is deprecated."); + create_instance_message = true; + } return std::shared_ptr( createRawInstance(derived_class_name, true), std::bind(&ClassLoader::onPluginDeletion, this, std::placeholders::_1) @@ -165,9 +170,14 @@ class ClassLoader : public std::enable_shared_from_this std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) ); } catch (std::bad_weak_ptr & e) { // This is not a shared_ptr - CONSOLE_BRIDGE_logWarn( - "class_loader::ClassLoader::createUniqueInstance " - "This class must be used with smart pointer"); + static bool create_unique_instance_message = false; + if (!create_unique_instance_message) { + CONSOLE_BRIDGE_logWarn( + "To createUniqueInstance() with a class_loader::ClassLoader " + "instance whose lifetime is not managed by an std::shared_ptr " + "is deprecated."); + create_unique_instance_message = true; + } return std::unique_ptr>( raw, std::bind(&ClassLoader::onPluginDeletion, this, std::placeholders::_1) From 457d04945f4ecfa2fb0f80c652266da618d5397a Mon Sep 17 00:00:00 2001 From: ahcorde Date: Tue, 21 Sep 2021 10:51:22 +0200 Subject: [PATCH 7/8] style Signed-off-by: ahcorde --- include/class_loader/class_loader.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/class_loader/class_loader.hpp b/include/class_loader/class_loader.hpp index 4858c714..c7611ae7 100644 --- a/include/class_loader/class_loader.hpp +++ b/include/class_loader/class_loader.hpp @@ -135,10 +135,10 @@ class ClassLoader : public std::enable_shared_from_this static bool create_instance_message = false; if (!create_instance_message) { CONSOLE_BRIDGE_logWarn( - "To createUniqueInstance() with a class_loader::ClassLoader " + "To createInstance() with a class_loader::ClassLoader " "instance whose lifetime is not managed by an std::shared_ptr " "is deprecated."); - create_instance_message = true; + create_instance_message = true; } return std::shared_ptr( createRawInstance(derived_class_name, true), From 7c789238e05fe268843f85583e2319c2fd3ef671 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 25 Oct 2021 18:24:29 +0200 Subject: [PATCH 8/8] fixed warning Signed-off-by: ahcorde --- include/class_loader/class_loader.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/class_loader/class_loader.hpp b/include/class_loader/class_loader.hpp index c7611ae7..0ed39360 100644 --- a/include/class_loader/class_loader.hpp +++ b/include/class_loader/class_loader.hpp @@ -131,7 +131,7 @@ class ClassLoader : public std::enable_shared_from_this createRawInstance(derived_class_name, true), std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) ); - } catch (std::bad_weak_ptr & e) { // This is not a shared_ptr + } catch (std::bad_weak_ptr &) { // This is not a shared_ptr static bool create_instance_message = false; if (!create_instance_message) { CONSOLE_BRIDGE_logWarn( @@ -169,7 +169,7 @@ class ClassLoader : public std::enable_shared_from_this raw, std::bind(&ClassLoader::onPluginDeletion, shared_from_this(), std::placeholders::_1) ); - } catch (std::bad_weak_ptr & e) { // This is not a shared_ptr + } catch (std::bad_weak_ptr &) { // This is not a shared_ptr static bool create_unique_instance_message = false; if (!create_unique_instance_message) { CONSOLE_BRIDGE_logWarn(