diff options
Diffstat (limited to 'src/corelib/plugin')
-rw-r--r-- | src/corelib/plugin/qelfparser_p.cpp | 2 | ||||
-rw-r--r-- | src/corelib/plugin/qfactoryloader.cpp | 2 | ||||
-rw-r--r-- | src/corelib/plugin/qlibrary.cpp | 2 | ||||
-rw-r--r-- | src/corelib/plugin/quuid.cpp | 88 | ||||
-rw-r--r-- | src/corelib/plugin/quuid.h | 90 |
5 files changed, 111 insertions, 73 deletions
diff --git a/src/corelib/plugin/qelfparser_p.cpp b/src/corelib/plugin/qelfparser_p.cpp index 7f6271cde4..78c9be0e56 100644 --- a/src/corelib/plugin/qelfparser_p.cpp +++ b/src/corelib/plugin/qelfparser_p.cpp @@ -35,7 +35,7 @@ static constexpr bool IncludeValidityChecks = true; # define QELFPARSER_DEBUG #endif #if defined(QELFPARSER_DEBUG) -static Q_LOGGING_CATEGORY(lcElfParser, "qt.core.plugin.elfparser") +Q_STATIC_LOGGING_CATEGORY(lcElfParser, "qt.core.plugin.elfparser") # define qEDebug qCDebug(lcElfParser) << reinterpret_cast<const char16_t *>(error.errMsg->constData()) << ':' #else # define qEDebug if (false) {} else QNoDebug() diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp index e2d9a40cb4..6486414d8c 100644 --- a/src/corelib/plugin/qfactoryloader.cpp +++ b/src/corelib/plugin/qfactoryloader.cpp @@ -272,7 +272,7 @@ public: #if QT_CONFIG(library) -static Q_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(lcFactoryLoader, "QT_DEBUG_PLUGINS", +Q_STATIC_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(lcFactoryLoader, "QT_DEBUG_PLUGINS", "qt.core.plugin.factoryloader") namespace { diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index a3ef8e3c52..8f1db7e4d4 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -55,7 +55,7 @@ static constexpr bool QtBuildIsDebug = true; #endif Q_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(qt_lcDebugPlugins, "QT_DEBUG_PLUGINS", "qt.core.plugin.loader") -static Q_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(lcDebugLibrary, "QT_DEBUG_PLUGINS", "qt.core.library") +Q_STATIC_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(lcDebugLibrary, "QT_DEBUG_PLUGINS", "qt.core.library") /*! \class QLibrary diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index 9c7216c3c5..b3fad47ee6 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -116,12 +116,12 @@ static QUuid _q_uuidFromHex(const char *src) return QUuid(); } -static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCryptographicHash::Algorithm algorithm, int version) +static QUuid createFromName(QUuid ns, QByteArrayView baseData, QCryptographicHash::Algorithm algorithm, int version) noexcept { - QCryptographicHash hash(algorithm); - hash.addData(ns.toRfc4122()); - hash.addData(baseData); - QByteArrayView hashResult = hash.resultView(); + std::byte buffer[20]; + Q_ASSERT(sizeof buffer >= size_t(QCryptographicHash::hashLength(algorithm))); + QByteArrayView hashResult + = QCryptographicHash::hashInto(buffer, {QByteArrayView{ns.toBytes()}, baseData}, algorithm); Q_ASSERT(hashResult.size() >= 16); hashResult.truncate(16); // Sha1 will be too long @@ -142,6 +142,11 @@ static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCrypto \reentrant + \compares strong + \compareswith strong GUID + \note Comparison with GUID is Windows-only. + \endcompareswith + Using \e{U}niversally \e{U}nique \e{ID}entifiers (UUID) is a standard way to uniquely identify entities in a distributed computing environment. A UUID is a 16-byte (128-bit) number @@ -527,11 +532,14 @@ QUuid QUuid::fromString(QAnyStringView text) noexcept /*! \since 5.0 - \fn QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &baseData); + \fn QUuid QUuid::createUuidV3(QUuid ns, QByteArrayView baseData); This function returns a new UUID with variant QUuid::DCE and version QUuid::Md5. \a ns is the namespace and \a baseData is the basic data as described by RFC 4122. + \note In Qt versions prior to 6.8, this function took QByteArray, not + QByteArrayView. + \sa variant(), version(), createUuidV5() */ @@ -547,11 +555,14 @@ QUuid QUuid::fromString(QAnyStringView text) noexcept /*! \since 5.0 - \fn QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData); + \fn QUuid QUuid::createUuidV5(QUuid ns, QByteArrayView baseData); This function returns a new UUID with variant QUuid::DCE and version QUuid::Sha1. \a ns is the namespace and \a baseData is the basic data as described by RFC 4122. + \note In Qt versions prior to 6.8, this function took QByteArray, not + QByteArrayView. + \sa variant(), version(), createUuidV3() */ @@ -565,13 +576,13 @@ QUuid QUuid::fromString(QAnyStringView text) noexcept \sa variant(), version(), createUuidV3() */ #ifndef QT_BOOTSTRAPPED -QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &baseData) +QUuid QUuid::createUuidV3(QUuid ns, QByteArrayView baseData) noexcept { return createFromName(ns, baseData, QCryptographicHash::Md5, 3); } #endif -QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData) +QUuid QUuid::createUuidV5(QUuid ns, QByteArrayView baseData) noexcept { return createFromName(ns, baseData, QCryptographicHash::Sha1, 5); } @@ -600,16 +611,16 @@ QUuid QUuid::fromRfc4122(QByteArrayView bytes) noexcept } /*! - \fn bool QUuid::operator==(const QUuid &other) const + \fn bool QUuid::operator==(const QUuid &lhs, const QUuid &rhs) - Returns \c true if this QUuid and the \a other QUuid are identical; + Returns \c true if \a lhs QUuid and the \a rhs QUuid are identical; otherwise returns \c false. */ /*! - \fn bool QUuid::operator!=(const QUuid &other) const + \fn bool QUuid::operator!=(const QUuid &lhs, const QUuid &rhs) - Returns \c true if this QUuid and the \a other QUuid are different; + Returns \c true if \a lhs QUuid and the \a rhs QUuid are different; otherwise returns \c false. */ @@ -898,51 +909,31 @@ QUuid::Version QUuid::version() const noexcept } /*! - \fn bool QUuid::operator<(const QUuid &other) const + \fn bool QUuid::operator<(const QUuid &lhs, const QUuid &rhs) - Returns \c true if this QUuid has the same \l{Variant field} - {variant field} as the \a other QUuid and is lexicographically - \e{before} the \a other QUuid. If the \a other QUuid has a + Returns \c true if \a lhs QUuid has the same \l{Variant field} + {variant field} as the \a rhs QUuid and is lexicographically + \e{before} the \a rhs QUuid. If the \a rhs QUuid has a different variant field, the return value is determined by comparing the two \l{QUuid::Variant} {variants}. \sa variant() */ -bool QUuid::operator<(const QUuid &other) const noexcept -{ - if (variant() != other.variant()) - return variant() < other.variant(); - -#define ISLESS(f1, f2) if (f1!=f2) return (f1<f2); - ISLESS(data1, other.data1); - ISLESS(data2, other.data2); - ISLESS(data3, other.data3); - for (int n = 0; n < 8; n++) { - ISLESS(data4[n], other.data4[n]); - } -#undef ISLESS - return false; -} /*! - \fn bool QUuid::operator>(const QUuid &other) const + \fn bool QUuid::operator>(const QUuid &lhs, const QUuid &rhs) - Returns \c true if this QUuid has the same \l{Variant field} - {variant field} as the \a other QUuid and is lexicographically - \e{after} the \a other QUuid. If the \a other QUuid has a + Returns \c true if \a lhs QUuid has the same \l{Variant field} + {variant field} as the \a rhs QUuid and is lexicographically + \e{after} the \a rhs QUuid. If the \a rhs QUuid has a different variant field, the return value is determined by comparing the two \l{QUuid::Variant} {variants}. \sa variant() */ -bool QUuid::operator>(const QUuid &other) const noexcept -{ - return other < *this; -} /*! - \fn bool operator<=(const QUuid &lhs, const QUuid &rhs) - \relates QUuid + \fn bool QUuid::operator<=(const QUuid &lhs, const QUuid &rhs) \since 5.5 Returns \c true if \a lhs has the same \l{Variant field} @@ -955,8 +946,7 @@ bool QUuid::operator>(const QUuid &other) const noexcept */ /*! - \fn bool operator>=(const QUuid &lhs, const QUuid &rhs) - \relates QUuid + \fn bool QUuid::operator>=(const QUuid &lhs, const QUuid &rhs) \since 5.5 Returns \c true if \a lhs has the same \l{Variant field} @@ -1009,17 +999,17 @@ QUuid QUuid::createUuid() #endif // !Q_OS_WIN && !QT_BOOTSTRAPPED /*! - \fn bool QUuid::operator==(const GUID &guid) const + \fn bool QUuid::operator==(const QUuid &lhs, const GUID &rhs) - Returns \c true if this UUID is equal to the Windows GUID \a guid; + Returns \c true if \a lhs UUID is equal to the Windows GUID \a rhs; otherwise returns \c false. */ /*! - \fn bool QUuid::operator!=(const GUID &guid) const + \fn bool QUuid::operator!=(const QUuid &lhs, const GUID &rhs) - Returns \c true if this UUID is not equal to the Windows GUID \a - guid; otherwise returns \c false. + Returns \c true if \a lhs UUID is not equal to the Windows GUID \a rhs; + otherwise returns \c false. */ #ifndef QT_NO_DEBUG_STREAM diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index 7125e8e2cc..591d9b27c4 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -4,6 +4,7 @@ #ifndef QUUID_H #define QUUID_H +#include <QtCore/qcompare.h> #include <QtCore/qendian.h> #include <QtCore/qstring.h> @@ -122,27 +123,60 @@ QT_WARNING_POP constexpr quint128 toUInt128(QSysInfo::Endian order = QSysInfo::BigEndian) const noexcept; #endif - constexpr bool operator==(const QUuid &orig) const noexcept +private: + friend constexpr bool comparesEqual(const QUuid &lhs, const QUuid &rhs) noexcept { - if (data1 != orig.data1 || data2 != orig.data2 || - data3 != orig.data3) + if (lhs.data1 != rhs.data1 || lhs.data2 != rhs.data2 || lhs.data3 != rhs.data3) return false; - for (uint i = 0; i < 8; i++) - if (data4[i] != orig.data4[i]) + for (uint i = 0; i < 8; i++) { + if (lhs.data4[i] != rhs.data4[i]) return false; + } return true; } + friend Qt::strong_ordering compareThreeWay(const QUuid &lhs, const QUuid &rhs) noexcept + { + if (lhs.variant() != rhs.variant()) + return Qt::compareThreeWay(lhs.variant(), rhs.variant()); + if (lhs.data1 != rhs.data1) + return Qt::compareThreeWay(lhs.data1, rhs.data1); + if (lhs.data2 != rhs.data2) + return Qt::compareThreeWay(lhs.data2, rhs.data2); + if (lhs.data3 != rhs.data3) + return Qt::compareThreeWay(lhs.data3, rhs.data3); + + int c = std::memcmp(lhs.data4, rhs.data4, sizeof(lhs.data4)); + return Qt::compareThreeWay(c, 0); + } + +public: +/* To prevent a meta-type creation ambiguity on Windows, we put comparison + macros under NOT QT_CORE_REMOVED_SINCE(6, 8) part. */ +#if QT_CORE_REMOVED_SINCE(6, 8) + constexpr bool operator==(const QUuid &orig) const noexcept + { + return comparesEqual(*this, orig); + } constexpr bool operator!=(const QUuid &orig) const noexcept { - return !(*this == orig); + return !operator==(orig); } bool operator<(const QUuid &other) const noexcept; bool operator>(const QUuid &other) const noexcept; - +#else +private: +#if defined(__cpp_lib_three_way_comparison) && !defined(Q_QDOC) + QT_DECLARE_3WAY_HELPER_STRONG(QUuid, QUuid, /* non-constexpr */, /* no attributes */) +#else + QT_DECLARE_ORDERING_HELPER_STRONG(QUuid, QUuid, /* non-constexpr */, /* no attributes */) +#endif // defined(__cpp_lib_three_way_comparison) && !defined(Q_QDOC) + Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QUuid) +#endif // QT_CORE_REMOVED_SINCE(6, 8) +public: #if defined(Q_OS_WIN) || defined(Q_QDOC) // On Windows we have a type GUID that is used by the platform API, so we // provide convenience operators to cast from and to this type. @@ -162,32 +196,51 @@ QT_WARNING_POP GUID guid = { data1, data2, data3, { data4[0], data4[1], data4[2], data4[3], data4[4], data4[5], data4[6], data4[7] } }; return guid; } - +private: + friend constexpr bool comparesEqual(const QUuid &lhs, const GUID &rhs) noexcept + { + return comparesEqual(lhs, QUuid(rhs)); + } +public: +/* To prevent a meta-type creation ambiguity on Windows, we put comparison + macros under NOT QT_CORE_REMOVED_SINCE(6, 8) part. */ +#if QT_CORE_REMOVED_SINCE(6, 8) constexpr bool operator==(const GUID &guid) const noexcept { - return *this == QUuid(guid); + return comparesEqual(*this, QUuid(guid)); } constexpr bool operator!=(const GUID &guid) const noexcept { - return !(*this == guid); + return !operator==(guid); } +#else + Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QUuid, GUID) +#endif // !QT_CORE_REMOVED_SINCE(6, 8) #endif +public: static QUuid createUuid(); -#ifndef QT_BOOTSTRAPPED - static QUuid createUuidV3(const QUuid &ns, const QByteArray &baseData); +#if QT_CORE_REMOVED_SINCE(6, 8) + static QUuid createUuidV3(const QUuid &ns, const QByteArray &baseData) noexcept; + static QUuid createUuidV5(const QUuid &ns, const QByteArray &baseData) noexcept; #endif - static QUuid createUuidV5(const QUuid &ns, const QByteArray &baseData); + static QUuid createUuidV5(QUuid ns, QByteArrayView baseData) noexcept; #ifndef QT_BOOTSTRAPPED + static QUuid createUuidV3(QUuid ns, QByteArrayView baseData) noexcept; +#if !QT_CORE_REMOVED_SINCE(6, 8) + Q_WEAK_OVERLOAD +#endif static inline QUuid createUuidV3(const QUuid &ns, const QString &baseData) { - return QUuid::createUuidV3(ns, baseData.toUtf8()); + return QUuid::createUuidV3(ns, qToByteArrayViewIgnoringNull(baseData.toUtf8())); } #endif - +#if !QT_CORE_REMOVED_SINCE(6, 8) + Q_WEAK_OVERLOAD +#endif static inline QUuid createUuidV5(const QUuid &ns, const QString &baseData) { - return QUuid::createUuidV5(ns, baseData.toUtf8()); + return QUuid::createUuidV5(ns, qToByteArrayViewIgnoringNull(baseData.toUtf8())); } QUuid::Variant variant() const noexcept; @@ -291,11 +344,6 @@ constexpr quint128 QUuid::toUInt128(QSysInfo::Endian order) const noexcept } #endif -inline bool operator<=(const QUuid &lhs, const QUuid &rhs) noexcept -{ return !(rhs < lhs); } -inline bool operator>=(const QUuid &lhs, const QUuid &rhs) noexcept -{ return !(lhs < rhs); } - #if defined(Q_QDOC) // provide fake declarations of qXXXEndian() functions, so that qDoc could // distinguish them from the general template |