From 6b113c827063972d43bf55d25b6baa66374992ac Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Wed, 26 Feb 2025 09:55:08 -0800 Subject: [PATCH] Add auto-detection of platform integer size in prometheus --- .../core/include/prometheus/counter.h | 13 ++++++++++++- .../core/include/prometheus/gauge.h | 10 ++++++++++ .../simpleapi/include/prometheus/simpleapi.h | 15 +++++++++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ext/prometheus-cpp-lite-1.0/core/include/prometheus/counter.h b/ext/prometheus-cpp-lite-1.0/core/include/prometheus/counter.h index 5d8053739..bd309c43a 100644 --- a/ext/prometheus-cpp-lite-1.0/core/include/prometheus/counter.h +++ b/ext/prometheus-cpp-lite-1.0/core/include/prometheus/counter.h @@ -25,7 +25,18 @@ namespace prometheus { /// /// The class is thread-safe. No concurrent call to any API of this type causes /// a data race. - template + +#include + +#if UINTPTR_MAX == 0xffFFffFF +// 32-bit platform +template +#elif UINTPTR_MAX == 0xffFFffFFffFFffFF +// 64-bit platform +template +#else +#error Unknown platform - does not look either like 32-bit or 64-bit +#endif class Counter : public Metric { std::atomic value{ 0 }; diff --git a/ext/prometheus-cpp-lite-1.0/core/include/prometheus/gauge.h b/ext/prometheus-cpp-lite-1.0/core/include/prometheus/gauge.h index fcda14631..2e4a4db8b 100644 --- a/ext/prometheus-cpp-lite-1.0/core/include/prometheus/gauge.h +++ b/ext/prometheus-cpp-lite-1.0/core/include/prometheus/gauge.h @@ -23,7 +23,17 @@ namespace prometheus { /// /// The class is thread-safe. No concurrent call to any API of this type causes /// a data race. + #include + + #if UINTPTR_MAX == 0xffFFffFF + // 32-bit + template + #elif UINTPTR_MAX == 0xffFFffFFffFFffFF + // 64-bit template + #else + #error Unknown platform - does not look either like 32-bit or 64-bit + #endif class Gauge : public Metric { std::atomic value { 0 }; diff --git a/ext/prometheus-cpp-lite-1.0/simpleapi/include/prometheus/simpleapi.h b/ext/prometheus-cpp-lite-1.0/simpleapi/include/prometheus/simpleapi.h index bf2ec4832..12e115844 100644 --- a/ext/prometheus-cpp-lite-1.0/simpleapi/include/prometheus/simpleapi.h +++ b/ext/prometheus-cpp-lite-1.0/simpleapi/include/prometheus/simpleapi.h @@ -15,6 +15,17 @@ #include #include #include +#include + +#if UINTPTR_MAX == 0xffFFffFF +// 32-bit +typedef uint32_tmetric_size; +#elif UINTPTR_MAX == 0xffFFffFFffFFffFF +// 64-bit +typedef uint64_t metric_size; +#else +#error Unknown platform - does not look either like 32-bit or 64-bit +#endif namespace prometheus { namespace simpleapi { @@ -46,7 +57,7 @@ namespace prometheus { public: - using Metric = Counter; + using Metric = Counter; using Family = Metric::Family; private: @@ -82,7 +93,7 @@ namespace prometheus { public: - using Metric = Gauge; + using Metric = Gauge; using Family = Metric::Family; private: