diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2023-07-24 18:47:15 +0200 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2023-08-01 10:30:51 +0200 |
commit | eb0abd9789062d95bc62dbbc29b2038dc40472b1 (patch) | |
tree | 4f520ab610b85796d38e1f01e97717020d5134e1 | |
parent | 8cedef62cf1b401d2c5ae08b03f92f95fd09df75 (diff) |
Use QT_SUPPORTS_INT128 macro to handle 128-bit integral types
Introduce QT_SUPPORTS_INT128 and QT_NO_INT128 marcos to handle 128-bit
types. These macros allow to undef Qt's own 128-bit types and the
related code, but keep the compiler definitions unchanged.
This is required for Qt Bluetooth, where we need to use
QT_BLUETOOTH_REMOVED_SINCE to get rid of the APIs using
QtBluetooth-specific struct quint128 which clashes with the 128-bit
types. The idea is to use QT_NO_INT128 in Qt Bluetooth's
removed_api.cpp instead of directly undef'ing __SIZEOF_INT128__,
because the latter is UB.
This commit amends befda1accab417ce5f55cb11816e6ded51af55e3.
Pick-to: 6.6
Change-Id: Ia2c110b5744c3aaa53eda39fb44984cf5a01fac2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/global/qendian.h | 2 | ||||
-rw-r--r-- | src/corelib/global/qtypes.h | 10 | ||||
-rw-r--r-- | src/corelib/plugin/quuid.h | 6 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/quuid/tst_quuid.cpp | 2 |
4 files changed, 13 insertions, 7 deletions
diff --git a/src/corelib/global/qendian.h b/src/corelib/global/qendian.h index 29d632ef04..60c4a7b174 100644 --- a/src/corelib/global/qendian.h +++ b/src/corelib/global/qendian.h @@ -105,7 +105,7 @@ inline constexpr T qbswap(T source) return T(qbswap_helper(typename QIntegerForSizeof<T>::Unsigned(source))); } -#ifdef __SIZEOF_INT128__ +#ifdef QT_SUPPORTS_INT128 // extra definitions for q(u)int128, in case std::is_integral_v<~~> == false inline constexpr quint128 qbswap(quint128 source) { diff --git a/src/corelib/global/qtypes.h b/src/corelib/global/qtypes.h index 954f22a191..6a4b6acf39 100644 --- a/src/corelib/global/qtypes.h +++ b/src/corelib/global/qtypes.h @@ -58,7 +58,13 @@ typedef unsigned long long quint64; /* 64 bit unsigned */ typedef qint64 qlonglong; typedef quint64 qulonglong; -#if defined(__SIZEOF_INT128__) +#if defined(__SIZEOF_INT128__) && !defined(QT_NO_INT128) +# define QT_SUPPORTS_INT128 __SIZEOF_INT128__ +#else +# undef QT_SUPPORTS_INT128 +#endif + +#if defined(QT_SUPPORTS_INT128) __extension__ typedef __int128_t qint128; __extension__ typedef __uint128_t quint128; #endif @@ -107,7 +113,7 @@ template <> struct QIntegerForSize<1> { typedef quint8 Unsigned; typedef qin template <> struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qint16 Signed; }; template <> struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; }; template <> struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; }; -#if defined(__SIZEOF_INT128__) +#if defined(QT_SUPPORTS_INT128) template <> struct QIntegerForSize<16> { typedef quint128 Unsigned; typedef qint128 Signed; }; #endif template <class T> struct QIntegerForSizeof: QIntegerForSize<sizeof(T)> { }; diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index ddd24eb678..2cefb4d764 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -60,7 +60,7 @@ public: quint16 data16[8]; quint32 data32[4]; quint64 data64[2]; -#ifdef __SIZEOF_INT128__ +#ifdef QT_SUPPORTS_INT128 quint128 data128[1]; #endif @@ -100,7 +100,7 @@ public: bool isNull() const noexcept; -#ifdef __SIZEOF_INT128__ +#ifdef QT_SUPPORTS_INT128 constexpr QUuid(quint128 uuid, QSysInfo::Endian order = QSysInfo::BigEndian) noexcept; constexpr quint128 toUInt128(QSysInfo::Endian order = QSysInfo::BigEndian) const noexcept; #endif @@ -242,7 +242,7 @@ inline QUuid QUuid::fromBytes(const void *bytes, QSysInfo::Endian order) noexcep return QUuid(result, order); } -#ifdef __SIZEOF_INT128__ +#ifdef QT_SUPPORTS_INT128 constexpr QUuid::QUuid(quint128 uuid, QSysInfo::Endian order) noexcept : QUuid() { diff --git a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp index b9fcf585fb..08f548a834 100644 --- a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp +++ b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp @@ -248,7 +248,7 @@ void tst_QUuid::id128() void tst_QUuid::uint128() { -#ifdef __SIZEOF_INT128__ +#ifdef QT_SUPPORTS_INT128 constexpr quint128 u = quint128(Q_UINT64_C(0xfc69b59ecc344436)) << 64 | Q_UINT64_C(0xa43cee95d128b8c5); // This is LE constexpr quint128 be = qToBigEndian(u); |