From 9ecb3f8d5c82a86734ee3af3c17a3a08e6b8daa2 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 13 Apr 2019 13:01:49 -0700 Subject: Ninja,Makefile: use `unique_ptr` for memory management Use a `unique_ptr` to manage the lifetime of the `MacOSXContentGenerator` and 'OSXBundleGenerator` rather than manually handling the lifetime. --- Source/cmMakefileExecutableTargetGenerator.cxx | 9 ++++----- Source/cmMakefileLibraryTargetGenerator.cxx | 9 ++++----- Source/cmMakefileTargetGenerator.h | 2 +- Source/cmMakefileUtilityTargetGenerator.cxx | 9 ++++----- Source/cmNinjaNormalTargetGenerator.cxx | 7 ++----- Source/cmNinjaTargetGenerator.cxx | 11 ++++------- Source/cmNinjaTargetGenerator.h | 4 ++-- 7 files changed, 21 insertions(+), 30 deletions(-) diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 984cd85..ebf5fc2 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -9,6 +9,7 @@ #include #include +#include "cmAlgorithms.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" #include "cmGlobalUnixMakefileGenerator3.h" @@ -35,14 +36,12 @@ cmMakefileExecutableTargetGenerator::cmMakefileExecutableTargetGenerator( this->GeneratorTarget->GetExecutableNames(this->ConfigName); this->OSXBundleGenerator = - new cmOSXBundleGenerator(target, this->ConfigName); + cm::make_unique(target, this->ConfigName); this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders); } -cmMakefileExecutableTargetGenerator::~cmMakefileExecutableTargetGenerator() -{ - delete this->OSXBundleGenerator; -} +cmMakefileExecutableTargetGenerator::~cmMakefileExecutableTargetGenerator() = + default; void cmMakefileExecutableTargetGenerator::WriteRuleFiles() { diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 44e6547..0393e22 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -9,6 +9,7 @@ #include #include +#include "cmAlgorithms.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" #include "cmGlobalUnixMakefileGenerator3.h" @@ -37,14 +38,12 @@ cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator( } this->OSXBundleGenerator = - new cmOSXBundleGenerator(target, this->ConfigName); + cm::make_unique(target, this->ConfigName); this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders); } -cmMakefileLibraryTargetGenerator::~cmMakefileLibraryTargetGenerator() -{ - delete this->OSXBundleGenerator; -} +cmMakefileLibraryTargetGenerator::~cmMakefileLibraryTargetGenerator() = + default; void cmMakefileLibraryTargetGenerator::WriteRuleFiles() { diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index c053d5b..ec58d17 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -235,7 +235,7 @@ protected: // macOS content info. std::set MacContentFolders; - cmOSXBundleGenerator* OSXBundleGenerator; + std::unique_ptr OSXBundleGenerator; MacOSXContentGeneratorType* MacOSXContentGenerator; }; diff --git a/Source/cmMakefileUtilityTargetGenerator.cxx b/Source/cmMakefileUtilityTargetGenerator.cxx index 8fbd5d2..4236995 100644 --- a/Source/cmMakefileUtilityTargetGenerator.cxx +++ b/Source/cmMakefileUtilityTargetGenerator.cxx @@ -7,6 +7,7 @@ #include #include +#include "cmAlgorithms.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" #include "cmGlobalUnixMakefileGenerator3.h" @@ -21,14 +22,12 @@ cmMakefileUtilityTargetGenerator::cmMakefileUtilityTargetGenerator( { this->CustomCommandDriver = OnUtility; this->OSXBundleGenerator = - new cmOSXBundleGenerator(target, this->ConfigName); + cm::make_unique(target, this->ConfigName); this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders); } -cmMakefileUtilityTargetGenerator::~cmMakefileUtilityTargetGenerator() -{ - delete this->OSXBundleGenerator; -} +cmMakefileUtilityTargetGenerator::~cmMakefileUtilityTargetGenerator() = + default; void cmMakefileUtilityTargetGenerator::WriteRuleFiles() { diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 3300fef..af47fa7 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -54,14 +54,11 @@ cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator( } this->OSXBundleGenerator = - new cmOSXBundleGenerator(target, this->GetConfigName()); + cm::make_unique(target, this->GetConfigName()); this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders); } -cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator() -{ - delete this->OSXBundleGenerator; -} +cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator() = default; void cmNinjaNormalTargetGenerator::Generate() { diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 1ad26dd..2324839 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -59,13 +59,10 @@ cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target) , LocalGenerator( static_cast(target->GetLocalGenerator())) { - MacOSXContentGenerator = new MacOSXContentGeneratorType(this); + MacOSXContentGenerator = cm::make_unique(this); } -cmNinjaTargetGenerator::~cmNinjaTargetGenerator() -{ - delete this->MacOSXContentGenerator; -} +cmNinjaTargetGenerator::~cmNinjaTargetGenerator() = default; cmGeneratedFileStream& cmNinjaTargetGenerator::GetBuildFileStream() const { @@ -813,11 +810,11 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() std::vector headerSources; this->GeneratorTarget->GetHeaderSources(headerSources, config); this->OSXBundleGenerator->GenerateMacOSXContentStatements( - headerSources, this->MacOSXContentGenerator); + headerSources, this->MacOSXContentGenerator.get()); std::vector extraSources; this->GeneratorTarget->GetExtraSources(extraSources, config); this->OSXBundleGenerator->GenerateMacOSXContentStatements( - extraSources, this->MacOSXContentGenerator); + extraSources, this->MacOSXContentGenerator.get()); std::vector externalObjects; this->GeneratorTarget->GetExternalObjects(externalObjects, config); for (cmSourceFile const* sf : externalObjects) { diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 6a42da0..51c9ac7 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -153,9 +153,9 @@ protected: }; friend struct MacOSXContentGeneratorType; - MacOSXContentGeneratorType* MacOSXContentGenerator; + std::unique_ptr MacOSXContentGenerator; // Properly initialized by sub-classes. - cmOSXBundleGenerator* OSXBundleGenerator; + std::unique_ptr OSXBundleGenerator; std::set MacContentFolders; void addPoolNinjaVariable(const std::string& pool_property, -- cgit v0.12