modermize: replace some raw pointers w/ unique_ptr

This commit is contained in:
Alex Turbov 2019-06-21 03:41:48 +03:00 committed by Brad King
parent cecf7e61c4
commit 5e52de7d57
10 changed files with 42 additions and 61 deletions

View File

@ -202,7 +202,6 @@ cmComputeLinkDepends::cmComputeLinkDepends(const cmGeneratorTarget* target,
cmComputeLinkDepends::~cmComputeLinkDepends() cmComputeLinkDepends::~cmComputeLinkDepends()
{ {
cmDeleteAll(this->InferredDependSets); cmDeleteAll(this->InferredDependSets);
delete this->CCG;
} }
void cmComputeLinkDepends::SetOldLinkDirMode(bool b) void cmComputeLinkDepends::SetOldLinkDirMode(bool b)
@ -632,7 +631,8 @@ void cmComputeLinkDepends::OrderLinkEntires()
// the same order in which the items were originally discovered in // the same order in which the items were originally discovered in
// the BFS. This should preserve the original order when no // the BFS. This should preserve the original order when no
// constraints disallow it. // constraints disallow it.
this->CCG = new cmComputeComponentGraph(this->EntryConstraintGraph); this->CCG =
cm::make_unique<cmComputeComponentGraph>(this->EntryConstraintGraph);
// The component graph is guaranteed to be acyclic. Start a DFS // The component graph is guaranteed to be acyclic. Start a DFS
// from every entry to compute a topological order for the // from every entry to compute a topological order for the

View File

@ -137,7 +137,7 @@ private:
std::set<int> Entries; std::set<int> Entries;
}; };
std::map<int, PendingComponent> PendingComponents; std::map<int, PendingComponent> PendingComponents;
cmComputeComponentGraph* CCG; std::unique_ptr<cmComputeComponentGraph> CCG;
std::vector<int> FinalLinkOrder; std::vector<int> FinalLinkOrder;
void DisplayComponents(); void DisplayComponents();
void VisitComponent(unsigned int c); void VisitComponent(unsigned int c);

View File

@ -92,7 +92,6 @@ cmGlobalGenerator::cmGlobalGenerator(cmake* cm)
// how long to let try compiles run // how long to let try compiles run
this->TryCompileTimeout = cmDuration::zero(); this->TryCompileTimeout = cmDuration::zero();
this->ExtraGenerator = nullptr;
this->CurrentConfigureMakefile = nullptr; this->CurrentConfigureMakefile = nullptr;
this->TryCompileOuterMakefile = nullptr; this->TryCompileOuterMakefile = nullptr;
@ -113,7 +112,6 @@ cmGlobalGenerator::cmGlobalGenerator(cmake* cm)
cmGlobalGenerator::~cmGlobalGenerator() cmGlobalGenerator::~cmGlobalGenerator()
{ {
this->ClearGeneratorMembers(); this->ClearGeneratorMembers();
delete this->ExtraGenerator;
} }
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
@ -1499,7 +1497,7 @@ void cmGlobalGenerator::Generate()
this->WriteSummary(); this->WriteSummary();
if (this->ExtraGenerator != nullptr) { if (this->ExtraGenerator) {
this->ExtraGenerator->Generate(); this->ExtraGenerator->Generate();
} }
@ -2720,8 +2718,8 @@ bool cmGlobalGenerator::IsReservedTarget(std::string const& name)
void cmGlobalGenerator::SetExternalMakefileProjectGenerator( void cmGlobalGenerator::SetExternalMakefileProjectGenerator(
cmExternalMakefileProjectGenerator* extraGenerator) cmExternalMakefileProjectGenerator* extraGenerator)
{ {
this->ExtraGenerator = extraGenerator; this->ExtraGenerator.reset(extraGenerator);
if (this->ExtraGenerator != nullptr) { if (this->ExtraGenerator) {
this->ExtraGenerator->SetGlobalGenerator(this); this->ExtraGenerator->SetGlobalGenerator(this);
} }
} }

View File

@ -618,7 +618,7 @@ private:
void ComputeBuildFileGenerators(); void ComputeBuildFileGenerators();
cmExternalMakefileProjectGenerator* ExtraGenerator; std::unique_ptr<cmExternalMakefileProjectGenerator> ExtraGenerator;
// track files replaced during a Generate // track files replaced during a Generate
std::vector<std::string> FilesReplacedDuringGenerate; std::vector<std::string> FilesReplacedDuringGenerate;

View File

@ -2,9 +2,9 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmMachO.h" #include "cmMachO.h"
#include "cmAlgorithms.h"
#include "cmsys/FStream.hxx" #include "cmsys/FStream.hxx"
#include <algorithm> #include <cstddef>
#include <stddef.h>
#include <string> #include <string>
#include <vector> #include <vector>
@ -120,7 +120,7 @@ protected:
// Implementation for reading Mach-O header and load commands. // Implementation for reading Mach-O header and load commands.
// This is 32 or 64 bit arch specific. // This is 32 or 64 bit arch specific.
template <class T> template <typename T>
class cmMachOHeaderAndLoadCommandsImpl : public cmMachOHeaderAndLoadCommands class cmMachOHeaderAndLoadCommandsImpl : public cmMachOHeaderAndLoadCommands
{ {
public: public:
@ -306,15 +306,11 @@ bool cmMachOInternal::read_mach_o(uint32_t file_offset)
// External class implementation. // External class implementation.
cmMachO::cmMachO(const char* fname) cmMachO::cmMachO(const char* fname)
: Internal(nullptr) : Internal(cm::make_unique<cmMachOInternal>(fname))
{ {
this->Internal = new cmMachOInternal(fname);
} }
cmMachO::~cmMachO() cmMachO::~cmMachO() = default;
{
delete this->Internal;
}
std::string const& cmMachO::GetErrorMessage() const std::string const& cmMachO::GetErrorMessage() const
{ {

View File

@ -41,7 +41,7 @@ public:
private: private:
friend class cmMachOInternal; friend class cmMachOInternal;
bool Valid() const; bool Valid() const;
cmMachOInternal* Internal; std::unique_ptr<cmMachOInternal> Internal;
}; };
#endif #endif

View File

@ -23,14 +23,12 @@
cmState::cmState() cmState::cmState()
{ {
this->CacheManager = new cmCacheManager; this->CacheManager = cm::make_unique<cmCacheManager>();
this->GlobVerificationManager = new cmGlobVerificationManager; this->GlobVerificationManager = cm::make_unique<cmGlobVerificationManager>();
} }
cmState::~cmState() cmState::~cmState()
{ {
delete this->CacheManager;
delete this->GlobVerificationManager;
cmDeleteAll(this->BuiltinCommands); cmDeleteAll(this->BuiltinCommands);
cmDeleteAll(this->ScriptedCommands); cmDeleteAll(this->ScriptedCommands);
} }

View File

@ -211,8 +211,8 @@ private:
std::map<std::string, cmCommand*> BuiltinCommands; std::map<std::string, cmCommand*> BuiltinCommands;
std::map<std::string, cmCommand*> ScriptedCommands; std::map<std::string, cmCommand*> ScriptedCommands;
cmPropertyMap GlobalProperties; cmPropertyMap GlobalProperties;
cmCacheManager* CacheManager; std::unique_ptr<cmCacheManager> CacheManager;
cmGlobVerificationManager* GlobVerificationManager; std::unique_ptr<cmGlobVerificationManager> GlobVerificationManager;
cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType> cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>
BuildsystemDirectory; BuildsystemDirectory;

View File

@ -141,12 +141,12 @@ cmake::cmake(Role role, cmState::Mode mode)
this->DebugOutput = false; this->DebugOutput = false;
this->DebugTryCompile = false; this->DebugTryCompile = false;
this->ClearBuildSystem = false; this->ClearBuildSystem = false;
this->FileTimeCache = new cmFileTimeCache; this->FileTimeCache = cm::make_unique<cmFileTimeCache>();
this->State = new cmState; this->State = cm::make_unique<cmState>();
this->State->SetMode(mode); this->State->SetMode(mode);
this->CurrentSnapshot = this->State->CreateBaseSnapshot(); this->CurrentSnapshot = this->State->CreateBaseSnapshot();
this->Messenger = new cmMessenger; this->Messenger = cm::make_unique<cmMessenger>();
#ifdef __APPLE__ #ifdef __APPLE__
struct rlimit rlp; struct rlimit rlp;
@ -165,7 +165,7 @@ cmake::cmake(Role role, cmState::Mode mode)
this->CurrentWorkingMode = NORMAL_MODE; this->CurrentWorkingMode = NORMAL_MODE;
#ifdef CMAKE_BUILD_WITH_CMAKE #ifdef CMAKE_BUILD_WITH_CMAKE
this->VariableWatch = new cmVariableWatch; this->VariableWatch = cm::make_unique<cmVariableWatch>();
#endif #endif
this->AddDefaultGenerators(); this->AddDefaultGenerators();
@ -222,17 +222,11 @@ cmake::cmake(Role role, cmState::Mode mode)
cmake::~cmake() cmake::~cmake()
{ {
delete this->State;
delete this->Messenger;
if (this->GlobalGenerator) { if (this->GlobalGenerator) {
delete this->GlobalGenerator; delete this->GlobalGenerator;
this->GlobalGenerator = nullptr; this->GlobalGenerator = nullptr;
} }
cmDeleteAll(this->Generators); cmDeleteAll(this->Generators);
#ifdef CMAKE_BUILD_WITH_CMAKE
delete this->VariableWatch;
#endif
delete this->FileTimeCache;
} }
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
@ -460,7 +454,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
return false; return false;
} }
// Register fake project commands that hint misuse in script mode. // Register fake project commands that hint misuse in script mode.
GetProjectCommandsInScriptMode(this->State); GetProjectCommandsInScriptMode(this->GetState());
this->ReadListFile(args, path); this->ReadListFile(args, path);
} else if (arg.find("--find-package", 0) == 0) { } else if (arg.find("--find-package", 0) == 0) {
findPackageMode = true; findPackageMode = true;
@ -1898,12 +1892,12 @@ const char* cmake::GetCacheDefinition(const std::string& name) const
void cmake::AddScriptingCommands() void cmake::AddScriptingCommands()
{ {
GetScriptingCommands(this->State); GetScriptingCommands(this->GetState());
} }
void cmake::AddProjectCommands() void cmake::AddProjectCommands()
{ {
GetProjectCommands(this->State); GetProjectCommands(this->GetState());
} }
void cmake::AddDefaultGenerators() void cmake::AddDefaultGenerators()
@ -2607,11 +2601,6 @@ std::vector<std::string> cmake::GetDebugConfigs()
return configs; return configs;
} }
cmMessenger* cmake::GetMessenger() const
{
return this->Messenger;
}
int cmake::Build(int jobs, const std::string& dir, int cmake::Build(int jobs, const std::string& dir,
const std::vector<std::string>& targets, const std::vector<std::string>& targets,
const std::string& config, const std::string& config,

View File

@ -307,7 +307,7 @@ public:
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
//! Get the variable watch object //! Get the variable watch object
cmVariableWatch* GetVariableWatch() { return this->VariableWatch; } cmVariableWatch* GetVariableWatch() { return this->VariableWatch.get(); }
#endif #endif
std::vector<cmDocumentationEntry> GetGeneratorsDocumentation(); std::vector<cmDocumentationEntry> GetGeneratorsDocumentation();
@ -348,18 +348,18 @@ public:
/** /**
* Get the file comparison class * Get the file comparison class
*/ */
cmFileTimeCache* GetFileTimeCache() { return this->FileTimeCache; } cmFileTimeCache* GetFileTimeCache() { return this->FileTimeCache.get(); }
// Get the selected log level for `message()` commands during the cmake run. //! Get the selected log level for `message()` commands during the cmake run.
LogLevel GetLogLevel() const { return this->MessageLogLevel; } LogLevel GetLogLevel() const { return this->MessageLogLevel; }
void SetLogLevel(LogLevel level) { this->MessageLogLevel = level; } void SetLogLevel(LogLevel level) { this->MessageLogLevel = level; }
static LogLevel StringToLogLevel(const std::string& levelStr); static LogLevel StringToLogLevel(const std::string& levelStr);
// Do we want debug output during the cmake run. //! Do we want debug output during the cmake run.
bool GetDebugOutput() { return this->DebugOutput; } bool GetDebugOutput() { return this->DebugOutput; }
void SetDebugOutputOn(bool b) { this->DebugOutput = b; } void SetDebugOutputOn(bool b) { this->DebugOutput = b; }
// Do we want trace output during the cmake run. //! Do we want trace output during the cmake run.
bool GetTrace() { return this->Trace; } bool GetTrace() { return this->Trace; }
void SetTrace(bool b) { this->Trace = b; } void SetTrace(bool b) { this->Trace = b; }
bool GetTraceExpand() { return this->TraceExpand; } bool GetTraceExpand() { return this->TraceExpand; }
@ -396,31 +396,31 @@ public:
return this->CMakeEditCommand; return this->CMakeEditCommand;
} }
cmMessenger* GetMessenger() const; cmMessenger* GetMessenger() const { return this->Messenger.get(); }
/* /**
* Get the state of the suppression of developer (author) warnings. * Get the state of the suppression of developer (author) warnings.
* Returns false, by default, if developer warnings should be shown, true * Returns false, by default, if developer warnings should be shown, true
* otherwise. * otherwise.
*/ */
bool GetSuppressDevWarnings() const; bool GetSuppressDevWarnings() const;
/* /**
* Set the state of the suppression of developer (author) warnings. * Set the state of the suppression of developer (author) warnings.
*/ */
void SetSuppressDevWarnings(bool v); void SetSuppressDevWarnings(bool v);
/* /**
* Get the state of the suppression of deprecated warnings. * Get the state of the suppression of deprecated warnings.
* Returns false, by default, if deprecated warnings should be shown, true * Returns false, by default, if deprecated warnings should be shown, true
* otherwise. * otherwise.
*/ */
bool GetSuppressDeprecatedWarnings() const; bool GetSuppressDeprecatedWarnings() const;
/* /**
* Set the state of the suppression of deprecated warnings. * Set the state of the suppression of deprecated warnings.
*/ */
void SetSuppressDeprecatedWarnings(bool v); void SetSuppressDeprecatedWarnings(bool v);
/* /**
* Get the state of treating developer (author) warnings as errors. * Get the state of treating developer (author) warnings as errors.
* Returns false, by default, if warnings should not be treated as errors, * Returns false, by default, if warnings should not be treated as errors,
* true otherwise. * true otherwise.
@ -431,7 +431,7 @@ public:
*/ */
void SetDevWarningsAsErrors(bool v); void SetDevWarningsAsErrors(bool v);
/* /**
* Get the state of treating deprecated warnings as errors. * Get the state of treating deprecated warnings as errors.
* Returns false, by default, if warnings should not be treated as errors, * Returns false, by default, if warnings should not be treated as errors,
* true otherwise. * true otherwise.
@ -459,7 +459,7 @@ public:
void UnwatchUnusedCli(const std::string& var); void UnwatchUnusedCli(const std::string& var);
void WatchUnusedCli(const std::string& var); void WatchUnusedCli(const std::string& var);
cmState* GetState() const { return this->State; } cmState* GetState() const { return this->State.get(); }
void SetCurrentSnapshot(cmStateSnapshot const& snapshot) void SetCurrentSnapshot(cmStateSnapshot const& snapshot)
{ {
this->CurrentSnapshot = snapshot; this->CurrentSnapshot = snapshot;
@ -537,18 +537,18 @@ private:
std::unordered_set<std::string> HeaderFileExtensionsSet; std::unordered_set<std::string> HeaderFileExtensionsSet;
bool ClearBuildSystem; bool ClearBuildSystem;
bool DebugTryCompile; bool DebugTryCompile;
cmFileTimeCache* FileTimeCache; std::unique_ptr<cmFileTimeCache> FileTimeCache;
std::string GraphVizFile; std::string GraphVizFile;
InstalledFilesMap InstalledFiles; InstalledFilesMap InstalledFiles;
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
cmVariableWatch* VariableWatch; std::unique_ptr<cmVariableWatch> VariableWatch;
std::unique_ptr<cmFileAPI> FileAPI; std::unique_ptr<cmFileAPI> FileAPI;
#endif #endif
cmState* State; std::unique_ptr<cmState> State;
cmStateSnapshot CurrentSnapshot; cmStateSnapshot CurrentSnapshot;
cmMessenger* Messenger; std::unique_ptr<cmMessenger> Messenger;
std::vector<std::string> TraceOnlyThisSources; std::vector<std::string> TraceOnlyThisSources;
@ -556,7 +556,7 @@ private:
void UpdateConversionPathTable(); void UpdateConversionPathTable();
// Print a list of valid generators to stderr. //! Print a list of valid generators to stderr.
void PrintGeneratorList(); void PrintGeneratorList();
std::unique_ptr<cmGlobalGenerator> EvaluateDefaultGlobalGenerator(); std::unique_ptr<cmGlobalGenerator> EvaluateDefaultGlobalGenerator();