diff options
author | Brad King <brad.king@kitware.com> | 2020-01-22 14:49:21 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-01-22 14:49:30 (GMT) |
commit | 39695f6fb316de2289636de483f52d53096ac41d (patch) | |
tree | fa576569e86ba6a1ab5159c6d908c409f15dd295 | |
parent | fad5716c2a072a9fdfb644ee84ebea69c0526415 (diff) | |
parent | edab5add57894b2f9bcbc91ee0c9b5b6051f4ac1 (diff) | |
download | CMake-39695f6fb316de2289636de483f52d53096ac41d.zip CMake-39695f6fb316de2289636de483f52d53096ac41d.tar.gz CMake-39695f6fb316de2289636de483f52d53096ac41d.tar.bz2 |
Merge topic 'modernize-memory-management'
edab5add57 cmMakefileTargetGenerator: modernize memory management
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4250
-rw-r--r-- | Source/cmMakefileTargetGenerator.cxx | 49 | ||||
-rw-r--r-- | Source/cmMakefileTargetGenerator.h | 15 |
2 files changed, 31 insertions, 33 deletions
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 77b6bc2..714d01e 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -4,10 +4,10 @@ #include <cassert> #include <cstdio> -#include <memory> #include <sstream> #include <utility> +#include <cm/memory> #include <cmext/algorithm> #include "cmComputeLinkInformation.h" @@ -38,12 +38,7 @@ cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmGeneratorTarget* target) : cmCommonTargetGenerator(target) - , OSXBundleGenerator(nullptr) - , MacOSXContentGenerator(nullptr) { - this->BuildFileStream = nullptr; - this->InfoFileStream = nullptr; - this->FlagFileStream = nullptr; this->CustomCommandDriver = OnBuild; this->LocalGenerator = static_cast<cmLocalUnixMakefileGenerator3*>(target->GetLocalGenerator()); @@ -55,31 +50,28 @@ cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmGeneratorTarget* target) cm->GetState()->GetGlobalProperty("RULE_MESSAGES")) { this->NoRuleMessages = cmIsOff(ruleStatus); } - MacOSXContentGenerator = new MacOSXContentGeneratorType(this); + MacOSXContentGenerator = cm::make_unique<MacOSXContentGeneratorType>(this); } -cmMakefileTargetGenerator::~cmMakefileTargetGenerator() -{ - delete MacOSXContentGenerator; -} +cmMakefileTargetGenerator::~cmMakefileTargetGenerator() = default; -cmMakefileTargetGenerator* cmMakefileTargetGenerator::New( +std::unique_ptr<cmMakefileTargetGenerator> cmMakefileTargetGenerator::New( cmGeneratorTarget* tgt) { - cmMakefileTargetGenerator* result = nullptr; + std::unique_ptr<cmMakefileTargetGenerator> result; switch (tgt->GetType()) { case cmStateEnums::EXECUTABLE: - result = new cmMakefileExecutableTargetGenerator(tgt); + result = cm::make_unique<cmMakefileExecutableTargetGenerator>(tgt); break; case cmStateEnums::STATIC_LIBRARY: case cmStateEnums::SHARED_LIBRARY: case cmStateEnums::MODULE_LIBRARY: case cmStateEnums::OBJECT_LIBRARY: - result = new cmMakefileLibraryTargetGenerator(tgt); + result = cm::make_unique<cmMakefileLibraryTargetGenerator>(tgt); break; case cmStateEnums::UTILITY: - result = new cmMakefileUtilityTargetGenerator(tgt); + result = cm::make_unique<cmMakefileUtilityTargetGenerator>(tgt); break; default: return result; @@ -139,9 +131,9 @@ void cmMakefileTargetGenerator::CreateRuleFile() // Open the rule file. This should be copy-if-different because the // rules may depend on this file itself. - this->BuildFileStream = - new cmGeneratedFileStream(this->BuildFileNameFull, false, - this->GlobalGenerator->GetMakefileEncoding()); + this->BuildFileStream = cm::make_unique<cmGeneratedFileStream>( + this->BuildFileNameFull, false, + this->GlobalGenerator->GetMakefileEncoding()); if (!this->BuildFileStream) { return; } @@ -247,11 +239,11 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() this->GeneratorTarget->GetHeaderSources(headerSources, this->GetConfigName()); this->OSXBundleGenerator->GenerateMacOSXContentStatements( - headerSources, this->MacOSXContentGenerator, this->GetConfigName()); + headerSources, this->MacOSXContentGenerator.get(), this->GetConfigName()); std::vector<cmSourceFile const*> extraSources; this->GeneratorTarget->GetExtraSources(extraSources, this->GetConfigName()); this->OSXBundleGenerator->GenerateMacOSXContentStatements( - extraSources, this->MacOSXContentGenerator, this->GetConfigName()); + extraSources, this->MacOSXContentGenerator.get(), this->GetConfigName()); const char* pchExtension = this->Makefile->GetDefinition("CMAKE_PCH_EXTENSION"); std::vector<cmSourceFile const*> externalObjects; @@ -316,9 +308,9 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules() // rules may depend on this file itself. this->FlagFileNameFull = cmStrCat(this->TargetBuildDirectoryFull, "/flags.make"); - this->FlagFileStream = - new cmGeneratedFileStream(this->FlagFileNameFull, false, - this->GlobalGenerator->GetMakefileEncoding()); + this->FlagFileStream = cm::make_unique<cmGeneratedFileStream>( + this->FlagFileNameFull, false, + this->GlobalGenerator->GetMakefileEncoding()); if (!this->FlagFileStream) { return; } @@ -1057,7 +1049,8 @@ void cmMakefileTargetGenerator::WriteTargetDependRules() this->InfoFileNameFull = cmStrCat(dir, "/DependInfo.cmake"); this->InfoFileNameFull = this->LocalGenerator->ConvertToFullPath(this->InfoFileNameFull); - this->InfoFileStream = new cmGeneratedFileStream(this->InfoFileNameFull); + this->InfoFileStream = + cm::make_unique<cmGeneratedFileStream>(this->InfoFileNameFull); if (!this->InfoFileStream) { return; } @@ -1524,9 +1517,9 @@ std::string cmMakefileTargetGenerator::GetLinkRule( void cmMakefileTargetGenerator::CloseFileStreams() { - delete this->BuildFileStream; - delete this->InfoFileStream; - delete this->FlagFileStream; + this->BuildFileStream.reset(); + this->InfoFileStream.reset(); + this->FlagFileStream.reset(); } void cmMakefileTargetGenerator::CreateLinkScript( diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index fd62933..ec6b314 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -34,10 +34,15 @@ class cmMakefileTargetGenerator : public cmCommonTargetGenerator public: // constructor to set the ivars cmMakefileTargetGenerator(cmGeneratorTarget* target); + cmMakefileTargetGenerator(const cmMakefileTargetGenerator&) = delete; ~cmMakefileTargetGenerator() override; + cmMakefileTargetGenerator& operator=(const cmMakefileTargetGenerator&) = + delete; + // construct using this factory call - static cmMakefileTargetGenerator* New(cmGeneratorTarget* tgt); + static std::unique_ptr<cmMakefileTargetGenerator> New( + cmGeneratorTarget* tgt); /* the main entry point for this class. Writes the Makefiles associated with this target */ @@ -195,11 +200,11 @@ protected: std::string TargetBuildDirectoryFull; // the stream for the build file - cmGeneratedFileStream* BuildFileStream; + std::unique_ptr<cmGeneratedFileStream> BuildFileStream; // the stream for the flag file std::string FlagFileNameFull; - cmGeneratedFileStream* FlagFileStream; + std::unique_ptr<cmGeneratedFileStream> FlagFileStream; class StringList : public std::vector<std::string> { }; @@ -207,7 +212,7 @@ protected: // the stream for the info file std::string InfoFileNameFull; - cmGeneratedFileStream* InfoFileStream; + std::unique_ptr<cmGeneratedFileStream> InfoFileStream; // files to clean std::set<std::string> CleanFiles; @@ -236,7 +241,7 @@ protected: // macOS content info. std::set<std::string> MacContentFolders; std::unique_ptr<cmOSXBundleGenerator> OSXBundleGenerator; - MacOSXContentGeneratorType* MacOSXContentGenerator; + std::unique_ptr<MacOSXContentGeneratorType> MacOSXContentGenerator; }; #endif |