mirror of
https://github.com/reactos/CMake.git
synced 2025-02-26 15:05:34 +00:00
Merge topic 'modernize-memory-management'
dc2daa6860 cmFileMonitor: modernize memory management 23130c539f cmInstalledFile: modernize memory management 3c632b89ab cmOrderDirectories: Modernize memory management Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !4149
This commit is contained in:
commit
2fafa66b18
@ -7,9 +7,9 @@
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
#include "cmsys/SystemTools.hxx"
|
||||
#include <cm/memory>
|
||||
|
||||
#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<cmIBaseWatcher>(watcher));
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, cmIBaseWatcher*> Children; // owned!
|
||||
std::unordered_map<std::string, std::unique_ptr<cmIBaseWatcher>>
|
||||
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<cmRootWatcher>(l))
|
||||
{
|
||||
}
|
||||
|
||||
cmFileMonitor::~cmFileMonitor()
|
||||
{
|
||||
delete this->Root;
|
||||
}
|
||||
cmFileMonitor::~cmFileMonitor() = default;
|
||||
|
||||
void cmFileMonitor::MonitorPaths(const std::vector<std::string>& paths,
|
||||
Callback const& cb)
|
||||
@ -316,7 +310,7 @@ void cmFileMonitor::MonitorPaths(const std::vector<std::string>& 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<std::string>& 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<cmRealDirectoryWatcher*>(currentWatcher),
|
||||
currentSegment, cb);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -30,5 +31,5 @@ public:
|
||||
std::vector<std::string> WatchedDirectories() const;
|
||||
|
||||
private:
|
||||
cmRootWatcher* Root;
|
||||
std::unique_ptr<cmRootWatcher> Root;
|
||||
};
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#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 = ";";
|
||||
|
@ -24,7 +24,7 @@ public:
|
||||
using CompiledGeneratorExpressionPtrType =
|
||||
std::unique_ptr<cmCompiledGeneratorExpression>;
|
||||
|
||||
using ExpressionVectorType = std::vector<cmCompiledGeneratorExpression*>;
|
||||
using ExpressionVectorType = std::vector<CompiledGeneratorExpressionPtrType>;
|
||||
|
||||
struct Property
|
||||
{
|
||||
@ -73,7 +73,7 @@ public:
|
||||
|
||||
private:
|
||||
std::string Name;
|
||||
cmCompiledGeneratorExpression* NameExpression = nullptr;
|
||||
CompiledGeneratorExpressionPtrType NameExpression;
|
||||
PropertyMapType Properties;
|
||||
};
|
||||
|
||||
|
@ -8,9 +8,9 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/memory>
|
||||
#include <cmext/algorithm>
|
||||
|
||||
#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<std::string> 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<cmOrderDirectoriesConstraintSOName>(this, fullPath,
|
||||
soname));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Construct the runtime information entry for this library.
|
||||
this->ConstraintEntries.push_back(
|
||||
new cmOrderDirectoriesConstraintSOName(this, fullPath, soname));
|
||||
cm::make_unique<cmOrderDirectoriesConstraintSOName>(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<cmOrderDirectoriesConstraintLibrary>(this,
|
||||
fullPath));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Construct the link library entry.
|
||||
this->ConstraintEntries.push_back(
|
||||
new cmOrderDirectoriesConstraintLibrary(this, fullPath));
|
||||
cm::make_unique<cmOrderDirectoriesConstraintLibrary>(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);
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@ -46,8 +47,9 @@ private:
|
||||
|
||||
std::vector<std::string> OrderedDirectories;
|
||||
|
||||
std::vector<cmOrderDirectoriesConstraint*> ConstraintEntries;
|
||||
std::vector<cmOrderDirectoriesConstraint*> ImplicitDirEntries;
|
||||
std::vector<std::unique_ptr<cmOrderDirectoriesConstraint>> ConstraintEntries;
|
||||
std::vector<std::unique_ptr<cmOrderDirectoriesConstraint>>
|
||||
ImplicitDirEntries;
|
||||
std::vector<std::string> UserDirectories;
|
||||
std::vector<std::string> LanguageDirectories;
|
||||
cmsys::RegularExpression RemoveLibraryExtension;
|
||||
|
Loading…
x
Reference in New Issue
Block a user