From ce3f3aff9c27f902c6b6b5a0f8d9bdc3dfb26c3f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 7 Mar 2019 22:42:29 +0100 Subject: Use smart pointers to manage World in programs --- src/ingen/ingen.cpp | 2 +- tests/ingen_bench.cpp | 7 +++---- tests/ingen_test.cpp | 7 +++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/ingen/ingen.cpp b/src/ingen/ingen.cpp index 62dd83ba..bc47d433 100644 --- a/src/ingen/ingen.cpp +++ b/src/ingen/ingen.cpp @@ -48,7 +48,7 @@ class DummyInterface : public Interface void message(const Message& msg) override {} }; -unique_ptr world; +unique_ptr world; static void ingen_interrupt(int signal) diff --git a/tests/ingen_bench.cpp b/tests/ingen_bench.cpp index b51ec364..1a0d84ca 100644 --- a/tests/ingen_bench.cpp +++ b/tests/ingen_bench.cpp @@ -35,14 +35,14 @@ using namespace std; using namespace ingen; -World* world = nullptr; +unique_ptr world; static void ingen_try(bool cond, const char* msg) { if (!cond) { cerr << "ingen: Error: " << msg << endl; - delete world; + world.reset(); exit(EXIT_FAILURE); } } @@ -63,7 +63,7 @@ main(int argc, char** argv) // Create world try { - world = new World(nullptr, nullptr, nullptr); + world = unique_ptr{new World(nullptr, nullptr, nullptr)}; world->conf().add( "output", "output", 'O', "File to write benchmark output", ingen::Configuration::SESSION, world->forge().String, Atom()); @@ -135,6 +135,5 @@ main(int argc, char** argv) // Shut down world->engine()->deactivate(); - delete world; return EXIT_SUCCESS; } diff --git a/tests/ingen_test.cpp b/tests/ingen_test.cpp index 3a566084..f40499b4 100644 --- a/tests/ingen_test.cpp +++ b/tests/ingen_test.cpp @@ -51,14 +51,14 @@ using namespace std; using namespace ingen; -World* world = nullptr; +unique_ptr world; static void ingen_try(bool cond, const char* msg) { if (!cond) { cerr << "ingen: Error: " << msg << endl; - delete world; + world.reset(); exit(EXIT_FAILURE); } } @@ -70,7 +70,7 @@ main(int argc, char** argv) // Create world try { - world = new World(nullptr, nullptr, nullptr); + world = unique_ptr{new World(nullptr, nullptr, nullptr)}; world->load_configuration(argc, argv); } catch (std::exception& e) { cout << "ingen: " << e.what() << endl; @@ -218,6 +218,5 @@ main(int argc, char** argv) // Shut down world->engine()->deactivate(); - delete world; return EXIT_SUCCESS; } -- cgit v1.2.1