From b084739b89fbd32047d454075daf147073926f18 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 14 May 2016 11:17:48 -0700 Subject: Revert "QMutexPool: avoid QVarLengthArray of QAtomicPointers" This reverts commit 4579d966af2e5d4ba229f13312eeb2f921406038. This causes a miscompilation with ICC 16 on Windows (MSVC 2015 ABI): the vector created by new[] with () in: mutexes(new QAtomicPointer[size]()), // (): zero-initialize does not actually zero-initialize (see disassembly in the bug report). This is definitely a compiler bug. Since we plan on removing QMutexPool in Qt 5.8 anyway, let's just revert the patch. Task-number: QTBUG-53360 Change-Id: I06bae9392f534e45b3f1ffff144e823b747e7962 Reviewed-by: Kai Koehne --- src/corelib/thread/qmutexpool.cpp | 11 ++++++----- src/corelib/thread/qmutexpool_p.h | 5 ++--- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/thread/qmutexpool.cpp b/src/corelib/thread/qmutexpool.cpp index 522fd5eac2..90b6989467 100644 --- a/src/corelib/thread/qmutexpool.cpp +++ b/src/corelib/thread/qmutexpool.cpp @@ -92,10 +92,11 @@ Q_GLOBAL_STATIC_WITH_ARGS(QMutexPool, globalMutexPool, (QMutex::Recursive)) QMutexPool is destructed. */ QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size) - : count(size), - mutexes(new QAtomicPointer[size]()), // (): zero-initialize - recursionMode(recursionMode) + : mutexes(size), recursionMode(recursionMode) { + for (int index = 0; index < mutexes.count(); ++index) { + mutexes[index].store(0); + } } /*! @@ -104,8 +105,8 @@ QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size) */ QMutexPool::~QMutexPool() { - qDeleteAll(mutexes, mutexes + count); - delete[] mutexes; + for (int index = 0; index < mutexes.count(); ++index) + delete mutexes[index].load(); } /*! diff --git a/src/corelib/thread/qmutexpool_p.h b/src/corelib/thread/qmutexpool_p.h index 33e9a52cb7..796e65d960 100644 --- a/src/corelib/thread/qmutexpool_p.h +++ b/src/corelib/thread/qmutexpool_p.h @@ -66,7 +66,7 @@ public: ~QMutexPool(); inline QMutex *get(const void *address) { - int index = uint(quintptr(address)) % count; + int index = uint(quintptr(address)) % mutexes.count(); QMutex *m = mutexes[index].load(); if (m) return m; @@ -78,8 +78,7 @@ public: private: QMutex *createMutex(int index); - int count; - QAtomicPointer *mutexes; + QVarLengthArray, 131> mutexes; QMutex::RecursionMode recursionMode; }; -- cgit v1.2.3 From 184b2ea4ea9c3e4ad735ff67c5a399e9613da8ab Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 25 May 2016 16:47:29 +0200 Subject: Check for CRC32 properly Just being on ARMv8 does not mean CRC32 (and arm_acle.h) is available. Task-number: QTBUG-53629 Change-Id: I104f643f2d59620e1f4d1ef814a1de71bb484e7b Reviewed-by: Thiago Macieira --- src/corelib/tools/qsimd_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qsimd_p.h b/src/corelib/tools/qsimd_p.h index 8ddaed8032..f68ae5d3b8 100644 --- a/src/corelib/tools/qsimd_p.h +++ b/src/corelib/tools/qsimd_p.h @@ -285,7 +285,7 @@ #endif #endif // AArch64/ARM64 -#if defined(Q_PROCESSOR_ARM_V8) +#if defined(Q_PROCESSOR_ARM_V8) && defined(__ARM_FEATURE_CRC32) #define QT_FUNCTION_TARGET_STRING_CRC32 "+crc" # include #endif -- cgit v1.2.3 From 5c2ff22ba117f295718c529198ab42ee4646d90c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 26 Apr 2016 16:40:37 -0700 Subject: Use void instead of uchar in the endian-swapping function parameters This allows us to pass pointers to storage that is not an array of uchar, which it hardly ever is. Change-Id: Ifea6e497f11a461db432ffff14490d2c2df21906 Reviewed-by: Konstantin Ritt Reviewed-by: Marc Mutz --- src/corelib/global/qendian.h | 57 ++++++++++++++++---------------- src/corelib/global/qendian.qdoc | 20 +++++++---- src/corelib/json/qjson.cpp | 2 +- src/corelib/json/qjsonparser.cpp | 2 +- src/corelib/mimetypes/qmimemagicrule.cpp | 2 +- src/corelib/plugin/qelfparser_p.h | 4 +-- 6 files changed, 48 insertions(+), 39 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qendian.h b/src/corelib/global/qendian.h index 34bb015a2f..c2028289a7 100644 --- a/src/corelib/global/qendian.h +++ b/src/corelib/global/qendian.h @@ -58,25 +58,26 @@ QT_BEGIN_NAMESPACE /* * ENDIAN FUNCTIONS */ -inline void qbswap_helper(const uchar *src, uchar *dest, int size) +inline void qbswap_helper(const void *src, void *dest, int size) { - for (int i = 0; i < size ; ++i) dest[i] = src[size - 1 - i]; + for (int i = 0; i < size ; ++i) + static_cast(dest)[i] = static_cast(src)[size - 1 - i]; } /* - * qbswap(const T src, const uchar *dest); + * qbswap(const T src, const void *dest); * Changes the byte order of \a src from big endian to little endian or vice versa * and stores the result in \a dest. * There is no alignment requirements for \a dest. */ -template inline void qbswap(const T src, uchar *dest) +template inline void qbswap(const T src, void *dest) { - qbswap_helper(reinterpret_cast(&src), dest, sizeof(T)); + qbswap_helper(&src, dest, sizeof(T)); } // Used to implement a type-safe and alignment-safe copy operation // If you want to avoid the memcpy, you must write specializations for these functions -template Q_ALWAYS_INLINE void qToUnaligned(const T src, uchar *dest) +template Q_ALWAYS_INLINE void qToUnaligned(const T src, void *dest) { // Using sizeof(T) inside memcpy function produces internal compiler error with // MSVC2008/ARM in tst_endian -> use extra indirection to resolve size of T. @@ -89,7 +90,7 @@ template Q_ALWAYS_INLINE void qToUnaligned(const T src, uchar *dest (dest, &src, size); } -template Q_ALWAYS_INLINE T qFromUnaligned(const uchar *src) +template Q_ALWAYS_INLINE T qFromUnaligned(const void *src) { T dest; const size_t size = sizeof(T); @@ -122,11 +123,11 @@ template <> inline quint32 qbswap(quint32 source) return __builtin_bswap32(source); } -template <> inline void qbswap(quint64 source, uchar *dest) +template <> inline void qbswap(quint64 source, void *dest) { qToUnaligned(__builtin_bswap64(source), dest); } -template <> inline void qbswap(quint32 source, uchar *dest) +template <> inline void qbswap(quint32 source, void *dest) { qToUnaligned(__builtin_bswap32(source), dest); } @@ -158,7 +159,7 @@ template <> inline quint16 qbswap(quint16 source) { return __builtin_bswap16(source); } -template <> inline void qbswap(quint16 source, uchar *dest) +template <> inline void qbswap(quint16 source, void *dest) { qToUnaligned(__builtin_bswap16(source), dest); } @@ -187,17 +188,17 @@ template <> inline qint16 qbswap(qint16 source) return qbswap(quint16(source)); } -template <> inline void qbswap(qint64 source, uchar *dest) +template <> inline void qbswap(qint64 source, void *dest) { qbswap(quint64(source), dest); } -template <> inline void qbswap(qint32 source, uchar *dest) +template <> inline void qbswap(qint32 source, void *dest) { qbswap(quint32(source), dest); } -template <> inline void qbswap(qint16 source, uchar *dest) +template <> inline void qbswap(qint16 source, void *dest) { qbswap(quint16(source), dest); } @@ -212,9 +213,9 @@ template inline T qToLittleEndian(T source) { return qbswap(source); } template inline T qFromLittleEndian(T source) { return qbswap(source); } -template inline void qToBigEndian(T src, uchar *dest) +template inline void qToBigEndian(T src, void *dest) { qToUnaligned(src, dest); } -template inline void qToLittleEndian(T src, uchar *dest) +template inline void qToLittleEndian(T src, void *dest) { qbswap(src, dest); } #else // Q_LITTLE_ENDIAN @@ -226,9 +227,9 @@ template inline T qToLittleEndian(T source) { return source; } template inline T qFromLittleEndian(T source) { return source; } -template inline void qToBigEndian(T src, uchar *dest) +template inline void qToBigEndian(T src, void *dest) { qbswap(src, dest); } -template inline void qToLittleEndian(T src, uchar *dest) +template inline void qToLittleEndian(T src, void *dest) { qToUnaligned(src, dest); } #endif // Q_BYTE_ORDER == Q_BIG_ENDIAN @@ -243,34 +244,34 @@ template <> inline qint8 qbswap(qint8 source) return source; } -/* T qFromLittleEndian(const uchar *src) +/* T qFromLittleEndian(const void *src) * This function will read a little-endian encoded value from \a src * and return the value in host-endian encoding. * There is no requirement that \a src must be aligned. */ -template inline T qFromLittleEndian(const uchar *src) +template inline T qFromLittleEndian(const void *src) { return qFromLittleEndian(qFromUnaligned(src)); } -template <> inline quint8 qFromLittleEndian(const uchar *src) -{ return static_cast(src[0]); } -template <> inline qint8 qFromLittleEndian(const uchar *src) -{ return static_cast(src[0]); } +template <> inline quint8 qFromLittleEndian(const void *src) +{ return static_cast(src)[0]; } +template <> inline qint8 qFromLittleEndian(const void *src) +{ return static_cast(src)[0]; } /* This function will read a big-endian (also known as network order) encoded value from \a src * and return the value in host-endian encoding. * There is no requirement that \a src must be aligned. */ -template inline T qFromBigEndian(const uchar *src) +template inline T qFromBigEndian(const void *src) { return qFromBigEndian(qFromUnaligned(src)); } -template <> inline quint8 qFromBigEndian(const uchar *src) -{ return static_cast(src[0]); } -template <> inline qint8 qFromBigEndian(const uchar *src) -{ return static_cast(src[0]); } +template <> inline quint8 qFromBigEndian(const void *src) +{ return static_cast(src)[0]; } +template <> inline qint8 qFromBigEndian(const void *src) +{ return static_cast(src)[0]; } QT_END_NAMESPACE diff --git a/src/corelib/global/qendian.qdoc b/src/corelib/global/qendian.qdoc index 3b22dcec87..9ce9dbdb0e 100644 --- a/src/corelib/global/qendian.qdoc +++ b/src/corelib/global/qendian.qdoc @@ -35,7 +35,7 @@ /*! \internal - \fn T qFromUnaligned(const uchar *ptr) + \fn T qFromUnaligned(const void *ptr) \since 5.5 Loads a \c{T} from address \a ptr, which may be misaligned. @@ -46,7 +46,7 @@ /*! \internal - \fn void qToUnaligned(T t, uchar *ptr) + \fn void qToUnaligned(T t, void *ptr) \since 4.5 Stores \a t to address \a ptr, which may be misaligned. @@ -57,7 +57,7 @@ /*! - \fn T qFromBigEndian(const uchar *src) + \fn T qFromBigEndian(const void *src) \since 4.3 \relates @@ -69,6 +69,8 @@ \note Template type \c{T} can either be a qint16, qint32 or qint64. Other types of integers, e.g., qlong, are not applicable. + \note Since Qt 5.7, the type of the \a src parameter is a void pointer. + There are no data alignment constraints for \a src. \sa qFromLittleEndian() @@ -88,7 +90,7 @@ unmodified. */ /*! - \fn T qFromLittleEndian(const uchar *src) + \fn T qFromLittleEndian(const void *src) \since 4.3 \relates @@ -100,6 +102,8 @@ \note Template type \c{T} can either be a qint16, qint32 or qint64. Other types of integers, e.g., qlong, are not applicable. + \note Since Qt 5.7, the type of the \a src parameter is a void pointer. + There are no data alignment constraints for \a src. \sa qFromBigEndian() @@ -119,7 +123,7 @@ unmodified. */ /*! - \fn void qToBigEndian(T src, uchar *dest) + \fn void qToBigEndian(T src, void *dest) \since 4.3 \relates @@ -130,6 +134,8 @@ There are no data alignment constraints for \a dest. + \note Since Qt 5.7, the type of the \a dest parameter is a void pointer. + \sa qFromBigEndian() \sa qFromLittleEndian() \sa qToLittleEndian() @@ -147,7 +153,7 @@ unmodified. */ /*! - \fn void qToLittleEndian(T src, uchar *dest) + \fn void qToLittleEndian(T src, void *dest) \since 4.3 \relates @@ -158,6 +164,8 @@ There are no data alignment constraints for \a dest. + \note Since Qt 5.7, the type of the \a dest parameter is a void pointer. + \sa qFromBigEndian() \sa qFromLittleEndian() \sa qToBigEndian() diff --git a/src/corelib/json/qjson.cpp b/src/corelib/json/qjson.cpp index bb98e25fa5..4b98ef076c 100644 --- a/src/corelib/json/qjson.cpp +++ b/src/corelib/json/qjson.cpp @@ -435,7 +435,7 @@ void Value::copyData(const QJsonValue &v, char *dest, bool compressed) switch (v.t) { case QJsonValue::Double: if (!compressed) { - qToLittleEndian(v.ui, (uchar *)dest); + qToLittleEndian(v.ui, dest); } break; case QJsonValue::String: { diff --git a/src/corelib/json/qjsonparser.cpp b/src/corelib/json/qjsonparser.cpp index 2926adf10a..6a3d1de99a 100644 --- a/src/corelib/json/qjsonparser.cpp +++ b/src/corelib/json/qjsonparser.cpp @@ -738,7 +738,7 @@ bool Parser::parseNumber(QJsonPrivate::Value *val, int baseOffset) } int pos = reserveSpace(sizeof(double)); - qToLittleEndian(ui, reinterpret_cast(data + pos)); + qToLittleEndian(ui, data + pos); if (current - baseOffset >= Value::MaxSize) { lastError = QJsonParseError::DocumentTooLarge; return false; diff --git a/src/corelib/mimetypes/qmimemagicrule.cpp b/src/corelib/mimetypes/qmimemagicrule.cpp index 8461bf7130..7e07f8acb9 100644 --- a/src/corelib/mimetypes/qmimemagicrule.cpp +++ b/src/corelib/mimetypes/qmimemagicrule.cpp @@ -163,7 +163,7 @@ bool QMimeMagicRule::matchNumber(const QByteArray &data) const const char *p = data.constData() + m_startPos; const char *e = data.constData() + qMin(data.size() - int(sizeof(T)), m_endPos + 1); for ( ; p <= e; ++p) { - if ((qFromUnaligned(reinterpret_cast(p)) & mask) == (value & mask)) + if ((qFromUnaligned(p) & mask) == (value & mask)) return true; } diff --git a/src/corelib/plugin/qelfparser_p.h b/src/corelib/plugin/qelfparser_p.h index 2ecdc4e786..145f00df43 100644 --- a/src/corelib/plugin/qelfparser_p.h +++ b/src/corelib/plugin/qelfparser_p.h @@ -89,9 +89,9 @@ public: T read(const char *s) { if (m_endian == ElfBigEndian) - return qFromBigEndian(reinterpret_cast(s)); + return qFromBigEndian(s); else - return qFromLittleEndian(reinterpret_cast(s)); + return qFromLittleEndian(s); } const char *parseSectionHeader(const char* s, ElfSectionHeader *sh); -- cgit v1.2.3 From e454e986d57bacbc895cc4f476d2b100b782936c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 3 Jun 2016 22:43:03 -0300 Subject: Move the Q_DECL_UNUSED attribute elsewhere to satisfy ICC 17 It doesn't like the attribute there. I think it's a compiler bug, but I can't be sure because the part of the standard dealing with the placement of attributes and where they apply is very complex. Exercise left for the reader to determine if ICC is correct or not to reject it there. Change-Id: I87e17314d8b24ae983b1fffd1454bde826b7bcf4 Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Simon Hausmann Reviewed-by: Frederik Gladhorn --- src/corelib/global/qglobal.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 2081ca8649..118203f720 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1080,9 +1080,9 @@ struct QOverload : QConstOverload, QNonConstOverload }; #if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304 // C++14 -template Q_CONSTEXPR QOverload qOverload Q_DECL_UNUSED = {}; -template Q_CONSTEXPR QConstOverload qConstOverload Q_DECL_UNUSED = {}; -template Q_CONSTEXPR QNonConstOverload qNonConstOverload Q_DECL_UNUSED = {}; +template Q_CONSTEXPR Q_DECL_UNUSED QOverload qOverload = {}; +template Q_CONSTEXPR Q_DECL_UNUSED QConstOverload qConstOverload = {}; +template Q_CONSTEXPR Q_DECL_UNUSED QNonConstOverload qNonConstOverload = {}; #endif #endif -- cgit v1.2.3