From 3c632b89abf7edd2d82f21dc31d0a933775d8b85 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Wed, 18 Dec 2019 17:27:16 +0100 Subject: cmOrderDirectories: Modernize memory management --- Source/cmOrderDirectories.cxx | 23 +++++++++++------------ Source/cmOrderDirectories.h | 6 ++++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Source/cmOrderDirectories.cxx b/Source/cmOrderDirectories.cxx index 9ee7127..0369af0 100644 --- a/Source/cmOrderDirectories.cxx +++ b/Source/cmOrderDirectories.cxx @@ -8,9 +8,9 @@ #include #include +#include #include -#include "cmAlgorithms.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" #include "cmMessageType.h" @@ -250,11 +250,7 @@ cmOrderDirectories::cmOrderDirectories(cmGlobalGenerator* gg, this->Computed = false; } -cmOrderDirectories::~cmOrderDirectories() -{ - cmDeleteAll(this->ConstraintEntries); - cmDeleteAll(this->ImplicitDirEntries); -} +cmOrderDirectories::~cmOrderDirectories() = default; std::vector const& cmOrderDirectories::GetOrderedDirectories() { @@ -288,14 +284,16 @@ void cmOrderDirectories::AddRuntimeLibrary(std::string const& fullPath, if (this->IsImplicitDirectory(dir)) { this->ImplicitDirEntries.push_back( - new cmOrderDirectoriesConstraintSOName(this, fullPath, soname)); + cm::make_unique(this, fullPath, + soname)); return; } } // Construct the runtime information entry for this library. this->ConstraintEntries.push_back( - new cmOrderDirectoriesConstraintSOName(this, fullPath, soname)); + cm::make_unique(this, fullPath, + soname)); } else { // This can happen if the same library is linked multiple times. // In that case the runtime information check need be done only @@ -316,14 +314,15 @@ void cmOrderDirectories::AddLinkLibrary(std::string const& fullPath) std::string dir = cmSystemTools::GetFilenamePath(fullPath); if (this->IsImplicitDirectory(dir)) { this->ImplicitDirEntries.push_back( - new cmOrderDirectoriesConstraintLibrary(this, fullPath)); + cm::make_unique(this, + fullPath)); return; } } // Construct the link library entry. this->ConstraintEntries.push_back( - new cmOrderDirectoriesConstraintLibrary(this, fullPath)); + cm::make_unique(this, fullPath)); } } @@ -371,7 +370,7 @@ void cmOrderDirectories::CollectOriginalDirectories() this->AddOriginalDirectories(this->UserDirectories); // Add directories containing constraints. - for (cmOrderDirectoriesConstraint* entry : this->ConstraintEntries) { + for (const auto& entry : this->ConstraintEntries) { entry->AddDirectory(); } @@ -456,7 +455,7 @@ void cmOrderDirectories::FindImplicitConflicts() // Check for items in implicit link directories that have conflicts // in the explicit directories. std::ostringstream conflicts; - for (cmOrderDirectoriesConstraint* entry : this->ImplicitDirEntries) { + for (const auto& entry : this->ImplicitDirEntries) { entry->FindImplicitConflicts(conflicts); } diff --git a/Source/cmOrderDirectories.h b/Source/cmOrderDirectories.h index 23c5145..8ce53e0 100644 --- a/Source/cmOrderDirectories.h +++ b/Source/cmOrderDirectories.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include +#include #include #include #include @@ -46,8 +47,9 @@ private: std::vector OrderedDirectories; - std::vector ConstraintEntries; - std::vector ImplicitDirEntries; + std::vector> ConstraintEntries; + std::vector> + ImplicitDirEntries; std::vector UserDirectories; std::vector LanguageDirectories; cmsys::RegularExpression RemoveLibraryExtension; -- cgit v0.12 From 23130c539fc6ae1f4809e4c639a1a15a5f299c48 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Wed, 18 Dec 2019 17:50:42 +0100 Subject: cmInstalledFile: modernize memory management --- Source/cmInstalledFile.cxx | 17 +++++------------ Source/cmInstalledFile.h | 4 ++-- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Source/cmInstalledFile.cxx b/Source/cmInstalledFile.cxx index eabe590..a65ae03 100644 --- a/Source/cmInstalledFile.cxx +++ b/Source/cmInstalledFile.cxx @@ -4,7 +4,6 @@ #include -#include "cmAlgorithms.h" #include "cmGeneratorExpression.h" #include "cmListFileCache.h" #include "cmMakefile.h" @@ -12,17 +11,11 @@ cmInstalledFile::cmInstalledFile() = default; -cmInstalledFile::~cmInstalledFile() -{ - delete NameExpression; -} +cmInstalledFile::~cmInstalledFile() = default; cmInstalledFile::Property::Property() = default; -cmInstalledFile::Property::~Property() -{ - cmDeleteAll(this->ValueExpressions); -} +cmInstalledFile::Property::~Property() = default; void cmInstalledFile::SetName(cmMakefile* mf, const std::string& name) { @@ -30,7 +23,7 @@ void cmInstalledFile::SetName(cmMakefile* mf, const std::string& name) cmGeneratorExpression ge(backtrace); this->Name = name; - this->NameExpression = ge.Parse(name).release(); + this->NameExpression = ge.Parse(name); } std::string const& cmInstalledFile::GetName() const @@ -63,7 +56,7 @@ void cmInstalledFile::AppendProperty(cmMakefile const* mf, cmGeneratorExpression ge(backtrace); Property& property = this->Properties[prop]; - property.ValueExpressions.push_back(ge.Parse(value).release()); + property.ValueExpressions.push_back(ge.Parse(value)); } bool cmInstalledFile::HasProperty(const std::string& prop) const @@ -84,7 +77,7 @@ bool cmInstalledFile::GetProperty(const std::string& prop, std::string output; std::string separator; - for (auto ve : property.ValueExpressions) { + for (const auto& ve : property.ValueExpressions) { output += separator; output += ve->GetInput(); separator = ";"; diff --git a/Source/cmInstalledFile.h b/Source/cmInstalledFile.h index ee809ee..698151e 100644 --- a/Source/cmInstalledFile.h +++ b/Source/cmInstalledFile.h @@ -24,7 +24,7 @@ public: using CompiledGeneratorExpressionPtrType = std::unique_ptr; - using ExpressionVectorType = std::vector; + using ExpressionVectorType = std::vector; struct Property { @@ -73,7 +73,7 @@ public: private: std::string Name; - cmCompiledGeneratorExpression* NameExpression = nullptr; + CompiledGeneratorExpressionPtrType NameExpression; PropertyMapType Properties; }; -- cgit v0.12 From dc2daa6860285be066813d24ecca88f61ae3e18a Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Wed, 18 Dec 2019 18:37:05 +0100 Subject: cmFileMonitor: modernize memory management --- Source/cmFileMonitor.cxx | 35 +++++++++++++++-------------------- Source/cmFileMonitor.h | 3 ++- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Source/cmFileMonitor.cxx b/Source/cmFileMonitor.cxx index ac8a37e..8cfdb2d 100644 --- a/Source/cmFileMonitor.cxx +++ b/Source/cmFileMonitor.cxx @@ -7,9 +7,9 @@ #include #include -#include "cmsys/SystemTools.hxx" +#include -#include "cmAlgorithms.h" +#include "cmsys/SystemTools.hxx" namespace { void on_directory_change(uv_fs_event_t* handle, const char* filename, @@ -37,12 +37,12 @@ public: class cmVirtualDirectoryWatcher : public cmIBaseWatcher { public: - ~cmVirtualDirectoryWatcher() override { cmDeleteAll(this->Children); } + ~cmVirtualDirectoryWatcher() override = default; cmIBaseWatcher* Find(const std::string& ps) { const auto i = this->Children.find(ps); - return (i == this->Children.end()) ? nullptr : i->second; + return (i == this->Children.end()) ? nullptr : i->second.get(); } void Trigger(const std::string& pathSegment, int events, @@ -96,11 +96,7 @@ public: return result; } - void Reset() - { - cmDeleteAll(this->Children); - this->Children.clear(); - } + void Reset() { this->Children.clear(); } void AddChildWatcher(const std::string& ps, cmIBaseWatcher* watcher) { @@ -108,11 +104,12 @@ public: assert(this->Children.find(ps) == this->Children.end()); assert(watcher); - this->Children.emplace(std::make_pair(ps, watcher)); + this->Children.emplace(ps, std::unique_ptr(watcher)); } private: - std::unordered_map Children; // owned! + std::unordered_map> + Children; // owned! }; // Root of all the different (on windows!) root directories: @@ -295,14 +292,11 @@ void on_fs_close(uv_handle_t* handle) } // namespace cmFileMonitor::cmFileMonitor(uv_loop_t* l) - : Root(new cmRootWatcher(l)) + : Root(cm::make_unique(l)) { } -cmFileMonitor::~cmFileMonitor() -{ - delete this->Root; -} +cmFileMonitor::~cmFileMonitor() = default; void cmFileMonitor::MonitorPaths(const std::vector& paths, Callback const& cb) @@ -316,7 +310,7 @@ void cmFileMonitor::MonitorPaths(const std::vector& paths, if (segmentCount < 2) { // Expect at least rootdir and filename continue; } - cmVirtualDirectoryWatcher* currentWatcher = this->Root; + cmVirtualDirectoryWatcher* currentWatcher = this->Root.get(); for (size_t i = 0; i < segmentCount; ++i) { assert(currentWatcher); @@ -334,11 +328,12 @@ void cmFileMonitor::MonitorPaths(const std::vector& paths, cmIBaseWatcher* nextWatcher = currentWatcher->Find(currentSegment); if (!nextWatcher) { if (rootSegment) { // Root part - assert(currentWatcher == this->Root); - nextWatcher = new cmRootDirectoryWatcher(this->Root, currentSegment); + assert(currentWatcher == this->Root.get()); + nextWatcher = + new cmRootDirectoryWatcher(this->Root.get(), currentSegment); assert(currentWatcher->Find(currentSegment) == nextWatcher); } else if (fileSegment) { // File part - assert(currentWatcher != this->Root); + assert(currentWatcher != this->Root.get()); nextWatcher = new cmFileWatcher( dynamic_cast(currentWatcher), currentSegment, cb); diff --git a/Source/cmFileMonitor.h b/Source/cmFileMonitor.h index 7ffc929..b510a2c 100644 --- a/Source/cmFileMonitor.h +++ b/Source/cmFileMonitor.h @@ -5,6 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include +#include #include #include @@ -30,5 +31,5 @@ public: std::vector WatchedDirectories() const; private: - cmRootWatcher* Root; + std::unique_ptr Root; }; -- cgit v0.12