From f3e03ce77745aef6c2a7370835eed8865b5943ff Mon Sep 17 00:00:00 2001 From: Vitaly Zaitsev Date: Wed, 5 Jan 2022 08:42:51 +0100 Subject: [PATCH] Updated Big Endian patch. Added ABI fix patch. --- fmt-big-endian-fixes.patch | 76 +++++++++++++++++++++++++++----------- fmt-on_error-abi-fix.patch | 27 ++++++++++++++ fmt.spec | 11 +++++- 3 files changed, 90 insertions(+), 24 deletions(-) create mode 100644 fmt-on_error-abi-fix.patch diff --git a/fmt-big-endian-fixes.patch b/fmt-big-endian-fixes.patch index 94142d5..3c94b9a 100644 --- a/fmt-big-endian-fixes.patch +++ b/fmt-big-endian-fixes.patch @@ -1,36 +1,68 @@ -From 0273005bf5e92f1bbf230b654939489b01eb2eb3 Mon Sep 17 00:00:00 2001 +From 214cf13f17c7177912cc8f9b6c070c4b3a282c36 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov -Date: Tue, 4 Jan 2022 15:04:30 +0500 -Subject: [PATCH] Fix endianness bug in write_digit2_separated +Date: Wed, 5 Jan 2022 03:23:42 +0500 +Subject: [PATCH] Fix endianness bug in write_digit2_separated (#2699) +* Fix endianness bug in write_digit2_separated + +* Move endianness check to compile time if it possible + +* Turn 8 into a constant --- - include/fmt/chrono.h | 16 ++++++++++++++++ - 1 file changed, 16 insertions(+) + include/fmt/chrono.h | 10 +++++++++- + include/fmt/format.h | 10 +++++++++- + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h -index 908999ab5f..c52be81ca6 100644 +index 908999ab5f..682efd8d21 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h -@@ -558,6 +558,22 @@ inline void write_digit2_separated(char* buf, unsigned a, unsigned b, +@@ -558,7 +558,15 @@ inline void write_digit2_separated(char* buf, unsigned a, unsigned b, auto usep = static_cast(sep); // Add ASCII '0' to each digit byte and insert separators. digits |= 0x3030003030003030 | (usep << 16) | (usep << 40); -+#ifndef _WIN32 -+# if defined(__GNUC__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -+ digits = __builtin_bswap64(digits); -+# else -+ if (is_big_endian()) { -+ digits = ((digits & 0xff00000000000000ull) >> 56) | -+ ((digits & 0x00ff000000000000ull) >> 40) | -+ ((digits & 0x0000ff0000000000ull) >> 24) | -+ ((digits & 0x000000ff00000000ull) >> 8) | -+ ((digits & 0x00000000ff000000ull) << 8) | -+ ((digits & 0x0000000000ff0000ull) << 24) | -+ ((digits & 0x000000000000ff00ull) << 40) | -+ ((digits & 0x00000000000000ffull) << 56); +- memcpy(buf, &digits, 8); ++ ++ constexpr const size_t len = 8; ++ if (const_check(is_big_endian())) { ++ char tmp[len]; ++ memcpy(tmp, &digits, len); ++ std::reverse_copy(tmp, tmp + len, buf); ++ } else { ++ memcpy(buf, &digits, len); + } -+# endif + } + + template FMT_CONSTEXPR inline const char* get_units() { +diff --git a/include/fmt/format.h b/include/fmt/format.h +index a6f1fdc89e..8b789574ec 100644 +--- a/include/fmt/format.h ++++ b/include/fmt/format.h +@@ -296,10 +296,18 @@ FMT_CONSTEXPR20 auto bit_cast(const From& from) -> To { + } + + inline auto is_big_endian() -> bool { ++#ifdef _WIN32 ++ return false; ++#elif defined(__BIG_ENDIAN__) ++ return true; ++#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) ++ return __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__; ++#else + struct bytes { + char data[sizeof(int)]; + }; + return bit_cast(1).data[0] == 0; +#endif - memcpy(buf, &digits, 8); } + // A fallback implementation of uintptr_t for systems that lack it. +@@ -309,7 +317,7 @@ struct fallback_uintptr { + fallback_uintptr() = default; + explicit fallback_uintptr(const void* p) { + *this = bit_cast(p); +- if (is_big_endian()) { ++ if (const_check(is_big_endian())) { + for (size_t i = 0, j = sizeof(void*) - 1; i < j; ++i, --j) + std::swap(value[i], value[j]); + } diff --git a/fmt-on_error-abi-fix.patch b/fmt-on_error-abi-fix.patch new file mode 100644 index 0000000..f8332f9 --- /dev/null +++ b/fmt-on_error-abi-fix.patch @@ -0,0 +1,27 @@ +From 17a5c808dad4bcf3a412c005314cad43609ae6ef Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Julian=20R=C3=BCth?= +Date: Tue, 4 Jan 2022 12:53:44 -0600 +Subject: [PATCH] Restore FMT_API on error_handler::on_error() (#2696) + +this fixes a breaking ABI change that was introduce in the upgrade from +8.0.1 to 8.1.0. + +Fixes #2695. +--- + include/fmt/core.h | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/include/fmt/core.h b/include/fmt/core.h +index 4efa21f11f..28b8ff648f 100644 +--- a/include/fmt/core.h ++++ b/include/fmt/core.h +@@ -615,7 +615,8 @@ struct error_handler { + constexpr error_handler(const error_handler&) = default; + + // This function is intentionally not constexpr to give a compile-time error. +- void on_error(const char* message) { throw_format_error(message); } ++ // This function is marked as FMT_API for backwards compatibility, see #2695. ++ FMT_NORETURN FMT_API void on_error(const char* message) { throw_format_error(message); } + }; + FMT_END_DETAIL_NAMESPACE + diff --git a/fmt.spec b/fmt.spec index ba30416..0d8ae48 100644 --- a/fmt.spec +++ b/fmt.spec @@ -2,16 +2,19 @@ Name: fmt Version: 8.1.0 -Release: 1%{?dist} +Release: 2%{?dist} License: BSD Summary: Small, safe and fast formatting library for C++ URL: https://github.com/fmtlib/%{name} Source0: %{url}/archive/%{version}.tar.gz -# https://github.com/fmtlib/fmt/pull/2699 +# https://github.com/fmtlib/fmt/commit/214cf13f17c7177912cc8f9b6c070c4b3a282c36 Patch100: %{name}-big-endian-fixes.patch +# https://github.com/fmtlib/fmt/commit/17a5c808dad4bcf3a412c005314cad43609ae6ef +Patch101: %{name}-on_error-abi-fix.patch + BuildRequires: gcc BuildRequires: gcc-c++ BuildRequires: ninja-build @@ -74,6 +77,10 @@ This package contains the header file for using %{name}. %{_libdir}/pkgconfig/%{name}.pc %changelog +* Wed Jan 05 2022 Vitaly Zaitsev - 8.1.0-2 +- Updated Big Endian patch. +- Added ABI fix patch. + * Tue Jan 04 2022 Vitaly Zaitsev - 8.1.0-1 - Updated to version 8.1.0.