From 4e6e296e5e38185c4d0854f909385cee70e4cfdc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 2 Apr 2019 19:51:14 +0100 Subject: Don't use smart pointer for global static It destructs itself way sooner than we want it to --- libadhocutil/globalStatic.h | 2 +- libadhocutil/globalStatic.impl.h | 7 ++++--- libadhocutil/unittests/testPlugins.cpp | 1 - 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libadhocutil/globalStatic.h b/libadhocutil/globalStatic.h index 5808551..3639237 100644 --- a/libadhocutil/globalStatic.h +++ b/libadhocutil/globalStatic.h @@ -18,7 +18,7 @@ namespace AdHoc { static Object * get(); private: - typedef std::unique_ptr Ptr; + using Ptr = Object *; static void createObject() __attribute__((constructor(101))); static void deleteObject() __attribute__((destructor(101))); diff --git a/libadhocutil/globalStatic.impl.h b/libadhocutil/globalStatic.impl.h index fcd8096..13f2f72 100644 --- a/libadhocutil/globalStatic.impl.h +++ b/libadhocutil/globalStatic.impl.h @@ -7,19 +7,20 @@ namespace AdHoc { template Object * GlobalStatic::get() { - return instance().get(); + return instance(); } template void GlobalStatic::createObject() { - instance() = std::make_unique(); + instance() = new Object(); } template void GlobalStatic::deleteObject() { - instance().reset(); + delete instance(); + instance() = nullptr; } template diff --git a/libadhocutil/unittests/testPlugins.cpp b/libadhocutil/unittests/testPlugins.cpp index a8380fb..8d35822 100644 --- a/libadhocutil/unittests/testPlugins.cpp +++ b/libadhocutil/unittests/testPlugins.cpp @@ -79,7 +79,6 @@ BOOST_AUTO_TEST_CASE( createAndRemove ) auto c1 = PluginManager::getDefault()->get("custom1"); BOOST_REQUIRE(c1); PluginManager::getDefault()->remove("custom1"); - } BOOST_AUTO_TEST_CASE( nameAndTypeClash ) -- cgit v1.2.3