diff options
author | Peter Würth <wuerth.peter@freenet.de> | 2022-11-17 11:12:26 (GMT) |
---|---|---|
committer | Peter Würth <wuerth.peter@freenet.de> | 2022-11-19 12:32:56 (GMT) |
commit | 60a5a39022c8c2504173d635732110b2550b7f91 (patch) | |
tree | fa0ef8f4a0512f483200d526a0b2c205e5857b37 | |
parent | d8c8e61633328b4e2247ce381e22ddc71dd0fbbf (diff) | |
download | CMake-60a5a39022c8c2504173d635732110b2550b7f91.zip CMake-60a5a39022c8c2504173d635732110b2550b7f91.tar.gz CMake-60a5a39022c8c2504173d635732110b2550b7f91.tar.bz2 |
cmCustomCommandGenerator: refactor GetComment to return std::string
Refactoring was done because EvaluateComment leaked memory.
-rw-r--r-- | Source/cmCustomCommandGenerator.cxx | 7 | ||||
-rw-r--r-- | Source/cmCustomCommandGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmGhsMultiTargetGenerator.cxx | 7 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 5 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 4 | ||||
-rw-r--r-- | Source/cmLocalUnixMakefileGenerator3.cxx | 6 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 6 |
7 files changed, 21 insertions, 16 deletions
diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 57b009a..54f0bab 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -463,9 +463,12 @@ std::string cmCustomCommandGenerator::GetInternalDepfile() const return this->ComputeInternalDepfile(this->OutputConfig, depfile); } -const char* cmCustomCommandGenerator::GetComment() const +cm::optional<std::string> cmCustomCommandGenerator::GetComment() const { - return this->CC->GetComment(); + if (const char* comment = this->CC->GetComment()) { + return comment; + } + return cm::nullopt; } std::string cmCustomCommandGenerator::GetWorkingDirectory() const diff --git a/Source/cmCustomCommandGenerator.h b/Source/cmCustomCommandGenerator.h index 73a8d38..4453654 100644 --- a/Source/cmCustomCommandGenerator.h +++ b/Source/cmCustomCommandGenerator.h @@ -58,7 +58,7 @@ public: unsigned int GetNumberOfCommands() const; std::string GetCommand(unsigned int c) const; void AppendArguments(unsigned int c, std::string& cmd) const; - const char* GetComment() const; + cm::optional<std::string> GetComment() const; std::string GetWorkingDirectory() const; std::vector<std::string> const& GetOutputs() const; std::vector<std::string> const& GetByproducts() const; diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 138d3f1..8471dfe 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -9,6 +9,8 @@ #include <utility> #include <vector> +#include <cm/optional> + #include "cmCustomCommand.h" #include "cmCustomCommandGenerator.h" #include "cmGeneratedFileStream.h" @@ -411,9 +413,8 @@ void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper( cmdLines.push_back("@echo off"); #endif // Echo the custom command's comment text. - const char* comment = ccg.GetComment(); - if (comment && *comment) { - std::string echocmd = cmStrCat("echo ", comment); + if (cm::optional<std::string> comment = ccg.GetComment()) { + std::string echocmd = cmStrCat("echo ", *comment); cmdLines.push_back(std::move(echocmd)); } diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 0e94de5..d57e2d1 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -13,6 +13,7 @@ #include <utility> #include <cm/memory> +#include <cm/optional> #include <cmext/algorithm> #include <cmext/string_view> @@ -2280,11 +2281,11 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile( } makefileStream << "\n"; - if (const char* comment = ccg.GetComment()) { + if (cm::optional<std::string> comment = ccg.GetComment()) { std::string echo_cmd = cmStrCat("echo ", (this->CurrentLocalGenerator->EscapeForShell( - comment, ccg.GetCC().GetEscapeAllowMakeVars()))); + *comment, ccg.GetCC().GetEscapeAllowMakeVars()))); makefileStream << "\t" << echo_cmd << "\n"; } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 9745142..af9abe5 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -3484,8 +3484,8 @@ std::string cmLocalGenerator::ConstructComment( cmCustomCommandGenerator const& ccg, const char* default_comment) const { // Check for a comment provided with the command. - if (ccg.GetComment()) { - return ccg.GetComment(); + if (cm::optional<std::string> comment = ccg.GetComment()) { + return *comment; } // Construct a reasonable default comment if possible. diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index de1d3cd..7172d34 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -10,6 +10,7 @@ #include <utility> #include <cm/memory> +#include <cm/optional> #include <cm/string_view> #include <cm/vector> #include <cmext/algorithm> @@ -945,9 +946,8 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand( // post-build command comments. Custom build step commands have // their comments generated elsewhere. if (echo_comment) { - const char* comment = ccg.GetComment(); - if (comment && *comment) { - this->AppendEcho(commands, comment, + if (cm::optional<std::string> comment = ccg.GetComment()) { + this->AppendEcho(commands, *comment, cmLocalUnixMakefileGenerator3::EchoGenerate); } } diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 383045d..538c036 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -10,6 +10,7 @@ #include <utility> #include <cm/memory> +#include <cm/optional> #include <cmext/algorithm> #include <windows.h> @@ -592,9 +593,8 @@ public: { cmCustomCommandGenerator ccg(cc, this->Config, this->LG); if (this->First) { - const char* comment = ccg.GetComment(); - if (comment && *comment) { - this->Stream << "\nDescription=\"" << this->LG->EscapeForXML(comment) + if (cm::optional<std::string> comment = ccg.GetComment()) { + this->Stream << "\nDescription=\"" << this->LG->EscapeForXML(*comment) << "\""; } this->Stream << "\nCommandLine=\""; |