1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

fileapi: Use unsigned int consistently for version numbers

The file API code used unsigned long to hold the major version in most
places, but not all. Some places used unsigned int, and an important one
of those is the cmFileApi::BuildVersion() function. As a result, it has never
been safe for a large value not representable by an unsigned int to be
used in these variables.

Convert all of the file API version number variables and function arguments
to use unsigned int consistently. This avoids any size mismatch warnings
when passing values around. They also don't need to be unsigned long,
as we never expect version numbers to be anything even close to what
an unsigned int cannot represent.
This commit is contained in:
Craig Scott
2025-07-13 14:24:35 +10:00
parent 7fcc90c99c
commit 892fa0bb88
17 changed files with 42 additions and 43 deletions

View File

@@ -23,12 +23,12 @@
#include "cmake.h"
cmConfigureLog::cmConfigureLog(std::string logDir,
std::vector<unsigned long> logVersions)
std::vector<unsigned int> logVersions)
: LogDir(std::move(logDir))
, LogVersions(std::move(logVersions))
{
// Always emit events for the latest log version.
static unsigned long const LatestLogVersion = 1;
static unsigned int const LatestLogVersion = 1;
if (!cm::contains(this->LogVersions, LatestLogVersion)) {
this->LogVersions.emplace_back(LatestLogVersion);
}
@@ -46,7 +46,7 @@ cmConfigureLog::~cmConfigureLog()
}
bool cmConfigureLog::IsAnyLogVersionEnabled(
std::vector<unsigned long> const& v) const
std::vector<unsigned int> const& v) const
{
// Both input lists are sorted. Look for a matching element.
auto i1 = v.cbegin();

View File

@@ -22,12 +22,12 @@ class cmConfigureLog
public:
/** Construct with the log directory and a sorted list of enabled log
versions. The latest log version will be enabled regardless. */
cmConfigureLog(std::string logDir, std::vector<unsigned long> logVersions);
cmConfigureLog(std::string logDir, std::vector<unsigned int> logVersions);
~cmConfigureLog();
/** Return true if at least one of the log versions in the given sorted
list is enabled. */
bool IsAnyLogVersionEnabled(std::vector<unsigned long> const& v) const;
bool IsAnyLogVersionEnabled(std::vector<unsigned int> const& v) const;
void EnsureInit();
@@ -60,7 +60,7 @@ public:
private:
std::string LogDir;
std::vector<unsigned long> LogVersions;
std::vector<unsigned int> LogVersions;
cmsys::ofstream Stream;
unsigned Indent = 0;
bool Opened = false;

View File

@@ -85,9 +85,9 @@ void cmFileAPI::ReadQueries()
}
}
std::vector<unsigned long> cmFileAPI::GetConfigureLogVersions()
std::vector<unsigned int> cmFileAPI::GetConfigureLogVersions()
{
std::vector<unsigned long> versions;
std::vector<unsigned int> versions;
auto getConfigureLogVersions = [&versions](Query const& q) {
for (Object const& o : q.Known) {
if (o.Kind == ObjectKind::ConfigureLog) {
@@ -126,7 +126,7 @@ std::vector<std::string> cmFileAPI::LoadDir(std::string const& dir)
std::vector<std::string> files;
cmsys::Directory d;
d.Load(dir);
for (unsigned long i = 0; i < d.GetNumberOfFiles(); ++i) {
for (unsigned int i = 0; i < d.GetNumberOfFiles(); ++i) {
std::string f = d.GetFile(i);
if (f != "." && f != "..") {
files.push_back(std::move(f));

View File

@@ -25,7 +25,7 @@ public:
void ReadQueries();
/** Get the list of configureLog object kind versions requested. */
std::vector<unsigned long> GetConfigureLogVersions();
std::vector<unsigned int> GetConfigureLogVersions();
/** Identify the situation in which WriteReplies is called. */
enum class IndexFor
@@ -83,7 +83,7 @@ private:
struct Object
{
ObjectKind Kind;
unsigned long Version = 0;
unsigned int Version = 0;
friend bool operator<(Object const& l, Object const& r)
{
if (l.Kind != r.Kind) {

View File

@@ -22,7 +22,7 @@ namespace {
class CMakeFiles
{
cmFileAPI& FileAPI;
unsigned long Version;
unsigned int Version;
std::string CMakeModules;
std::string const& TopSource;
std::string const& TopBuild;
@@ -35,11 +35,11 @@ class CMakeFiles
Json::Value DumpGlobDependent(cmGlobCacheEntry const& entry);
public:
CMakeFiles(cmFileAPI& fileAPI, unsigned long version);
CMakeFiles(cmFileAPI& fileAPI, unsigned int version);
Json::Value Dump();
};
CMakeFiles::CMakeFiles(cmFileAPI& fileAPI, unsigned long version)
CMakeFiles::CMakeFiles(cmFileAPI& fileAPI, unsigned int version)
: FileAPI(fileAPI)
, Version(version)
, CMakeModules(cmSystemTools::GetCMakeRoot() + "/Modules")
@@ -150,7 +150,7 @@ Json::Value CMakeFiles::DumpGlobDependent(cmGlobCacheEntry const& entry)
}
}
Json::Value cmFileAPICMakeFilesDump(cmFileAPI& fileAPI, unsigned long version)
Json::Value cmFileAPICMakeFilesDump(cmFileAPI& fileAPI, unsigned int version)
{
CMakeFiles cmakeFiles(fileAPI, version);
return cmakeFiles.Dump();

View File

@@ -9,4 +9,4 @@
class cmFileAPI;
extern Json::Value cmFileAPICMakeFilesDump(cmFileAPI& fileAPI,
unsigned long version);
unsigned int version);

View File

@@ -19,7 +19,7 @@ namespace {
class Cache
{
cmFileAPI& FileAPI;
unsigned long Version;
unsigned int Version;
cmState* State;
Json::Value DumpEntries();
@@ -29,11 +29,11 @@ class Cache
std::string const& prop);
public:
Cache(cmFileAPI& fileAPI, unsigned long version);
Cache(cmFileAPI& fileAPI, unsigned int version);
Json::Value Dump();
};
Cache::Cache(cmFileAPI& fileAPI, unsigned long version)
Cache::Cache(cmFileAPI& fileAPI, unsigned int version)
: FileAPI(fileAPI)
, Version(version)
, State(this->FileAPI.GetCMakeInstance()->GetState())
@@ -101,7 +101,7 @@ Json::Value Cache::DumpEntryProperty(std::string const& name,
}
}
Json::Value cmFileAPICacheDump(cmFileAPI& fileAPI, unsigned long version)
Json::Value cmFileAPICacheDump(cmFileAPI& fileAPI, unsigned int version)
{
Cache cache(fileAPI, version);
return cache.Dump();

View File

@@ -9,4 +9,4 @@
class cmFileAPI;
extern Json::Value cmFileAPICacheDump(cmFileAPI& fileAPI,
unsigned long version);
unsigned int version);

View File

@@ -223,21 +223,21 @@ Json::Value BacktraceData::Dump()
class Codemodel
{
cmFileAPI& FileAPI;
unsigned long Version;
unsigned int Version;
Json::Value DumpPaths();
Json::Value DumpConfigurations();
Json::Value DumpConfiguration(std::string const& config);
public:
Codemodel(cmFileAPI& fileAPI, unsigned long version);
Codemodel(cmFileAPI& fileAPI, unsigned int version);
Json::Value Dump();
};
class CodemodelConfig
{
cmFileAPI& FileAPI;
unsigned long Version;
unsigned int Version;
std::string const& Config;
std::string TopSource;
std::string TopBuild;
@@ -290,7 +290,7 @@ class CodemodelConfig
Json::Value DumpMinimumCMakeVersion(cmStateSnapshot s);
public:
CodemodelConfig(cmFileAPI& fileAPI, unsigned long version,
CodemodelConfig(cmFileAPI& fileAPI, unsigned int version,
std::string const& config);
Json::Value Dump();
};
@@ -515,7 +515,7 @@ public:
Json::Value Dump();
};
Codemodel::Codemodel(cmFileAPI& fileAPI, unsigned long version)
Codemodel::Codemodel(cmFileAPI& fileAPI, unsigned int version)
: FileAPI(fileAPI)
, Version(version)
{
@@ -561,7 +561,7 @@ Json::Value Codemodel::DumpConfiguration(std::string const& config)
return configuration.Dump();
}
CodemodelConfig::CodemodelConfig(cmFileAPI& fileAPI, unsigned long version,
CodemodelConfig::CodemodelConfig(cmFileAPI& fileAPI, unsigned int version,
std::string const& config)
: FileAPI(fileAPI)
, Version(version)
@@ -2154,7 +2154,7 @@ Json::Value Target::DumpDebugger()
return debuggerInformation;
}
Json::Value cmFileAPICodemodelDump(cmFileAPI& fileAPI, unsigned long version)
Json::Value cmFileAPICodemodelDump(cmFileAPI& fileAPI, unsigned int version)
{
Codemodel codemodel(fileAPI, version);
return codemodel.Dump();

View File

@@ -9,4 +9,4 @@
class cmFileAPI;
extern Json::Value cmFileAPICodemodelDump(cmFileAPI& fileAPI,
unsigned long version);
unsigned int version);

View File

@@ -13,17 +13,17 @@ namespace {
class ConfigureLog
{
cmFileAPI& FileAPI;
unsigned long Version;
unsigned int Version;
Json::Value DumpPath();
Json::Value DumpEventKindNames();
public:
ConfigureLog(cmFileAPI& fileAPI, unsigned long version);
ConfigureLog(cmFileAPI& fileAPI, unsigned int version);
Json::Value Dump();
};
ConfigureLog::ConfigureLog(cmFileAPI& fileAPI, unsigned long version)
ConfigureLog::ConfigureLog(cmFileAPI& fileAPI, unsigned int version)
: FileAPI(fileAPI)
, Version(version)
{
@@ -62,8 +62,7 @@ Json::Value ConfigureLog::DumpEventKindNames()
}
}
Json::Value cmFileAPIConfigureLogDump(cmFileAPI& fileAPI,
unsigned long version)
Json::Value cmFileAPIConfigureLogDump(cmFileAPI& fileAPI, unsigned int version)
{
ConfigureLog configureLog(fileAPI, version);
return configureLog.Dump();

View File

@@ -9,4 +9,4 @@
class cmFileAPI;
extern Json::Value cmFileAPIConfigureLogDump(cmFileAPI& fileAPI,
unsigned long version);
unsigned int version);

View File

@@ -29,7 +29,7 @@ struct ToolchainVariable
class Toolchains
{
cmFileAPI& FileAPI;
unsigned long Version;
unsigned int Version;
Json::Value DumpToolchains();
Json::Value DumpToolchain(std::string const& lang);
@@ -41,11 +41,11 @@ class Toolchains
ToolchainVariable const& variable);
public:
Toolchains(cmFileAPI& fileAPI, unsigned long version);
Toolchains(cmFileAPI& fileAPI, unsigned int version);
Json::Value Dump();
};
Toolchains::Toolchains(cmFileAPI& fileAPI, unsigned long version)
Toolchains::Toolchains(cmFileAPI& fileAPI, unsigned int version)
: FileAPI(fileAPI)
, Version(version)
{
@@ -143,7 +143,7 @@ void Toolchains::DumpToolchainVariable(cmMakefile const* mf,
}
}
Json::Value cmFileAPIToolchainsDump(cmFileAPI& fileAPI, unsigned long version)
Json::Value cmFileAPIToolchainsDump(cmFileAPI& fileAPI, unsigned int version)
{
Toolchains toolchains(fileAPI, version);
return toolchains.Dump();

View File

@@ -9,4 +9,4 @@
class cmFileAPI;
extern Json::Value cmFileAPIToolchainsDump(cmFileAPI& fileAPI,
unsigned long version);
unsigned int version);

View File

@@ -69,7 +69,7 @@ void WriteMessageEvent(cmConfigureLog& log, cmMakefile const& mf,
std::string const& message)
{
// Keep in sync with cmFileAPIConfigureLog's DumpEventKindNames.
static std::vector<unsigned long> const LogVersionsWithMessageV1{ 1 };
static std::vector<unsigned int> const LogVersionsWithMessageV1{ 1 };
if (log.IsAnyLogVersionEnabled(LogVersionsWithMessageV1)) {
log.BeginEvent("message-v1", mf);

View File

@@ -22,7 +22,7 @@ void WriteTryCompileEvent(cmConfigureLog& log, cmMakefile const& mf,
cmTryCompileResult const& compileResult)
{
// Keep in sync with cmFileAPIConfigureLog's DumpEventKindNames.
static std::vector<unsigned long> const LogVersionsWithTryCompileV1{ 1 };
static std::vector<unsigned int> const LogVersionsWithTryCompileV1{ 1 };
if (log.IsAnyLogVersionEnabled(LogVersionsWithTryCompileV1)) {
log.BeginEvent("try_compile-v1", mf);

View File

@@ -41,7 +41,7 @@ void WriteTryRunEvent(cmConfigureLog& log, cmMakefile const& mf,
cmTryRunResult const& runResult)
{
// Keep in sync with cmFileAPIConfigureLog's DumpEventKindNames.
static std::vector<unsigned long> const LogVersionsWithTryRunV1{ 1 };
static std::vector<unsigned int> const LogVersionsWithTryRunV1{ 1 };
if (log.IsAnyLogVersionEnabled(LogVersionsWithTryRunV1)) {
log.BeginEvent("try_run-v1", mf);