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 Change-Id: I5eeb7b36bfc5ed7218e1fffd6a773c582ad0f6f4 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit 222891d0b6b84bbf995bd75420bdfb55292c0901) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
ec16b18d82
commit
76da2f74d4
@ -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>
|
template <class Integral>
|
||||||
bool _q_fromHex(const char *&src, Integral &value)
|
bool _q_fromHex(const char *&src, Integral &value)
|
||||||
{
|
{
|
||||||
|
@ -132,7 +132,14 @@ private:
|
|||||||
static constexpr Qt::strong_ordering
|
static constexpr Qt::strong_ordering
|
||||||
compareThreeWay_helper(const QUuid &lhs, const QUuid &rhs) noexcept
|
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 lu = qFromBigEndian(std::bit_cast<quint128>(lhs));
|
||||||
quint128 ru = qFromBigEndian(std::bit_cast<quint128>(rhs));
|
quint128 ru = qFromBigEndian(std::bit_cast<quint128>(rhs));
|
||||||
return Qt::compareThreeWay(lu, ru);
|
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))
|
if (const auto c = Qt::compareThreeWay(make_int(lhs), make_int(rhs)); !is_eq(c))
|
||||||
return c;
|
return c;
|
||||||
|
#endif
|
||||||
for (unsigned i = 0; i < sizeof(lhs.data4); ++i) {
|
for (unsigned i = 0; i < sizeof(lhs.data4); ++i) {
|
||||||
if (const auto c = Qt::compareThreeWay(lhs.data4[i], rhs.data4[i]); !is_eq(c))
|
if (const auto c = Qt::compareThreeWay(lhs.data4[i], rhs.data4[i]); !is_eq(c))
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
return Qt::strong_ordering::equal;
|
return Qt::strong_ordering::equal;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
friend constexpr Qt::strong_ordering compareThreeWay(const QUuid &lhs, const QUuid &rhs) noexcept
|
friend constexpr Qt::strong_ordering compareThreeWay(const QUuid &lhs, const QUuid &rhs) noexcept
|
||||||
{
|
{
|
||||||
|
@ -465,6 +465,7 @@ void tst_QUuid::ordering_data()
|
|||||||
#define AFTER_NCS(x) ROW(minNCS, x, less)
|
#define AFTER_NCS(x) ROW(minNCS, x, less)
|
||||||
AFTER_NCS(ncs000_0000_0010);
|
AFTER_NCS(ncs000_0000_0010);
|
||||||
AFTER_NCS(ncs000_0000_0100);
|
AFTER_NCS(ncs000_0000_0100);
|
||||||
|
ROW(ncs000_0000_0010, ncs000_0000_0100, less);
|
||||||
AFTER_NCS(ncs000_0000_1000);
|
AFTER_NCS(ncs000_0000_1000);
|
||||||
AFTER_NCS(ncs000_0001_0000);
|
AFTER_NCS(ncs000_0001_0000);
|
||||||
AFTER_NCS(ncs000_0010_0000);
|
AFTER_NCS(ncs000_0010_0000);
|
||||||
@ -492,6 +493,13 @@ void tst_QUuid::ordering_data()
|
|||||||
AFTER_R(ones);
|
AFTER_R(ones);
|
||||||
#undef AFTER_R
|
#undef AFTER_R
|
||||||
#undef ROW
|
#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()
|
void tst_QUuid::ordering()
|
||||||
@ -500,6 +508,7 @@ void tst_QUuid::ordering()
|
|||||||
QFETCH(const QUuid, rhs);
|
QFETCH(const QUuid, rhs);
|
||||||
QFETCH(const Qt::strong_ordering, expected);
|
QFETCH(const Qt::strong_ordering, expected);
|
||||||
|
|
||||||
|
QCOMPARE(qCompareThreeWay(lhs, rhs), expected);
|
||||||
QT_TEST_ALL_COMPARISON_OPS(lhs, rhs, expected);
|
QT_TEST_ALL_COMPARISON_OPS(lhs, rhs, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user