From c7b50349de5e56d7584fa644832170d1e08ef62e Mon Sep 17 00:00:00 2001 From: Vitaly Stakhovsky Date: Wed, 4 Nov 2020 10:00:00 -0500 Subject: cmSourceFile::GetPropertyForUser: return cmProp also fix GetSafeProperty() return type --- Source/cmGetPropertyCommand.cxx | 2 +- Source/cmGetSourceFilePropertyCommand.cxx | 5 +++-- Source/cmQtAutoGenInitializer.cxx | 2 +- Source/cmSourceFile.cxx | 19 ++++++++++--------- Source/cmSourceFile.h | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx index 3a5b39d..b1dc72d 100644 --- a/Source/cmGetPropertyCommand.cxx +++ b/Source/cmGetPropertyCommand.cxx @@ -391,7 +391,7 @@ bool HandleSourceMode(cmExecutionStatus& status, const std::string& name, if (cmSourceFile* sf = directory_makefile.GetOrCreateSource(source_file_absolute_path)) { return StoreResult(infoType, status.GetMakefile(), variable, - sf->GetPropertyForUser(propertyName)); + cmToCStr(sf->GetPropertyForUser(propertyName))); } status.SetError( cmStrCat("given SOURCE name that could not be found or created: ", diff --git a/Source/cmGetSourceFilePropertyCommand.cxx b/Source/cmGetSourceFilePropertyCommand.cxx index 5395bc8..212a968 100644 --- a/Source/cmGetSourceFilePropertyCommand.cxx +++ b/Source/cmGetSourceFilePropertyCommand.cxx @@ -4,6 +4,7 @@ #include "cmExecutionStatus.h" #include "cmMakefile.h" +#include "cmProperty.h" #include "cmSetPropertyCommand.h" #include "cmSourceFile.h" @@ -57,14 +58,14 @@ bool cmGetSourceFilePropertyCommand(std::vector const& args, } if (sf) { - const char* prop = nullptr; + cmProp prop = nullptr; if (!args[property_arg_index].empty()) { prop = sf->GetPropertyForUser(args[property_arg_index]); } if (prop) { // Set the value on the original Makefile scope, not the scope of the // requested directory. - status.GetMakefile().AddDefinition(var, prop); + status.GetMakefile().AddDefinition(var, *prop); return true; } } diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 3b62e9c..f2696a6 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -807,7 +807,7 @@ bool cmQtAutoGenInitializer::InitScanFiles() qrc.Generated = sf->GetIsGenerated(); // RCC options { - std::string const opts = sf->GetSafeProperty(kw.AUTORCC_OPTIONS); + std::string const& opts = sf->GetSafeProperty(kw.AUTORCC_OPTIONS); if (!opts.empty()) { cmExpandList(opts, qrc.Options); } diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 61f48e9..39074a5 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -310,7 +310,7 @@ void cmSourceFile::AppendProperty(const std::string& prop, } } -const char* cmSourceFile::GetPropertyForUser(const std::string& prop) +cmProp cmSourceFile::GetPropertyForUser(const std::string& prop) { // This method is a consequence of design history and backwards // compatibility. GetProperty is (and should be) a const method. @@ -334,13 +334,12 @@ const char* cmSourceFile::GetPropertyForUser(const std::string& prop) // Similarly, LANGUAGE can be determined by the file extension // if it is requested by the user. if (prop == propLANGUAGE) { - // The c_str pointer is valid until `this->Language` is modified. - return this->GetOrDetermineLanguage().c_str(); + // The pointer is valid until `this->Language` is modified. + return &this->GetOrDetermineLanguage(); } // Perform the normal property lookup. - cmProp p = this->GetProperty(prop); - return p ? p->c_str() : nullptr; + return this->GetProperty(prop); } cmProp cmSourceFile::GetProperty(const std::string& prop) const @@ -398,13 +397,15 @@ cmProp cmSourceFile::GetProperty(const std::string& prop) const return retVal; } -const char* cmSourceFile::GetSafeProperty(const std::string& prop) const +const std::string& cmSourceFile::GetSafeProperty(const std::string& prop) const { cmProp ret = this->GetProperty(prop); - if (!ret) { - return ""; + if (ret) { + return *ret; } - return ret->c_str(); + + static std::string const s_empty; + return s_empty; } bool cmSourceFile::GetPropertyAsBool(const std::string& prop) const diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index 3196b3f..3ad2664 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -47,12 +47,12 @@ public: //! Might return a nullptr if the property is not set or invalid cmProp GetProperty(const std::string& prop) const; //! Always returns a valid pointer - const char* GetSafeProperty(const std::string& prop) const; + const std::string& GetSafeProperty(const std::string& prop) const; bool GetPropertyAsBool(const std::string& prop) const; /** Implement getting a property when called from a CMake language command like get_property or get_source_file_property. */ - const char* GetPropertyForUser(const std::string& prop); + cmProp GetPropertyForUser(const std::string& prop); //! Checks is the GENERATED property is set and true /// @return Equivalent to GetPropertyAsBool("GENERATED") -- cgit v0.12