summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-08-10 21:15:38 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-08-15 17:18:58 +0000
commita0b845f78c031a62d02883889bc6c3effa2d2b9e (patch)
tree9ce01eb80d2f0af518ed7c8675b53ab7b54e00fb /src
parent6db171eec5cfaf0957e745fae2da4c100421e063 (diff)
QBluetoothUuid: provide Endian overloads for quint128 functions
This mimicks the new APIs of the same name in QUuid. For QBluetoothUuid, this is wonderful news, because the old overloads that lack the Endian parameter are now _always_ referring to the old struct quint128, and are, as usual, defined in removed_api.cpp¹ ¹ with the caveat that QT_NO_INT128 is defined there globally, which may create problems for potential QT_REMOVED_SINCE(6, 7)s. A solution would be to move this stuff out into a compat/old_int128_api.cpp, but let's first get the 6.6 part done. The new overloads are now either `unsigned __int128` (#ifdef QT_SUPPORTS_INT128) or `struct quint128` (otherwise), never both, so we don't need a second TU to do the overloading at the ABI level. This leaves removed_api.cpp with its traditional role of dealing with QT_REMOVED_SINCE (with the caveat mentioned above) and the QT_SUPPORTS_INT128 handling is in qbluetoothuuid.{h,cpp}, where it belongs. This greatly simplifies the #ifdef'ery in all three files and allows to do away with the "normal" vs. "not typical" QT_REMOVED_SINCE(6, 6) section split. Amends 5d90296f312f72ffa6a5322df7b565c3e5521684. As a drive-by, fix missing Q_QDOC handling. Change-Id: I4ead4ee39533967a78c145ef222d9991fdf4cd98 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit bfa5d5f6581439216ccbff97e1c9af76fc461dc7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothuuid.cpp51
-rw-r--r--src/bluetooth/qbluetoothuuid.h11
-rw-r--r--src/bluetooth/removed_api.cpp22
3 files changed, 53 insertions, 31 deletions
diff --git a/src/bluetooth/qbluetoothuuid.cpp b/src/bluetooth/qbluetoothuuid.cpp
index c67f704f..4959ba73 100644
--- a/src/bluetooth/qbluetoothuuid.cpp
+++ b/src/bluetooth/qbluetoothuuid.cpp
@@ -533,35 +533,50 @@ Q_CONSTRUCTOR_FUNCTION(registerQBluetoothUuid)
*/
/*!
- \fn quint128 QBluetoothUuid::toUInt128() const
+ \fn quint128 QBluetoothUuid::toUInt128(QSysInfo::Endian order) const
- Returns the 128 bit representation of this UUID.
+ Returns the 128 bit representation of this UUID in byte order \a order.
- \note The returned value is in big endian order.
-
- This method is only available when the platform \e {does not} support
- native 128 bit integral values. Otherwise, the call will resolve to
- \l QUuid::toUInt128(), which also allows to specify the desired endian
- order of the returned value.
+ \note In Qt versions prior to 6.6, the \a order argument was not present,
+ and the function was hard-coded to return in big-endian order.
*/
+#ifndef QT_SUPPORTS_INT128 // otherwise falls back to QUuid::toUint128()
+quint128 QBluetoothUuid::toUInt128(QSysInfo::Endian order) const noexcept
+{
+ quint128 r;
+ const auto bytes = toBytes(order);
+ static_assert(sizeof(quint128) == sizeof(decltype(bytes)));
+ memcpy(&r, bytes.data, sizeof(quint128));
+ return r;
+}
+#endif
+
+static QUuid::Id128Bytes to_id128_bytes(quint128 v) noexcept
+{
+#ifdef QT_SUPPORTS_INT128
+ // quint128 is `unsigned __int128`:
+ return {.data128 = {v}};
+#else
+ // quint128 is our legacy struct from qbluetoothuuid.h:
+ QUuid::Id128Bytes result;
+ memcpy(result.data, v.data, sizeof(v.data));
+ return result;
+#endif
+}
/*!
- \fn QBluetoothUuid::QBluetoothUuid(quint128 uuid)
+ \fn QBluetoothUuid::QBluetoothUuid(quint128 uuid, QSysInfo::Endian order)
Constructs a new Bluetooth UUID from a 128 bit \a uuid.
- \note The \a uuid must be in big endian order.
+ \note In Qt versions prior to 6.6, the \a order argument was not present,
+ and the function was hard-coded to big-endian order.
*/
-#ifdef QT_SUPPORTS_INT128
-// This implementation is used only when 128-bit ints are supported.
-// The old implementation which uses struct quint128 can be found in
-// removed_api.cpp. We need to keep it there, because we need to provide both
-// implementations for BC
-QBluetoothUuid::QBluetoothUuid(quint128 uuid)
- : QUuid(Id128Bytes{.data128 = {uuid}}, QSysInfo::BigEndian)
+
+QBluetoothUuid::QBluetoothUuid(quint128 uuid, QSysInfo::Endian order) noexcept
+ : QUuid{to_id128_bytes(uuid), order}
{
}
-#endif
/*!
Creates a QBluetoothUuid object from the string \a uuid,
diff --git a/src/bluetooth/qbluetoothuuid.h b/src/bluetooth/qbluetoothuuid.h
index f03dd63f..d91670d9 100644
--- a/src/bluetooth/qbluetoothuuid.h
+++ b/src/bluetooth/qbluetoothuuid.h
@@ -18,7 +18,7 @@ Q_FORWARD_DECLARE_OBJC_CLASS(CBUUID);
QT_BEGIN_NAMESPACE
-#if QT_BLUETOOTH_REMOVED_SINCE(6, 6) || !defined(QT_SUPPORTS_INT128)
+#if !defined(QT_SUPPORTS_INT128)
struct quint128
{
quint8 data[16];
@@ -350,8 +350,12 @@ public:
: QUuid(uuid, 0x0, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb) {};
explicit constexpr QBluetoothUuid(quint32 uuid) noexcept
: QUuid(uuid, 0x0, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb) {};
+ // end of bluetooth-specific constructors; rest is essentially `using QUuid::QUuid;`
+#if QT_BLUETOOTH_REMOVED_SINCE(6, 6)
explicit QBluetoothUuid(quint128 uuid);
+#endif
+ explicit QBluetoothUuid(quint128 uuid, QSysInfo::Endian order = QSysInfo::BigEndian) noexcept;
explicit QBluetoothUuid(Id128Bytes uuid, QSysInfo::Endian order = QSysInfo::BigEndian) noexcept
: QUuid(uuid, order) {};
explicit QBluetoothUuid(const QString &uuid);
@@ -378,9 +382,12 @@ public:
quint16 toUInt16(bool *ok = nullptr) const;
quint32 toUInt32(bool *ok = nullptr) const;
-#if QT_BLUETOOTH_REMOVED_SINCE(6, 6) || !defined(QT_SUPPORTS_INT128)
+#if QT_BLUETOOTH_REMOVED_SINCE(6, 6)
quint128 toUInt128() const;
#endif
+#if defined(Q_QDOC) || !defined(QT_SUPPORTS_INT128) // otherwise falls back to QUuid::toUint128()
+ quint128 toUInt128(QSysInfo::Endian order = QSysInfo::BigEndian) const noexcept;
+#endif
#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
static QBluetoothUuid fromCBUUID(CBUUID *cbUuid);
diff --git a/src/bluetooth/removed_api.cpp b/src/bluetooth/removed_api.cpp
index e2536be9..86af8b9c 100644
--- a/src/bluetooth/removed_api.cpp
+++ b/src/bluetooth/removed_api.cpp
@@ -10,16 +10,23 @@
QT_USE_NAMESPACE
-// This part is not typical to the removed_api.cpp, because we need to have
-// an extra condition. When adding new removed APIs for Qt 6.6, do not put them
-// into this section. Instead, add them to the section below.
-#if QT_BLUETOOTH_REMOVED_SINCE(6, 6) || !defined(QT_SUPPORTS_INT128)
+#if QT_BLUETOOTH_REMOVED_SINCE(6, 6)
+
+#include "qbluetoothaddress.h" // inlined API
#include "qbluetoothuuid.h"
static_assert(std::is_aggregate_v<quint128>);
static_assert(std::is_trivial_v<quint128>);
+// These legacy functions can't just call the new (quint128, Endian) overloads,
+// as the latter may see either QtCore's quint128 (__int128 built-in) _or_ our
+// fake version from qbluetoothuuid.h. This TU must _always_ see the fake ones
+// (as that is what we had in 6.5):
+#ifdef QT_SUPPORTS_INT128
+# error This TU requires QT_NO_INT128 to be defined.
+#endif
+
QBluetoothUuid::QBluetoothUuid(quint128 uuid)
: QUuid(fromBytes(uuid.data))
{}
@@ -32,11 +39,4 @@ quint128 QBluetoothUuid::toUInt128() const
return uuid;
}
-#endif // QT_BLUETOOTH_REMOVED_SINCE(6, 6) || !defined(QT_SUPPORTS_INT128)
-
-// This is a common section for Qt 6.6 removed APIs
-#if QT_BLUETOOTH_REMOVED_SINCE(6, 6)
-
-#include "qbluetoothaddress.h" // inlined API
-
#endif // QT_BLUETOOTH_REMOVED_SINCE(6, 6)