From aa5fed5052f903614a06c55786a1f682fee787a5 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Fri, 26 May 2023 11:09:07 +0200 Subject: SetProperty: suppress raw pointer usage --- Source/cmCMakeLanguageCommand.cxx | 2 +- Source/cmCPluginAPI.cxx | 6 +++++- Source/cmCacheManager.cxx | 37 +++++++++++++++++++++++++------------ Source/cmCacheManager.h | 5 +++-- Source/cmFindPackageCommand.cxx | 10 +++++----- Source/cmGlobalGenerator.cxx | 2 +- Source/cmMakefile.cxx | 4 ---- Source/cmMakefile.h | 7 +++++-- Source/cmPropertyMap.cxx | 9 ++------- Source/cmPropertyMap.h | 3 ++- Source/cmSourceFile.cxx | 12 +----------- Source/cmSourceFile.h | 6 +++++- Source/cmState.cxx | 11 ++++++----- Source/cmState.h | 2 +- Source/cmStateDirectory.cxx | 16 ++-------------- Source/cmStateDirectory.h | 8 ++++++-- Source/cmTarget.cxx | 32 ++------------------------------ Source/cmTarget.h | 5 ++++- Source/cmTest.cxx | 4 ---- Source/cmTest.h | 6 +++++- Source/cmake.cxx | 4 ---- Source/cmake.h | 5 ++++- 22 files changed, 85 insertions(+), 111 deletions(-) diff --git a/Source/cmCMakeLanguageCommand.cxx b/Source/cmCMakeLanguageCommand.cxx index 68e658c..c7e9209 100644 --- a/Source/cmCMakeLanguageCommand.cxx +++ b/Source/cmCMakeLanguageCommand.cxx @@ -303,7 +303,7 @@ bool cmCMakeLanguageCommandSET_DEPENDENCY_PROVIDER( state->SetDependencyProvider({ parsedArgs.Command, methods }); state->SetGlobalProperty( fcmasProperty, - supportsFetchContentMakeAvailableSerial ? parsedArgs.Command.c_str() : ""); + supportsFetchContentMakeAvailableSerial ? parsedArgs.Command : ""); return true; } diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index abec968..c2c5bdb 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -615,7 +615,11 @@ static void CCONV cmSourceFileSetProperty(void* arg, const char* prop, { cmCPluginAPISourceFile* sf = static_cast(arg); if (cmSourceFile* rsf = sf->RealSourceFile) { - rsf->SetProperty(prop, value); + if (value == nullptr) { + rsf->SetProperty(prop, nullptr); + } else { + rsf->SetProperty(prop, value); + } } else if (prop) { if (!value) { value = "NOTFOUND"; diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index d95dcc4..8633de1 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -84,7 +84,7 @@ bool cmCacheManager::LoadCache(const std::string& path, bool internal, continue; } } - e.SetProperty("HELPSTRING", helpString.c_str()); + e.SetProperty("HELPSTRING", helpString); if (cmState::ParseCacheEntry(realbuffer, entryKey, e.Value, e.Type)) { if (excludes.find(entryKey) == excludes.end()) { // Load internal values if internal is set. @@ -102,7 +102,7 @@ bool cmCacheManager::LoadCache(const std::string& path, bool internal, " loaded from external file. " "To change this value edit this file: ", path, "/CMakeCache.txt"); - e.SetProperty("HELPSTRING", helpString.c_str()); + e.SetProperty("HELPSTRING", helpString); } if (!this->ReadPropertyEntry(entryKey, e)) { e.Initialized = true; @@ -186,11 +186,11 @@ bool cmCacheManager::ReadPropertyEntry(const std::string& entryKey, std::string key = entryKey.substr(0, entryKey.size() - plen); if (auto* entry = this->GetCacheEntry(key)) { // Store this property on its entry. - entry->SetProperty(p, e.Value.c_str()); + entry->SetProperty(p, e.Value); } else { // Create an entry and store the property. CacheEntry& ne = this->Cache[key]; - ne.SetProperty(p, e.Value.c_str()); + ne.SetProperty(p, e.Value); } return true; } @@ -541,10 +541,11 @@ void cmCacheManager::AddCacheEntry(const std::string& key, cmValue value, cmSystemTools::ConvertToUnixSlashes(e.Value); } } - e.SetProperty("HELPSTRING", - helpString - ? helpString - : "(This variable does not exist and should not be used)"); + e.SetProperty( + "HELPSTRING", + helpString ? std::string{ helpString } + : std::string{ + "(This variable does not exist and should not be used)" }); } void cmCacheManager::CacheEntry::SetValue(cmValue value) @@ -580,12 +581,12 @@ bool cmCacheManager::CacheEntry::GetPropertyAsBool( } void cmCacheManager::CacheEntry::SetProperty(const std::string& prop, - const char* value) + const std::string& value) { if (prop == "TYPE") { - this->Type = cmState::StringToCacheEntryType(value ? value : "STRING"); + this->Type = cmState::StringToCacheEntryType(value); } else if (prop == "VALUE") { - this->Value = value ? value : ""; + this->Value = value; } else { this->Properties.SetProperty(prop, value); } @@ -593,7 +594,19 @@ void cmCacheManager::CacheEntry::SetProperty(const std::string& prop, void cmCacheManager::CacheEntry::SetProperty(const std::string& p, bool v) { - this->SetProperty(p, v ? "ON" : "OFF"); + this->SetProperty(p, v ? std::string{ "ON" } : std::string{ "OFF" }); +} + +void cmCacheManager::CacheEntry::SetProperty(const std::string& prop, + std::nullptr_t) +{ + if (prop == "TYPE") { + this->Type = cmState::StringToCacheEntryType("STRING"); + } else if (prop == "VALUE") { + this->Value = ""; + } else { + this->Properties.SetProperty(prop, cmValue{ nullptr }); + } } void cmCacheManager::CacheEntry::AppendProperty(const std::string& prop, diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index bc3fb51..a2da0b5 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -39,8 +39,9 @@ class cmCacheManager std::vector GetPropertyList() const; cmValue GetProperty(const std::string& property) const; bool GetPropertyAsBool(const std::string& property) const; - void SetProperty(const std::string& property, const char* value); + void SetProperty(const std::string& property, const std::string& value); void SetProperty(const std::string& property, bool value); + void SetProperty(const std::string& property, std::nullptr_t); void AppendProperty(const std::string& property, const std::string& value, bool asString = false); @@ -127,7 +128,7 @@ public: std::string const& value) { if (auto* entry = this->GetCacheEntry(key)) { - entry->SetProperty(propName, value.c_str()); + entry->SetProperty(propName, value); } } diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 98b085c..1c2a937 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -1804,11 +1804,11 @@ void cmFindPackageCommand::AppendToFoundProperty(const bool found) notFoundContents.push_back(this->Name); } - this->Makefile->GetState()->SetGlobalProperty( - "PACKAGES_FOUND", foundContents.to_string().c_str()); + this->Makefile->GetState()->SetGlobalProperty("PACKAGES_FOUND", + foundContents.to_string()); - this->Makefile->GetState()->SetGlobalProperty( - "PACKAGES_NOT_FOUND", notFoundContents.to_string().c_str()); + this->Makefile->GetState()->SetGlobalProperty("PACKAGES_NOT_FOUND", + notFoundContents.to_string()); } void cmFindPackageCommand::AppendSuccessInformation() @@ -1845,7 +1845,7 @@ void cmFindPackageCommand::AppendSuccessInformation() cmStrCat(this->VersionExact ? "==" : ">=", ' ', this->Version); } this->Makefile->GetState()->SetGlobalProperty(versionInfoPropName, - versionInfo.c_str()); + versionInfo); if (this->Required) { std::string const requiredInfoPropName = cmStrCat("_CMAKE_", this->Name, "_TYPE"); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 5d0f8b2..22d5aeb 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -268,7 +268,7 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang, changeVars += ";"; changeVars += *cname; this->GetCMakeInstance()->GetState()->SetGlobalProperty( - "__CMAKE_DELETE_CACHE_CHANGE_VARS_", changeVars.c_str()); + "__CMAKE_DELETE_CACHE_CHANGE_VARS_", changeVars); } } } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 01afc44..585924d 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4044,10 +4044,6 @@ int cmMakefile::ConfigureFile(const std::string& infile, return res; } -void cmMakefile::SetProperty(const std::string& prop, const char* value) -{ - this->StateSnapshot.GetDirectory().SetProperty(prop, value, this->Backtrace); -} void cmMakefile::SetProperty(const std::string& prop, cmValue value) { this->StateSnapshot.GetDirectory().SetProperty(prop, value, this->Backtrace); diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index d1f5be5..6fdadab 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -425,7 +425,7 @@ public: */ void SetIncludeRegularExpression(const std::string& regex) { - this->SetProperty("INCLUDE_REGULAR_EXPRESSION", regex.c_str()); + this->SetProperty("INCLUDE_REGULAR_EXPRESSION", regex); } const std::string& GetIncludeRegularExpression() const { @@ -801,8 +801,11 @@ public: std::string& debugBuffer) const; //! Set/Get a property of this directory - void SetProperty(const std::string& prop, const char* value); void SetProperty(const std::string& prop, cmValue value); + void SetProperty(const std::string& prop, std::nullptr_t) + { + this->SetProperty(prop, cmValue{ nullptr }); + } void SetProperty(const std::string& prop, const std::string& value) { this->SetProperty(prop, cmValue(value)); diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx index b15000f..568a3d2 100644 --- a/Source/cmPropertyMap.cxx +++ b/Source/cmPropertyMap.cxx @@ -10,14 +10,9 @@ void cmPropertyMap::Clear() this->Map_.clear(); } -void cmPropertyMap::SetProperty(const std::string& name, const char* value) +void cmPropertyMap::SetProperty(const std::string& name, std::nullptr_t) { - if (!value) { - this->Map_.erase(name); - return; - } - - this->Map_[name] = value; + this->Map_.erase(name); } void cmPropertyMap::SetProperty(const std::string& name, cmValue value) { diff --git a/Source/cmPropertyMap.h b/Source/cmPropertyMap.h index f50b65e..23b50a5 100644 --- a/Source/cmPropertyMap.h +++ b/Source/cmPropertyMap.h @@ -4,6 +4,7 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include #include #include #include @@ -25,7 +26,7 @@ public: // -- Properties //! Set the property value - void SetProperty(const std::string& name, const char* value); + void SetProperty(const std::string& name, std::nullptr_t); void SetProperty(const std::string& name, cmValue value); void SetProperty(const std::string& name, const std::string& value) { diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 6224d0e..3403745 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -278,8 +278,7 @@ bool cmSourceFile::Matches(cmSourceFileLocation const& loc) return this->Location.Matches(loc); } -template -void cmSourceFile::StoreProperty(const std::string& prop, ValueType value) +void cmSourceFile::SetProperty(const std::string& prop, cmValue value) { if (prop == propINCLUDE_DIRECTORIES) { this->IncludeDirectories.clear(); @@ -304,15 +303,6 @@ void cmSourceFile::StoreProperty(const std::string& prop, ValueType value) } } -void cmSourceFile::SetProperty(const std::string& prop, const char* value) -{ - this->StoreProperty(prop, value); -} -void cmSourceFile::SetProperty(const std::string& prop, cmValue value) -{ - this->StoreProperty(prop, value); -} - void cmSourceFile::AppendProperty(const std::string& prop, const std::string& value, bool asString) { diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index 9308af4..3f070a7 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -4,6 +4,7 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include #include #include #include @@ -41,8 +42,11 @@ public: void SetCustomCommand(std::unique_ptr cc); //! Set/Get a property of this source file - void SetProperty(const std::string& prop, const char* value); void SetProperty(const std::string& prop, cmValue value); + void SetProperty(const std::string& prop, std::nullptr_t) + { + this->SetProperty(prop, cmValue{ nullptr }); + } void SetProperty(const std::string& prop, const std::string& value) { this->SetProperty(prop, cmValue(value)); diff --git a/Source/cmState.cxx b/Source/cmState.cxx index bbafc92..a72f830 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -564,7 +564,8 @@ void cmState::RemoveUserDefinedCommands() this->ScriptedCommands.clear(); } -void cmState::SetGlobalProperty(const std::string& prop, const char* value) +void cmState::SetGlobalProperty(const std::string& prop, + const std::string& value) { this->GlobalProperties.SetProperty(prop, value); } @@ -583,10 +584,10 @@ cmValue cmState::GetGlobalProperty(const std::string& prop) { if (prop == "CACHE_VARIABLES") { std::vector cacheKeys = this->GetCacheEntryKeys(); - this->SetGlobalProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str()); + this->SetGlobalProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";")); } else if (prop == "COMMANDS") { std::vector commands = this->GetCommandNames(); - this->SetGlobalProperty("COMMANDS", cmJoin(commands, ";").c_str()); + this->SetGlobalProperty("COMMANDS", cmJoin(commands, ";")); } else if (prop == "IN_TRY_COMPILE") { this->SetGlobalProperty( "IN_TRY_COMPILE", @@ -597,10 +598,10 @@ cmValue cmState::GetGlobalProperty(const std::string& prop) } else if (prop == "ENABLED_LANGUAGES") { std::string langs; langs = cmJoin(this->EnabledLanguages, ";"); - this->SetGlobalProperty("ENABLED_LANGUAGES", langs.c_str()); + this->SetGlobalProperty("ENABLED_LANGUAGES", langs); } else if (prop == "CMAKE_ROLE") { std::string mode = this->GetModeString(); - this->SetGlobalProperty("CMAKE_ROLE", mode.c_str()); + this->SetGlobalProperty("CMAKE_ROLE", mode); } #define STRING_LIST_ELEMENT(F) ";" #F if (prop == "CMAKE_C_KNOWN_FEATURES") { diff --git a/Source/cmState.h b/Source/cmState.h index 0a42df0..d9d2c21 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -194,7 +194,7 @@ public: void RemoveUserDefinedCommands(); std::vector GetCommandNames() const; - void SetGlobalProperty(const std::string& prop, const char* value); + void SetGlobalProperty(const std::string& prop, const std::string& value); void SetGlobalProperty(const std::string& prop, cmValue value); void AppendGlobalProperty(const std::string& prop, const std::string& value, bool asString = false); diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index 20e4604..6e6fcbd 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -271,9 +271,8 @@ void cmStateDirectory::ClearLinkDirectories() this->Snapshot_.Position->LinkDirectoriesPosition); } -template -void cmStateDirectory::StoreProperty(const std::string& prop, ValueType value, - cmListFileBacktrace const& lfbt) +void cmStateDirectory::SetProperty(const std::string& prop, cmValue value, + cmListFileBacktrace const& lfbt) { if (prop == "INCLUDE_DIRECTORIES") { if (!value) { @@ -319,17 +318,6 @@ void cmStateDirectory::StoreProperty(const std::string& prop, ValueType value, this->DirectoryState->Properties.SetProperty(prop, value); } -void cmStateDirectory::SetProperty(const std::string& prop, const char* value, - cmListFileBacktrace const& lfbt) -{ - this->StoreProperty(prop, value, lfbt); -} -void cmStateDirectory::SetProperty(const std::string& prop, cmValue value, - cmListFileBacktrace const& lfbt) -{ - this->StoreProperty(prop, value, lfbt); -} - void cmStateDirectory::AppendProperty(const std::string& prop, const std::string& value, bool asString, cmListFileBacktrace const& lfbt) diff --git a/Source/cmStateDirectory.h b/Source/cmStateDirectory.h index 8c6b09d..55cc716 100644 --- a/Source/cmStateDirectory.h +++ b/Source/cmStateDirectory.h @@ -5,6 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include #include #include @@ -57,10 +58,13 @@ public: void SetLinkDirectories(BT const& vecs); void ClearLinkDirectories(); - void SetProperty(const std::string& prop, const char* value, - cmListFileBacktrace const& lfbt); void SetProperty(const std::string& prop, cmValue value, cmListFileBacktrace const& lfbt); + void SetProperty(const std::string& prop, std::nullptr_t, + cmListFileBacktrace const& lfbt) + { + this->SetProperty(prop, cmValue{ nullptr }, lfbt); + } void AppendProperty(const std::string& prop, const std::string& value, bool asString, cmListFileBacktrace const& lfbt); cmValue GetProperty(const std::string& prop) const; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 0fbe430..b55554d 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1810,26 +1810,7 @@ MAKE_PROP(INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE); #undef MAKE_PROP } -namespace { -// to workaround bug on GCC/AIX -// Define a template to force conversion to std::string -template -std::string ConvertToString(ValueType value); - -template <> -std::string ConvertToString(const char* value) -{ - return std::string(value); -} -template <> -std::string ConvertToString(cmValue value) -{ - return std::string(*value); -} -} - -template -void cmTarget::StoreProperty(const std::string& prop, ValueType value) +void cmTarget::SetProperty(const std::string& prop, cmValue value) { if (prop == propMANUALLY_ADDED_DEPENDENCIES) { this->impl->Makefile->IssueMessage( @@ -1975,7 +1956,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) std::string reusedFrom = reusedTarget->GetSafeProperty(prop); if (reusedFrom.empty()) { - reusedFrom = ConvertToString(value); + reusedFrom = *value; } this->impl->Properties.SetProperty(prop, reusedFrom); @@ -2091,15 +2072,6 @@ void cmTarget::AppendProperty(const std::string& prop, } } -void cmTarget::SetProperty(const std::string& prop, const char* value) -{ - this->StoreProperty(prop, value); -} -void cmTarget::SetProperty(const std::string& prop, cmValue value) -{ - this->StoreProperty(prop, value); -} - template void cmTargetInternals::AddDirectoryToFileSet(cmTarget* self, std::string const& fileSetName, diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 24f6fcd..5fe5a28 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -180,8 +180,11 @@ public: std::set>> const& GetUtilities() const; //! Set/Get a property of this target file - void SetProperty(const std::string& prop, const char* value); void SetProperty(const std::string& prop, cmValue value); + void SetProperty(const std::string& prop, std::nullptr_t) + { + this->SetProperty(prop, cmValue{ nullptr }); + } void SetProperty(const std::string& prop, const std::string& value) { this->SetProperty(prop, cmValue(value)); diff --git a/Source/cmTest.cxx b/Source/cmTest.cxx index e6ed01b..b0d9c2d 100644 --- a/Source/cmTest.cxx +++ b/Source/cmTest.cxx @@ -52,10 +52,6 @@ bool cmTest::GetPropertyAsBool(const std::string& prop) const return cmIsOn(this->GetProperty(prop)); } -void cmTest::SetProperty(const std::string& prop, const char* value) -{ - this->Properties.SetProperty(prop, value); -} void cmTest::SetProperty(const std::string& prop, cmValue value) { this->Properties.SetProperty(prop, value); diff --git a/Source/cmTest.h b/Source/cmTest.h index 1c14310..8b50b87 100644 --- a/Source/cmTest.h +++ b/Source/cmTest.h @@ -4,6 +4,7 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include #include #include @@ -34,8 +35,11 @@ public: std::vector const& GetCommand() const { return this->Command; } //! Set/Get a property of this source file - void SetProperty(const std::string& prop, const char* value); void SetProperty(const std::string& prop, cmValue value); + void SetProperty(const std::string& prop, std::nullptr_t) + { + this->SetProperty(prop, cmValue{ nullptr }); + } void SetProperty(const std::string& prop, const std::string& value) { this->SetProperty(prop, cmValue(value)); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 284c5e7..c5b467d 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -3261,10 +3261,6 @@ void cmake::GenerateGraphViz(const std::string& fileName) const #endif } -void cmake::SetProperty(const std::string& prop, const char* value) -{ - this->State->SetGlobalProperty(prop, value); -} void cmake::SetProperty(const std::string& prop, cmValue value) { this->State->SetGlobalProperty(prop, value); diff --git a/Source/cmake.h b/Source/cmake.h index 0f8f642..955ec4f 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -404,8 +404,11 @@ public: std::vector GetGeneratorsDocumentation(); //! Set/Get a property of this target file - void SetProperty(const std::string& prop, const char* value); void SetProperty(const std::string& prop, cmValue value); + void SetProperty(const std::string& prop, std::nullptr_t) + { + this->SetProperty(prop, cmValue{ nullptr }); + } void SetProperty(const std::string& prop, const std::string& value) { this->SetProperty(prop, cmValue(value)); -- cgit v0.12