From ee9c09548cf4fa8c7edf0eb53494367fc17c859a Mon Sep 17 00:00:00 2001 From: KWSys Upstream Date: Sun, 6 Nov 2022 08:31:46 -0500 Subject: KWSys 2022-11-06 (9aebb97f) Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit 9aebb97f836b104b94d876df843889d9a1956612 (master). Upstream Shortlog ----------------- Ben Boeckel (1): 4226d5e5 Status: detect and diagnose X11 symbol conflicts Brad King (1): b72169e5 Process: Suppress clang -Wshorten-64-to-32 diagnostic on macOS Clemens Wasser (1): 550b5734 SystemTools: Use unordered_map for path caches Michael Hirsch (1): f0223ad1 SystemInformation: correct function name spelling --- ProcessUNIX.c | 13 +++++++++++++ Status.hxx.in | 10 ++++++++++ SystemInformation.cxx | 6 +++--- SystemTools.cxx | 40 ++++++++++++++++++++++++++++++++++------ 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/ProcessUNIX.c b/ProcessUNIX.c index 45a9e6f..b25b258 100644 --- a/ProcessUNIX.c +++ b/ProcessUNIX.c @@ -2011,6 +2011,14 @@ static int kwsysProcessGetTimeoutTime(kwsysProcess* cp, return 0; } +#if defined(__clang__) && defined(__has_warning) +# if __has_warning("-Wshorten-64-to-32") +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wshorten-64-to-32" +# define KWSYSPE_CLANG_DIAG_WSHORTEN +# endif +#endif + /* Get the length of time before the given timeout time arrives. Returns 1 if the time has already arrived, and 0 otherwise. */ static int kwsysProcessGetTimeoutLeft(kwsysProcessTime* timeoutTime, @@ -2061,6 +2069,11 @@ static kwsysProcessTime kwsysProcessTimeGetCurrent(void) return current; } +#if defined(KWSYSPE_CLANG_DIAG_WSHORTEN) +# undef KWSYSPE_CLANG_DIAG_WSHORTEN +# pragma clang diagnostic pop +#endif + static double kwsysProcessTimeToDouble(kwsysProcessTime t) { return (double)t.tv_sec + (double)(t.tv_usec) * 0.000001; diff --git a/Status.hxx.in b/Status.hxx.in index 16efaef..7cef029 100644 --- a/Status.hxx.in +++ b/Status.hxx.in @@ -7,6 +7,16 @@ #include +/* + * Detect a symbol collision with the name of this class. X11 headers use + * `#define Status int` instead of using `typedef` which poisons any other + * usage of this name. + */ +#if defined(Status) && defined(_X11_XLIB_H_) +# error \ + "Status.hxx must be included *before* any X11 headers to avoid a collision with the `Status` define that is made in its API." +#endif + namespace @KWSYS_NAMESPACE@ { /** \class Status diff --git a/SystemInformation.cxx b/SystemInformation.cxx index e6cc48f..20e2edb 100644 --- a/SystemInformation.cxx +++ b/SystemInformation.cxx @@ -482,7 +482,7 @@ protected: unsigned int); // For windows // For Linux and Cygwin, /proc/cpuinfo formats are slightly different - bool RetreiveInformationFromCpuInfoFile(); + bool RetrieveInformationFromCpuInfoFile(); std::string ExtractValueFromCpuInfoFile(std::string buffer, const char* word, size_t init = 0); @@ -1520,7 +1520,7 @@ void SystemInformationImplementation::RunCPUCheck() #elif defined(__hpux) this->QueryHPUXProcessor(); #elif defined(__linux) || defined(__CYGWIN__) - this->RetreiveInformationFromCpuInfoFile(); + this->RetrieveInformationFromCpuInfoFile(); #else this->QueryProcessor(); #endif @@ -3435,7 +3435,7 @@ std::string SystemInformationImplementation::ExtractValueFromCpuInfoFile( } /** Query for the cpu status */ -bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile() +bool SystemInformationImplementation::RetrieveInformationFromCpuInfoFile() { this->NumberOfLogicalCPU = 0; this->NumberOfPhysicalCPU = 0; diff --git a/SystemTools.cxx b/SystemTools.cxx index a20901c..fdd6b2d 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -36,6 +36,7 @@ #ifdef _WIN32 # include +# include #endif // Work-around CMake dependency scanning limitation. This must @@ -506,16 +507,39 @@ public: }; #ifdef _WIN32 -struct SystemToolsPathCaseCmp +# if defined(_WIN64) +static constexpr size_t FNV_OFFSET_BASIS = 14695981039346656037ULL; +static constexpr size_t FNV_PRIME = 1099511628211ULL; +# else +static constexpr size_t FNV_OFFSET_BASIS = 2166136261U; +static constexpr size_t FNV_PRIME = 16777619U; +# endif + +// Case insensitive Fnv1a hash +struct SystemToolsPathCaseHash +{ + size_t operator()(std::string const& path) const + { + size_t hash = FNV_OFFSET_BASIS; + for (auto c : path) { + hash ^= static_cast(std::tolower(c)); + hash *= FNV_PRIME; + } + + return hash; + } +}; + +struct SystemToolsPathCaseEqual { bool operator()(std::string const& l, std::string const& r) const { # ifdef _MSC_VER - return _stricmp(l.c_str(), r.c_str()) < 0; + return _stricmp(l.c_str(), r.c_str()) == 0; # elif defined(__GNUC__) - return strcasecmp(l.c_str(), r.c_str()) < 0; + return strcasecmp(l.c_str(), r.c_str()) == 0; # else - return SystemTools::Strucmp(l.c_str(), r.c_str()) < 0; + return SystemTools::Strucmp(l.c_str(), r.c_str()) == 0; # endif } }; @@ -540,8 +564,12 @@ public: bool const cache); static std::string GetActualCaseForPathCached(std::string const& path); static const char* GetEnvBuffered(const char* key); - std::map FindFileMap; - std::map PathCaseMap; + std::unordered_map + FindFileMap; + std::unordered_map + PathCaseMap; std::map EnvMap; #endif #ifdef __CYGWIN__ -- cgit v0.12