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:56:28 +10:00
parent 7fcc90c99c
commit 892fa0bb88
17 changed files with 42 additions and 43 deletions
+3 -3
View File
@@ -23,12 +23,12 @@
#include "cmake.h" #include "cmake.h"
cmConfigureLog::cmConfigureLog(std::string logDir, cmConfigureLog::cmConfigureLog(std::string logDir,
std::vector<unsigned long> logVersions) std::vector<unsigned int> logVersions)
: LogDir(std::move(logDir)) : LogDir(std::move(logDir))
, LogVersions(std::move(logVersions)) , LogVersions(std::move(logVersions))
{ {
// Always emit events for the latest log version. // 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)) { if (!cm::contains(this->LogVersions, LatestLogVersion)) {
this->LogVersions.emplace_back(LatestLogVersion); this->LogVersions.emplace_back(LatestLogVersion);
} }
@@ -46,7 +46,7 @@ cmConfigureLog::~cmConfigureLog()
} }
bool cmConfigureLog::IsAnyLogVersionEnabled( 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. // Both input lists are sorted. Look for a matching element.
auto i1 = v.cbegin(); auto i1 = v.cbegin();
+3 -3
View File
@@ -22,12 +22,12 @@ class cmConfigureLog
public: public:
/** Construct with the log directory and a sorted list of enabled log /** Construct with the log directory and a sorted list of enabled log
versions. The latest log version will be enabled regardless. */ 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(); ~cmConfigureLog();
/** Return true if at least one of the log versions in the given sorted /** Return true if at least one of the log versions in the given sorted
list is enabled. */ list is enabled. */
bool IsAnyLogVersionEnabled(std::vector<unsigned long> const& v) const; bool IsAnyLogVersionEnabled(std::vector<unsigned int> const& v) const;
void EnsureInit(); void EnsureInit();
@@ -60,7 +60,7 @@ public:
private: private:
std::string LogDir; std::string LogDir;
std::vector<unsigned long> LogVersions; std::vector<unsigned int> LogVersions;
cmsys::ofstream Stream; cmsys::ofstream Stream;
unsigned Indent = 0; unsigned Indent = 0;
bool Opened = false; bool Opened = false;
+3 -3
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) { auto getConfigureLogVersions = [&versions](Query const& q) {
for (Object const& o : q.Known) { for (Object const& o : q.Known) {
if (o.Kind == ObjectKind::ConfigureLog) { if (o.Kind == ObjectKind::ConfigureLog) {
@@ -126,7 +126,7 @@ std::vector<std::string> cmFileAPI::LoadDir(std::string const& dir)
std::vector<std::string> files; std::vector<std::string> files;
cmsys::Directory d; cmsys::Directory d;
d.Load(dir); 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); std::string f = d.GetFile(i);
if (f != "." && f != "..") { if (f != "." && f != "..") {
files.push_back(std::move(f)); files.push_back(std::move(f));
+2 -2
View File
@@ -25,7 +25,7 @@ public:
void ReadQueries(); void ReadQueries();
/** Get the list of configureLog object kind versions requested. */ /** 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. */ /** Identify the situation in which WriteReplies is called. */
enum class IndexFor enum class IndexFor
@@ -83,7 +83,7 @@ private:
struct Object struct Object
{ {
ObjectKind Kind; ObjectKind Kind;
unsigned long Version = 0; unsigned int Version = 0;
friend bool operator<(Object const& l, Object const& r) friend bool operator<(Object const& l, Object const& r)
{ {
if (l.Kind != r.Kind) { if (l.Kind != r.Kind) {
+4 -4
View File
@@ -22,7 +22,7 @@ namespace {
class CMakeFiles class CMakeFiles
{ {
cmFileAPI& FileAPI; cmFileAPI& FileAPI;
unsigned long Version; unsigned int Version;
std::string CMakeModules; std::string CMakeModules;
std::string const& TopSource; std::string const& TopSource;
std::string const& TopBuild; std::string const& TopBuild;
@@ -35,11 +35,11 @@ class CMakeFiles
Json::Value DumpGlobDependent(cmGlobCacheEntry const& entry); Json::Value DumpGlobDependent(cmGlobCacheEntry const& entry);
public: public:
CMakeFiles(cmFileAPI& fileAPI, unsigned long version); CMakeFiles(cmFileAPI& fileAPI, unsigned int version);
Json::Value Dump(); Json::Value Dump();
}; };
CMakeFiles::CMakeFiles(cmFileAPI& fileAPI, unsigned long version) CMakeFiles::CMakeFiles(cmFileAPI& fileAPI, unsigned int version)
: FileAPI(fileAPI) : FileAPI(fileAPI)
, Version(version) , Version(version)
, CMakeModules(cmSystemTools::GetCMakeRoot() + "/Modules") , 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); CMakeFiles cmakeFiles(fileAPI, version);
return cmakeFiles.Dump(); return cmakeFiles.Dump();
+1 -1
View File
@@ -9,4 +9,4 @@
class cmFileAPI; class cmFileAPI;
extern Json::Value cmFileAPICMakeFilesDump(cmFileAPI& fileAPI, extern Json::Value cmFileAPICMakeFilesDump(cmFileAPI& fileAPI,
unsigned long version); unsigned int version);
+4 -4
View File
@@ -19,7 +19,7 @@ namespace {
class Cache class Cache
{ {
cmFileAPI& FileAPI; cmFileAPI& FileAPI;
unsigned long Version; unsigned int Version;
cmState* State; cmState* State;
Json::Value DumpEntries(); Json::Value DumpEntries();
@@ -29,11 +29,11 @@ class Cache
std::string const& prop); std::string const& prop);
public: public:
Cache(cmFileAPI& fileAPI, unsigned long version); Cache(cmFileAPI& fileAPI, unsigned int version);
Json::Value Dump(); Json::Value Dump();
}; };
Cache::Cache(cmFileAPI& fileAPI, unsigned long version) Cache::Cache(cmFileAPI& fileAPI, unsigned int version)
: FileAPI(fileAPI) : FileAPI(fileAPI)
, Version(version) , Version(version)
, State(this->FileAPI.GetCMakeInstance()->GetState()) , 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); Cache cache(fileAPI, version);
return cache.Dump(); return cache.Dump();
+1 -1
View File
@@ -9,4 +9,4 @@
class cmFileAPI; class cmFileAPI;
extern Json::Value cmFileAPICacheDump(cmFileAPI& fileAPI, extern Json::Value cmFileAPICacheDump(cmFileAPI& fileAPI,
unsigned long version); unsigned int version);
+7 -7
View File
@@ -223,21 +223,21 @@ Json::Value BacktraceData::Dump()
class Codemodel class Codemodel
{ {
cmFileAPI& FileAPI; cmFileAPI& FileAPI;
unsigned long Version; unsigned int Version;
Json::Value DumpPaths(); Json::Value DumpPaths();
Json::Value DumpConfigurations(); Json::Value DumpConfigurations();
Json::Value DumpConfiguration(std::string const& config); Json::Value DumpConfiguration(std::string const& config);
public: public:
Codemodel(cmFileAPI& fileAPI, unsigned long version); Codemodel(cmFileAPI& fileAPI, unsigned int version);
Json::Value Dump(); Json::Value Dump();
}; };
class CodemodelConfig class CodemodelConfig
{ {
cmFileAPI& FileAPI; cmFileAPI& FileAPI;
unsigned long Version; unsigned int Version;
std::string const& Config; std::string const& Config;
std::string TopSource; std::string TopSource;
std::string TopBuild; std::string TopBuild;
@@ -290,7 +290,7 @@ class CodemodelConfig
Json::Value DumpMinimumCMakeVersion(cmStateSnapshot s); Json::Value DumpMinimumCMakeVersion(cmStateSnapshot s);
public: public:
CodemodelConfig(cmFileAPI& fileAPI, unsigned long version, CodemodelConfig(cmFileAPI& fileAPI, unsigned int version,
std::string const& config); std::string const& config);
Json::Value Dump(); Json::Value Dump();
}; };
@@ -515,7 +515,7 @@ public:
Json::Value Dump(); Json::Value Dump();
}; };
Codemodel::Codemodel(cmFileAPI& fileAPI, unsigned long version) Codemodel::Codemodel(cmFileAPI& fileAPI, unsigned int version)
: FileAPI(fileAPI) : FileAPI(fileAPI)
, Version(version) , Version(version)
{ {
@@ -561,7 +561,7 @@ Json::Value Codemodel::DumpConfiguration(std::string const& config)
return configuration.Dump(); return configuration.Dump();
} }
CodemodelConfig::CodemodelConfig(cmFileAPI& fileAPI, unsigned long version, CodemodelConfig::CodemodelConfig(cmFileAPI& fileAPI, unsigned int version,
std::string const& config) std::string const& config)
: FileAPI(fileAPI) : FileAPI(fileAPI)
, Version(version) , Version(version)
@@ -2154,7 +2154,7 @@ Json::Value Target::DumpDebugger()
return debuggerInformation; return debuggerInformation;
} }
Json::Value cmFileAPICodemodelDump(cmFileAPI& fileAPI, unsigned long version) Json::Value cmFileAPICodemodelDump(cmFileAPI& fileAPI, unsigned int version)
{ {
Codemodel codemodel(fileAPI, version); Codemodel codemodel(fileAPI, version);
return codemodel.Dump(); return codemodel.Dump();
+1 -1
View File
@@ -9,4 +9,4 @@
class cmFileAPI; class cmFileAPI;
extern Json::Value cmFileAPICodemodelDump(cmFileAPI& fileAPI, extern Json::Value cmFileAPICodemodelDump(cmFileAPI& fileAPI,
unsigned long version); unsigned int version);
+4 -5
View File
@@ -13,17 +13,17 @@ namespace {
class ConfigureLog class ConfigureLog
{ {
cmFileAPI& FileAPI; cmFileAPI& FileAPI;
unsigned long Version; unsigned int Version;
Json::Value DumpPath(); Json::Value DumpPath();
Json::Value DumpEventKindNames(); Json::Value DumpEventKindNames();
public: public:
ConfigureLog(cmFileAPI& fileAPI, unsigned long version); ConfigureLog(cmFileAPI& fileAPI, unsigned int version);
Json::Value Dump(); Json::Value Dump();
}; };
ConfigureLog::ConfigureLog(cmFileAPI& fileAPI, unsigned long version) ConfigureLog::ConfigureLog(cmFileAPI& fileAPI, unsigned int version)
: FileAPI(fileAPI) : FileAPI(fileAPI)
, Version(version) , Version(version)
{ {
@@ -62,8 +62,7 @@ Json::Value ConfigureLog::DumpEventKindNames()
} }
} }
Json::Value cmFileAPIConfigureLogDump(cmFileAPI& fileAPI, Json::Value cmFileAPIConfigureLogDump(cmFileAPI& fileAPI, unsigned int version)
unsigned long version)
{ {
ConfigureLog configureLog(fileAPI, version); ConfigureLog configureLog(fileAPI, version);
return configureLog.Dump(); return configureLog.Dump();
+1 -1
View File
@@ -9,4 +9,4 @@
class cmFileAPI; class cmFileAPI;
extern Json::Value cmFileAPIConfigureLogDump(cmFileAPI& fileAPI, extern Json::Value cmFileAPIConfigureLogDump(cmFileAPI& fileAPI,
unsigned long version); unsigned int version);
+4 -4
View File
@@ -29,7 +29,7 @@ struct ToolchainVariable
class Toolchains class Toolchains
{ {
cmFileAPI& FileAPI; cmFileAPI& FileAPI;
unsigned long Version; unsigned int Version;
Json::Value DumpToolchains(); Json::Value DumpToolchains();
Json::Value DumpToolchain(std::string const& lang); Json::Value DumpToolchain(std::string const& lang);
@@ -41,11 +41,11 @@ class Toolchains
ToolchainVariable const& variable); ToolchainVariable const& variable);
public: public:
Toolchains(cmFileAPI& fileAPI, unsigned long version); Toolchains(cmFileAPI& fileAPI, unsigned int version);
Json::Value Dump(); Json::Value Dump();
}; };
Toolchains::Toolchains(cmFileAPI& fileAPI, unsigned long version) Toolchains::Toolchains(cmFileAPI& fileAPI, unsigned int version)
: FileAPI(fileAPI) : FileAPI(fileAPI)
, Version(version) , 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); Toolchains toolchains(fileAPI, version);
return toolchains.Dump(); return toolchains.Dump();
+1 -1
View File
@@ -9,4 +9,4 @@
class cmFileAPI; class cmFileAPI;
extern Json::Value cmFileAPIToolchainsDump(cmFileAPI& fileAPI, extern Json::Value cmFileAPIToolchainsDump(cmFileAPI& fileAPI,
unsigned long version); unsigned int version);
+1 -1
View File
@@ -69,7 +69,7 @@ void WriteMessageEvent(cmConfigureLog& log, cmMakefile const& mf,
std::string const& message) std::string const& message)
{ {
// Keep in sync with cmFileAPIConfigureLog's DumpEventKindNames. // 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)) { if (log.IsAnyLogVersionEnabled(LogVersionsWithMessageV1)) {
log.BeginEvent("message-v1", mf); log.BeginEvent("message-v1", mf);
+1 -1
View File
@@ -22,7 +22,7 @@ void WriteTryCompileEvent(cmConfigureLog& log, cmMakefile const& mf,
cmTryCompileResult const& compileResult) cmTryCompileResult const& compileResult)
{ {
// Keep in sync with cmFileAPIConfigureLog's DumpEventKindNames. // 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)) { if (log.IsAnyLogVersionEnabled(LogVersionsWithTryCompileV1)) {
log.BeginEvent("try_compile-v1", mf); log.BeginEvent("try_compile-v1", mf);
+1 -1
View File
@@ -41,7 +41,7 @@ void WriteTryRunEvent(cmConfigureLog& log, cmMakefile const& mf,
cmTryRunResult const& runResult) cmTryRunResult const& runResult)
{ {
// Keep in sync with cmFileAPIConfigureLog's DumpEventKindNames. // 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)) { if (log.IsAnyLogVersionEnabled(LogVersionsWithTryRunV1)) {
log.BeginEvent("try_run-v1", mf); log.BeginEvent("try_run-v1", mf);