115 lines
4.5 KiB
Diff
115 lines
4.5 KiB
Diff
From 3e8037af63821123eb392f42d717d10f741fb384 Mon Sep 17 00:00:00 2001
|
|
From: Thiago Macieira <thiago.macieira@intel.com>
|
|
Date: Sat, 19 Oct 2024 21:28:48 -0700
|
|
Subject: [PATCH] QUuid: restore sorting order of Qt < 6.8
|
|
|
|
This brings back and adapted version of the sorting code that was
|
|
removed by commit 15f753ca5a60b5273d243f528978e25c28a9b56d. The issue,
|
|
as shown in the test, is that we store data1, data2, and data3 as
|
|
native-endian integers, so the bitcasts in the new code cause them to
|
|
become mangled in little-endian platforms.
|
|
|
|
Since this is a weird behavior and we'll be changing the sorting order
|
|
in Qt 7 anyway, I've left a warning for us to think about it at the
|
|
time.
|
|
|
|
[ChangeLog][QtCore][QUuid] Fixed a regression that caused QUuid sorting
|
|
order to change for some UUIDs, compared to Qt 6.7 and earlier versions.
|
|
|
|
Fixes: QTBUG-130155
|
|
Pick-to: 6.8
|
|
Change-Id: I5eeb7b36bfc5ed7218e1fffd6a773c582ad0f6f4
|
|
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
|
|
---
|
|
src/corelib/plugin/quuid.cpp | 3 +++
|
|
src/corelib/plugin/quuid.h | 12 +++++++++---
|
|
tests/auto/corelib/plugin/quuid/tst_quuid.cpp | 9 +++++++++
|
|
3 files changed, 21 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp
|
|
index af7c07d..5cbae60 100644
|
|
--- a/src/corelib/plugin/quuid.cpp
|
|
+++ b/src/corelib/plugin/quuid.cpp
|
|
@@ -33,6 +33,9 @@ void _q_toHex(char *&dst, Integral value)
|
|
}
|
|
}
|
|
|
|
+#if QT_VERSION_MAJOR == 7
|
|
+# warning Consider storing the UUID as simple bytes, not as {uint, ushort, short, array}
|
|
+#endif
|
|
template <class Integral>
|
|
bool _q_fromHex(const char *&src, Integral &value)
|
|
{
|
|
diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h
|
|
index 435b7bb..0597445 100644
|
|
--- a/src/corelib/plugin/quuid.h
|
|
+++ b/src/corelib/plugin/quuid.h
|
|
@@ -132,7 +132,14 @@ private:
|
|
static constexpr Qt::strong_ordering
|
|
compareThreeWay_helper(const QUuid &lhs, const QUuid &rhs) noexcept
|
|
{
|
|
-#if defined(__cpp_lib_bit_cast) && defined(QT_SUPPORTS_INT128)
|
|
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED)
|
|
+ if (const auto c = Qt::compareThreeWay(lhs.data1, rhs.data1); !is_eq(c))
|
|
+ return c;
|
|
+ if (const auto c = Qt::compareThreeWay(lhs.data2, rhs.data2); !is_eq(c))
|
|
+ return c;
|
|
+ if (const auto c = Qt::compareThreeWay(lhs.data3, rhs.data3); !is_eq(c))
|
|
+ return c;
|
|
+#elif defined(__cpp_lib_bit_cast) && defined(QT_SUPPORTS_INT128)
|
|
quint128 lu = qFromBigEndian(std::bit_cast<quint128>(lhs));
|
|
quint128 ru = qFromBigEndian(std::bit_cast<quint128>(rhs));
|
|
return Qt::compareThreeWay(lu, ru);
|
|
@@ -144,13 +151,12 @@ private:
|
|
};
|
|
if (const auto c = Qt::compareThreeWay(make_int(lhs), make_int(rhs)); !is_eq(c))
|
|
return c;
|
|
-
|
|
+#endif
|
|
for (unsigned i = 0; i < sizeof(lhs.data4); ++i) {
|
|
if (const auto c = Qt::compareThreeWay(lhs.data4[i], rhs.data4[i]); !is_eq(c))
|
|
return c;
|
|
}
|
|
return Qt::strong_ordering::equal;
|
|
-#endif
|
|
}
|
|
friend constexpr Qt::strong_ordering compareThreeWay(const QUuid &lhs, const QUuid &rhs) noexcept
|
|
{
|
|
diff --git a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp
|
|
index 8b75817..f1b96e6 100644
|
|
--- a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp
|
|
+++ b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp
|
|
@@ -465,6 +465,7 @@ void tst_QUuid::ordering_data()
|
|
#define AFTER_NCS(x) ROW(minNCS, x, less)
|
|
AFTER_NCS(ncs000_0000_0010);
|
|
AFTER_NCS(ncs000_0000_0100);
|
|
+ ROW(ncs000_0000_0010, ncs000_0000_0100, less);
|
|
AFTER_NCS(ncs000_0000_1000);
|
|
AFTER_NCS(ncs000_0001_0000);
|
|
AFTER_NCS(ncs000_0010_0000);
|
|
@@ -492,6 +493,13 @@ void tst_QUuid::ordering_data()
|
|
AFTER_R(ones);
|
|
#undef AFTER_R
|
|
#undef ROW
|
|
+
|
|
+ // due to the way we store data1,2,3 in memory, the ordering will flip
|
|
+ QTest::newRow("qt7-integer-portions")
|
|
+ << QUuid{0x01000002, 0x0000, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0}
|
|
+ << QUuid{0x02000001, 0x0000, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0}
|
|
+ << (QSysInfo::ByteOrder == QSysInfo::BigEndian || QT_VERSION_MAJOR < 7 ?
|
|
+ Qt::strong_ordering::less : Qt::strong_ordering::greater);
|
|
}
|
|
|
|
void tst_QUuid::ordering()
|
|
@@ -500,6 +508,7 @@ void tst_QUuid::ordering()
|
|
QFETCH(const QUuid, rhs);
|
|
QFETCH(const Qt::strong_ordering, expected);
|
|
|
|
+ QCOMPARE(qCompareThreeWay(lhs, rhs), expected);
|
|
QT_TEST_ALL_COMPARISON_OPS(lhs, rhs, expected);
|
|
}
|
|
|
|
--
|
|
2.47.0
|
|
|