summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaly Stakhovsky <vvs31415@gitlab.org>2018-09-05 20:08:17 -0400
committerVitaly Stakhovsky <vvs31415@gitlab.org>2018-09-05 20:08:17 -0400
commit437d0c16c72a45da8c81919f953859f5af71b19b (patch)
tree2a456a93a0eddf55d46313bd6d1bfbe668324d22
parentb0f769ad2da5162f7f65e13061b18b4538f06d9a (diff)
downloadcmake-437d0c16c72a45da8c81919f953859f5af71b19b.tar.gz
cmStateSnapshot::GetDefinition(): Return std::string const*
Expose std::string type used internally in cmDefinitions instead of const char*
-rw-r--r--Source/cmDefinitions.cxx6
-rw-r--r--Source/cmDefinitions.h4
-rw-r--r--Source/cmMakefile.cxx17
-rw-r--r--Source/cmOptionCommand.cxx4
-rw-r--r--Source/cmState.cxx4
-rw-r--r--Source/cmStateSnapshot.cxx7
-rw-r--r--Source/cmStateSnapshot.h2
7 files changed, 25 insertions, 19 deletions
diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index e766854a67..5fafaf9431 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -30,11 +30,11 @@ cmDefinitions::Def const& cmDefinitions::GetInternal(const std::string& key,
return begin->Map.insert(MapType::value_type(key, def)).first->second;
}
-const char* cmDefinitions::Get(const std::string& key, StackIter begin,
- StackIter end)
+const std::string* cmDefinitions::Get(const std::string& key, StackIter begin,
+ StackIter end)
{
Def const& def = cmDefinitions::GetInternal(key, begin, end, false);
- return def.Exists ? def.c_str() : nullptr;
+ return def.Exists ? &def : nullptr;
}
void cmDefinitions::Raise(const std::string& key, StackIter begin,
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index 528b157480..4ab5be6ccc 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -23,8 +23,8 @@ class cmDefinitions
typedef cmLinkedTree<cmDefinitions>::iterator StackIter;
public:
- static const char* Get(const std::string& key, StackIter begin,
- StackIter end);
+ static const std::string* Get(const std::string& key, StackIter begin,
+ StackIter end);
static void Raise(const std::string& key, StackIter begin, StackIter end);
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 6127b57175..8d2f932544 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -2368,8 +2368,10 @@ const char* cmMakefile::GetRequiredDefinition(const std::string& name) const
bool cmMakefile::IsDefinitionSet(const std::string& name) const
{
- const char* def = this->StateSnapshot.GetDefinition(name);
- if (!def) {
+ const char* def;
+ if (const std::string* d = this->StateSnapshot.GetDefinition(name)) {
+ def = d->c_str();
+ } else {
def = this->GetState()->GetInitializedCacheValue(name);
}
#ifdef CMAKE_BUILD_WITH_CMAKE
@@ -2385,8 +2387,10 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const
const char* cmMakefile::GetDefinition(const std::string& name) const
{
- const char* def = this->StateSnapshot.GetDefinition(name);
- if (!def) {
+ const char* def;
+ if (const std::string* d = this->StateSnapshot.GetDefinition(name)) {
+ def = d->c_str();
+ } else {
def = this->GetState()->GetInitializedCacheValue(name);
}
#ifdef CMAKE_BUILD_WITH_CMAKE
@@ -2402,8 +2406,9 @@ const char* cmMakefile::GetDefinition(const std::string& name) const
// A callback was executed and may have caused re-allocation of the
// variable storage. Look it up again for now.
// FIXME: Refactor variable storage to avoid this problem.
- def = this->StateSnapshot.GetDefinition(name);
- if (!def) {
+ if (const std::string* d = this->StateSnapshot.GetDefinition(name)) {
+ def = d->c_str();
+ } else {
def = this->GetState()->GetInitializedCacheValue(name);
}
}
diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx
index 239cd004f4..7d620bd1a5 100644
--- a/Source/cmOptionCommand.cxx
+++ b/Source/cmOptionCommand.cxx
@@ -31,7 +31,7 @@ bool cmOptionCommand::InitialPass(std::vector<std::string> const& args,
bool checkAndWarn = false;
{
auto status = this->Makefile->GetPolicyStatus(cmPolicies::CMP0077);
- const char* existsBeforeSet =
+ const auto* existsBeforeSet =
this->Makefile->GetStateSnapshot().GetDefinition(args[0]);
switch (status) {
case cmPolicies::WARN:
@@ -72,7 +72,7 @@ bool cmOptionCommand::InitialPass(std::vector<std::string> const& args,
args[1].c_str(), cmStateEnums::BOOL);
if (checkAndWarn) {
- const char* existsAfterSet =
+ const auto* existsAfterSet =
this->Makefile->GetStateSnapshot().GetDefinition(args[0]);
if (!existsAfterSet) {
std::ostringstream w;
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 565159479c..89738f459a 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -298,9 +298,9 @@ cmStateSnapshot cmState::Reset()
{
std::string srcDir =
- cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
+ *cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
std::string binDir =
- cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
+ *cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
this->VarTree.Clear();
pos->Vars = this->VarTree.Push(this->VarTree.Root());
pos->Parent = this->VarTree.Root();
diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx
index ec428a66d4..0379e7e71c 100644
--- a/Source/cmStateSnapshot.cxx
+++ b/Source/cmStateSnapshot.cxx
@@ -204,7 +204,8 @@ bool cmStateSnapshot::HasDefinedPolicyCMP0011()
return !this->Position->Policies->IsEmpty();
}
-const char* cmStateSnapshot::GetDefinition(std::string const& name) const
+std::string const* cmStateSnapshot::GetDefinition(
+ std::string const& name) const
{
assert(this->Position->Vars.IsValid());
return cmDefinitions::Get(name, this->Position->Vars, this->Position->Root);
@@ -426,8 +427,8 @@ std::string cmStateSnapshot::GetProjectName() const
void cmStateSnapshot::InitializeFromParent_ForSubdirsCommand()
{
- std::string currentSrcDir = this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR");
- std::string currentBinDir = this->GetDefinition("CMAKE_CURRENT_BINARY_DIR");
+ std::string currentSrcDir = *this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR");
+ std::string currentBinDir = *this->GetDefinition("CMAKE_CURRENT_BINARY_DIR");
this->InitializeFromParent();
this->SetDefinition("CMAKE_SOURCE_DIR", this->State->GetSourceDirectory());
this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory());
diff --git a/Source/cmStateSnapshot.h b/Source/cmStateSnapshot.h
index af5653b999..014c62e9d6 100644
--- a/Source/cmStateSnapshot.h
+++ b/Source/cmStateSnapshot.h
@@ -22,7 +22,7 @@ public:
cmStateSnapshot(cmState* state = nullptr);
cmStateSnapshot(cmState* state, cmStateDetail::PositionType position);
- const char* GetDefinition(std::string const& name) const;
+ std::string const* GetDefinition(std::string const& name) const;
bool IsInitialized(std::string const& name) const;
void SetDefinition(std::string const& name, std::string const& value);
void RemoveDefinition(std::string const& name);