From dd174576b06e97d956777735c0d0cf5a60a31090 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Sat, 8 Feb 2025 11:46:15 +0300 Subject: [PATCH 1/2] Support older macOS --- interop/src/cpp/DeserializerBase.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/interop/src/cpp/DeserializerBase.h b/interop/src/cpp/DeserializerBase.h index 219dcfbe2..2d7ace0b5 100644 --- a/interop/src/cpp/DeserializerBase.h +++ b/interop/src/cpp/DeserializerBase.h @@ -565,10 +565,16 @@ inline void WriteToString(std::string *result, InteropFloat32 value) { std::string storage; storage.resize(20); +#if (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED < 130300L)) + char buf[20]; + snprintf(buf, sizeof buf, "%f", value); + result->append(buf); +#else // We use to_chars() to avoid locale issues. auto rc = std::to_chars(storage.data(), storage.data() + storage.size(), value); storage.resize(rc.ptr - storage.data()); result->append(storage); +#endif } template <> inline void WriteToString(std::string* result, const InteropBuffer* value) { -- Gitee From 25f1dfc5a06cb3854406fb3c8e5c0bdd599023ba Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Sat, 8 Feb 2025 11:52:33 +0300 Subject: [PATCH 2/2] Better --- interop/src/cpp/DeserializerBase.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/interop/src/cpp/DeserializerBase.h b/interop/src/cpp/DeserializerBase.h index 2d7ace0b5..87fe3fc39 100644 --- a/interop/src/cpp/DeserializerBase.h +++ b/interop/src/cpp/DeserializerBase.h @@ -563,13 +563,14 @@ inline void WriteToString(std::string *result, InteropUInt32 value) template <> inline void WriteToString(std::string *result, InteropFloat32 value) { - std::string storage; - storage.resize(20); #if (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED < 130300L)) + // to_chars() is not available on older macOS. char buf[20]; snprintf(buf, sizeof buf, "%f", value); result->append(buf); #else + std::string storage; + storage.resize(20); // We use to_chars() to avoid locale issues. auto rc = std::to_chars(storage.data(), storage.data() + storage.size(), value); storage.resize(rc.ptr - storage.data()); -- Gitee