diff options
Diffstat (limited to 'src/corelib')
31 files changed, 344 insertions, 93 deletions
diff --git a/src/corelib/arch/qatomic_cxx11.h b/src/corelib/arch/qatomic_cxx11.h index 09e900f4ea..0e06ca951a 100644 --- a/src/corelib/arch/qatomic_cxx11.h +++ b/src/corelib/arch/qatomic_cxx11.h @@ -328,10 +328,10 @@ template <typename X> struct QAtomicOps } }; -#ifdef ATOMIC_VAR_INIT -# define Q_BASIC_ATOMIC_INITIALIZER(a) { ATOMIC_VAR_INIT(a) } +#if defined(Q_COMPILER_CONSTEXPR) && defined(Q_COMPILER_DEFAULT_MEMBERS) && defined(Q_COMPILER_DELETE_MEMBERS) +# define Q_BASIC_ATOMIC_INITIALIZER(a) { a } #else -# define Q_BASIC_ATOMIC_INITIALIZER(a) { {a} } +# define Q_BASIC_ATOMIC_INITIALIZER(a) { ATOMIC_VAR_INIT(a) } #endif QT_END_NAMESPACE diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp index 64863cdb05..98d4b2e4e3 100644 --- a/src/corelib/codecs/qutfcodec.cpp +++ b/src/corelib/codecs/qutfcodec.cpp @@ -51,8 +51,8 @@ static inline bool simdEncodeAscii(uchar *&dst, const ushort *&nextAscii, const { // do sixteen characters at a time for ( ; end - src >= 16; src += 16, dst += 16) { - __m128i data1 = _mm_loadu_si128((__m128i*)src); - __m128i data2 = _mm_loadu_si128(1+(__m128i*)src); + __m128i data1 = _mm_loadu_si128((const __m128i*)src); + __m128i data2 = _mm_loadu_si128(1+(const __m128i*)src); // check if everything is ASCII @@ -90,7 +90,7 @@ static inline bool simdDecodeAscii(ushort *&dst, const uchar *&nextAscii, const { // do sixteen characters at a time for ( ; end - src >= 16; src += 16, dst += 16) { - __m128i data = _mm_loadu_si128((__m128i*)src); + __m128i data = _mm_loadu_si128((const __m128i*)src); #ifdef __AVX2__ const int BitSpacing = 2; @@ -390,7 +390,7 @@ QString QUtf8::convertToUnicode(const char *chars, int len, QTextCodec::Converte *dst++ = QChar::ReplacementCharacter; } - result.truncate(dst - (ushort *)result.unicode()); + result.truncate(dst - (const ushort *)result.unicode()); if (state) { state->invalidChars += invalid; if (headerdone) @@ -469,7 +469,7 @@ QString QUtf16::convertToUnicode(const char *chars, int len, QTextCodec::Convert endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? BigEndianness : LittleEndianness; QString result(len, Qt::Uninitialized); // worst case - QChar *qch = (QChar *)result.unicode(); + QChar *qch = (QChar *)result.data(); while (len--) { if (half) { QChar ch; @@ -600,7 +600,7 @@ QString QUtf32::convertToUnicode(const char *chars, int len, QTextCodec::Convert QString result; result.resize((num + len) >> 2 << 1); // worst case - QChar *qch = (QChar *)result.unicode(); + QChar *qch = (QChar *)result.data(); const char *end = chars + len; while (chars < end) { diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index c582b1f238..4828d8596a 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -572,6 +572,9 @@ # if _MSC_VER < 1900 // ICC disables unicode string support when compatibility mode with MSVC 2013 or lower is active # undef Q_COMPILER_UNICODE_STRINGS +// Disable constexpr unless the MS headers have constexpr in all the right places too +// (like std::numeric_limits<T>::max()) +# undef Q_COMPILER_CONSTEXPR # endif # endif # endif @@ -1140,7 +1143,7 @@ # define QT_WARNING_DISABLE_GCC(text) QT_DO_PRAGMA(GCC diagnostic ignored text) // GCC directives work in Clang too # define QT_WARNING_DISABLE_INTEL(number) # define QT_WARNING_DISABLE_MSVC(number) -#elif defined(Q_CC_GNU) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 405) +#elif defined(Q_CC_GNU) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) # define QT_WARNING_PUSH QT_DO_PRAGMA(GCC diagnostic push) # define QT_WARNING_POP QT_DO_PRAGMA(GCC diagnostic pop) # define QT_WARNING_DISABLE_GCC(text) QT_DO_PRAGMA(GCC diagnostic ignored text) diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index f335794fed..37a765b40a 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1178,7 +1178,7 @@ bool qSharedBuild() Q_DECL_NOTHROW \relates <QtGlobal> Defined on Darwin-based operating systems distributed by Apple, which - currently includes OS X and iOS, but not the open source version. + currently includes OS X and iOS, but not the open source versions of Darwin. */ /*! @@ -1200,7 +1200,7 @@ bool qSharedBuild() Q_DECL_NOTHROW \relates <QtGlobal> Defined on all supported versions of Windows. That is, if - \l Q_OS_WIN32, \l Q_OS_WIN64 or \l Q_OS_WINCE is defined. + \l Q_OS_WIN32, \l Q_OS_WIN64, \l Q_OS_WINCE or \l Q_OS_WINRT is defined. */ /*! @@ -2046,8 +2046,6 @@ QSysInfo::WinVersion QSysInfo::windowsVersion() } else if (osver.dwMajorVersion == 10 && osver.dwMinorVersion == 0) { winver = QSysInfo::WV_WINDOWS10; } else { - qWarning("Qt: Untested Windows version %d.%d detected!", - int(osver.dwMajorVersion), int(osver.dwMinorVersion)); winver = QSysInfo::WV_NT_based; } } diff --git a/src/corelib/io/qbuffer.cpp b/src/corelib/io/qbuffer.cpp index 680f832909..fd74681663 100644 --- a/src/corelib/io/qbuffer.cpp +++ b/src/corelib/io/qbuffer.cpp @@ -425,7 +425,7 @@ qint64 QBuffer::writeData(const char *data, qint64 len) } } - memcpy(d->buf->data() + pos(), (uchar *)data, int(len)); + memcpy(d->buf->data() + pos(), data, int(len)); #ifndef QT_NO_QOBJECT d->writtenSinceLastEmit += len; diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 8676fe0259..54a705b72b 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -174,6 +174,16 @@ void QDebug::putUcs4(uint ucs4) maybeQuote('\''); } +// These two functions return true if the character should be printed by QDebug. +// For QByteArray, this is technically identical to US-ASCII isprint(); +// for QString, we use QChar::isPrint, which requires a full UCS-4 decode. +static inline bool isPrintable(uint ucs4) +{ return QChar::isPrint(ucs4); } +static inline bool isPrintable(ushort uc) +{ return QChar::isPrint(uc); } +static inline bool isPrintable(uchar c) +{ return c >= ' ' && c < 0x7f; } + template <typename Char> static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, int length, bool isUnicode = true) { @@ -194,22 +204,23 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, in } if (sizeof(Char) == sizeof(QChar)) { + // Surrogate characters are category Cs (Other_Surrogate), so isPrintable = false for them int runLength = 0; while (p + runLength != end && - p[runLength] < 0x7f && p[runLength] >= 0x20 && p[runLength] != '\\' && p[runLength] != '"') + isPrintable(p[runLength]) && p[runLength] != '\\' && p[runLength] != '"') ++runLength; if (runLength) { d->write(reinterpret_cast<const QChar *>(p), runLength); p += runLength - 1; continue; } - } else if (*p < 0x7f && *p >= 0x20 && *p != '\\' && *p != '"') { + } else if (isPrintable(*p) && *p != '\\' && *p != '"') { QChar c = QLatin1Char(*p); d->write(&c, 1); continue; } - // print as an escape sequence + // print as an escape sequence (maybe, see below for surrogate pairs) int buflen = 2; ushort buf[sizeof "\\U12345678" - 1]; buf[0] = '\\'; @@ -248,17 +259,23 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, in if ((p + 1) != end && QChar::isLowSurrogate(p[1])) { // properly-paired surrogates uint ucs4 = QChar::surrogateToUcs4(*p, p[1]); + if (isPrintable(ucs4)) { + buf[0] = *p; + buf[1] = p[1]; + buflen = 2; + } else { + buf[1] = 'U'; + buf[2] = '0'; // toHexUpper(ucs4 >> 32); + buf[3] = '0'; // toHexUpper(ucs4 >> 28); + buf[4] = toHexUpper(ucs4 >> 20); + buf[5] = toHexUpper(ucs4 >> 16); + buf[6] = toHexUpper(ucs4 >> 12); + buf[7] = toHexUpper(ucs4 >> 8); + buf[8] = toHexUpper(ucs4 >> 4); + buf[9] = toHexUpper(ucs4); + buflen = 10; + } ++p; - buf[1] = 'U'; - buf[2] = '0'; // toHexUpper(ucs4 >> 32); - buf[3] = '0'; // toHexUpper(ucs4 >> 28); - buf[4] = toHexUpper(ucs4 >> 20); - buf[5] = toHexUpper(ucs4 >> 16); - buf[6] = toHexUpper(ucs4 >> 12); - buf[7] = toHexUpper(ucs4 >> 8); - buf[8] = toHexUpper(ucs4 >> 4); - buf[9] = toHexUpper(ucs4); - buflen = 10; break; } // improperly-paired surrogates, fall through @@ -409,6 +426,9 @@ QDebug &QDebug::resetFormat() Disables automatic insertion of quotation characters around QChar, QString and QByteArray contents and returns a reference to the stream. + When quoting is disabled, these types are printed without quotation + characters and without escaping of non-printable characters. + \sa quote(), maybeQuote() */ @@ -454,7 +474,11 @@ QDebug &QDebug::resetFormat() \fn QDebug &QDebug::operator<<(QChar t) Writes the character, \a t, to the stream and returns a reference to the - stream. + stream. Normally, QDebug prints control characters and non-US-ASCII + characters as their C escape sequences or their Unicode value (\\u1234). To + print non-printable characters without transformation, enable the noquote() + functionality, but note that some QDebug backends may not be 8-bit clean + and may not be able to represent \c t. */ /*! @@ -545,34 +569,114 @@ QDebug &QDebug::resetFormat() \fn QDebug &QDebug::operator<<(const char *s) Writes the '\\0'-terminated string, \a s, to the stream and returns a - reference to the stream. + reference to the stream. The string is never quoted nor transformed to the + output, but note that some QDebug backends might not be 8-bit clean. */ /*! \fn QDebug &QDebug::operator<<(const QString &s) - Writes the string, \a s, to the stream and returns a reference to the stream. + Writes the string, \a s, to the stream and returns a reference to the + stream. Normally, QDebug prints the string inside quotes and transforms + non-printable characters to their Unicode values (\\u1234). + + To print non-printable characters without transformation, enable the + noquote() functionality. Note that some QDebug backends might not be 8-bit + clean. + + Output examples: + \code + QString s; + + s = "a"; + qDebug().noquote() << s; // prints: a + qDebug() << s; // prints: "a" + + s = "\"a\r\n\""; + qDebug() << s; // prints: "\"a\r\n\"" + + s = "\033"; // escape character + qDebug() << s; // prints: "\u001B" + + s = "\u00AD"; // SOFT HYPHEN + qDebug() << s; // prints: "\u00AD" + + s = "\u00E1"; // LATIN SMALL LETTER A WITH ACUTE + qDebug() << s; // prints: "á" + + s = "a\u0301"; // "a" followed by COMBINING ACUTE ACCENT + qDebug() << s; // prints: "á"; + + s = "\u0430\u0301"; // CYRILLIC SMALL LETTER A followed by COMBINING ACUTE ACCENT + qDebug() << s; // prints: "а́" + \endcode */ /*! \fn QDebug &QDebug::operator<<(const QStringRef &s) - Writes the string reference, \a s, to the stream and returns a reference to - the stream. + Writes the string, \a s, to the stream and returns a reference to the + stream. Normally, QDebug prints the string inside quotes and transforms + non-printable characters to their Unicode values (\\u1234). + + To print non-printable characters without transformation, enable the + noquote() functionality. Note that some QDebug backends might not be 8-bit + clean. + + See the QString overload for examples. */ /*! \fn QDebug &QDebug::operator<<(QLatin1String s) - Writes the Latin1-encoded string, \a s, to the stream and returns a reference - to the stream. + Writes the string, \a s, to the stream and returns a reference to the + stream. Normally, QDebug prints the string inside quotes and transforms + non-printable characters to their Unicode values (\\u1234). + + To print non-printable characters without transformation, enable the + noquote() functionality. Note that some QDebug backends might not be 8-bit + clean. + + See the QString overload for examples. */ /*! \fn QDebug &QDebug::operator<<(const QByteArray &b) Writes the byte array, \a b, to the stream and returns a reference to the - stream. + stream. Normally, QDebug prints the array inside quotes and transforms + control or non-US-ASCII characters to their C escape sequences (\\xAB). This + way, the output is always 7-bit clean and the string can be copied from the + output and pasted back into C++ sources, if necessary. + + To print non-printable characters without transformation, enable the + noquote() functionality. Note that some QDebug backends might not be 8-bit + clean. + + Output examples: + \code + QByteArray ba; + + ba = "a"; + qDebug().noquote() << ba; // prints: a + qDebug() << ba; // prints: "a" + + ba = "\"a\r\n\""; + qDebug() << ba; // prints: "\"a\r\n\"" + + ba = "\033"; // escape character + qDebug() << ba; // prints: "\x1B" + + ba = "\xC3\xA1"; + qDebug() << ba; // prints: "\xC3\xA1" + + ba = QByteArray("a\0b", 3); + qDebug() << ba // prints: "\a\x00""b" + \endcode + + Note how QDebug needed to close and reopen the string in the way C and C++ + languages concatenate string literals so that the letter 'b' is not + interpreted as part of the previous hexadecimal escape sequence. */ /*! diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 9391799624..2f626dfc1f 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -293,7 +293,7 @@ template <class T> inline typename QtPrivate::QEnableIf< QtPrivate::IsQEnumHelper<T>::Value || QtPrivate::IsQEnumHelper<QFlags<T> >::Value, QDebug>::Type -operator<<(QDebug debug, const QFlags<T> &flags) +qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags) { const QMetaObject *obj = qt_getEnumMetaObject(T()); const char *name = qt_getEnumName(T()); @@ -304,10 +304,10 @@ template <class T> inline typename QtPrivate::QEnableIf< !QtPrivate::IsQEnumHelper<T>::Value && !QtPrivate::IsQEnumHelper<QFlags<T> >::Value, QDebug>::Type -operator<<(QDebug debug, const QFlags<T> &flags) +qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags) #else // !QT_NO_QOBJECT template <class T> -inline QDebug operator<<(QDebug debug, const QFlags<T> &flags) +inline QDebug qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags) #endif { QDebugStateSaver saver(debug); @@ -327,6 +327,14 @@ inline QDebug operator<<(QDebug debug, const QFlags<T> &flags) return debug; } +template<typename T> +inline QDebug operator<<(QDebug debug, const QFlags<T> &flags) +{ + // We have to use an indirection otherwise specialisation of some other overload of the + // operator<< the compiler would try to instantiate QFlags<T> for the QEnableIf + return qt_QMetaEnum_flagDebugOperator_helper(debug, flags); +} + #ifdef Q_OS_MAC // We provide QDebug stream operators for commonly used Core Foundation diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp index ddbd24338b..429c40da1a 100644 --- a/src/corelib/io/qfsfileengine.cpp +++ b/src/corelib/io/qfsfileengine.cpp @@ -819,13 +819,13 @@ bool QFSFileEngine::extension(Extension extension, const ExtensionOption *option return feof(d->fh); if (extension == MapExtension) { - const MapExtensionOption *options = (MapExtensionOption*)(option); + const MapExtensionOption *options = (const MapExtensionOption*)(option); MapExtensionReturn *returnValue = static_cast<MapExtensionReturn*>(output); returnValue->address = d->map(options->offset, options->size, options->flags); return (returnValue->address != 0); } if (extension == UnMapExtension) { - UnMapExtensionOption *options = (UnMapExtensionOption*)option; + const UnMapExtensionOption *options = (const UnMapExtensionOption*)option; return d->unmap(options->address); } diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp index 05c41910c5..f0b72cd9be 100644 --- a/src/corelib/io/qloggingregistry.cpp +++ b/src/corelib/io/qloggingregistry.cpp @@ -398,10 +398,12 @@ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat) Q_ASSERT(reg->categories.contains(cat)); QtMsgType enableForLevel = reg->categories.value(cat); + // NB: note that the numeric values of the Qt*Msg constants are + // not in severity order. bool debug = (enableForLevel == QtDebugMsg); - bool info = (enableForLevel <= QtInfoMsg); - bool warning = (enableForLevel <= QtWarningMsg); - bool critical = (enableForLevel <= QtCriticalMsg); + bool info = debug || (enableForLevel == QtInfoMsg); + bool warning = info || (enableForLevel == QtWarningMsg); + bool critical = warning || (enableForLevel == QtCriticalMsg); // hard-wired implementation of // qt.*.debug=false diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index f979f8e0ec..dfde5f236d 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -2122,6 +2122,13 @@ void QProcess::start(const QString &program, const QStringList &arguments, OpenM qWarning("QProcess::start: Process is already running"); return; } + if (program.isEmpty()) { + Q_D(QProcess); + d->processError = QProcess::FailedToStart; + setErrorString(tr("No program defined")); + emit error(d->processError); + return; + } d->program = program; d->arguments = arguments; @@ -2146,7 +2153,10 @@ void QProcess::start(OpenMode mode) return; } if (d->program.isEmpty()) { - qWarning("QProcess::start: program not set"); + Q_D(QProcess); + d->processError = QProcess::FailedToStart; + setErrorString(tr("No program defined")); + emit error(d->processError); return; } diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index 345f0bd65d..4e6079306b 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -956,7 +956,7 @@ public: } else #endif { - delete [] (uchar *)mappingBuffer(); + delete [] mappingBuffer(); } } QString mappingFile() const { return fileName; } @@ -1450,13 +1450,13 @@ bool QResourceFileEngine::extension(Extension extension, const ExtensionOption * { Q_D(QResourceFileEngine); if (extension == MapExtension) { - const MapExtensionOption *options = (MapExtensionOption*)(option); + const MapExtensionOption *options = (const MapExtensionOption*)(option); MapExtensionReturn *returnValue = static_cast<MapExtensionReturn*>(output); returnValue->address = d->map(options->offset, options->size, options->flags); return (returnValue->address != 0); } if (extension == UnMapExtension) { - UnMapExtensionOption *options = (UnMapExtensionOption*)option; + const UnMapExtensionOption *options = (const UnMapExtensionOption*)option; return d->unmap(options->address); } return false; diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index fa7d4647a4..ba97543c44 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -1744,13 +1744,19 @@ const QItemSelection QItemSelectionModel::selection() const \property QItemSelectionModel::selectedIndexes */ + /*! \since 5.5 - \property QItemSelectionModel::model + \property QItemSelectionModel::selection \internal */ +/*! + \since 5.5 + \property QItemSelectionModel::model + \internal +*/ /*! \since 5.5 diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index 4ee37defae..0771fd0e30 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -2725,7 +2725,7 @@ bool QSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex & The default implementation returns \c true if the value held by the relevant item matches the filter string, wildcard string or regular expression. - \note By default, the Qt::DisplayRole is used to determine if the row + \note By default, the Qt::DisplayRole is used to determine if the column should be accepted or not. This can be changed by setting the \l filterRole property. diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 5e15f2d773..e08f709cd2 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -441,7 +441,7 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint static const char *const empty = ""; if (argc == 0 || argv == 0) { argc = 0; - argv = (char **)∅ + argv = const_cast<char **>(&empty); } #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) if (!isArgvModified(argc, argv)) { diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 90ee7d8f95..7ae9fef622 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -1533,6 +1533,29 @@ bool QMetaObject::invokeMethod(QObject *obj, */ /*! + \fn QMetaObject::Connection::Connection(const Connection &other) + + Constructs a copy of \a other. +*/ + +/*! + \fn QMetaObject::Connection::Connection &operator=(const Connection &other) + + Assigns \a other to this connection and returns a reference to this connection. +*/ + +/*! + \fn QMetaObject::Connection &QMetaObject::Connection::operator=(Connection &&other) + + Move-assigns \a other to this object. +*/ +/*! + \fn QMetaObject::Connection::Connection(Connection &&o) + + Move-constructs a Connection instance, making it point to the same object that \a o was pointing to. +*/ + +/*! \class QMetaMethod \inmodule QtCore diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 641053371d..3906cdc036 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -421,6 +421,16 @@ struct DefinedTypesFilter { */ /*! + \fn void *QMetaType::construct(int type, const void *copy) + \deprecated + + Constructs a value of the given type which is a copy of \a copy. + The default value for \a copy is 0. + + Deprecated, use the static function QMetaType::create(int type, + const void *copy) instead. +*/ +/*! \fn void *QMetaType::construct(void *where, const void *copy = 0) const \since 5.0 @@ -1834,7 +1844,8 @@ public: void delegate(const T *where) { DestructorImpl<T>::Destruct(m_type, const_cast<T*>(where)); } void delegate(const void *) {} void delegate(const QMetaTypeSwitcher::UnknownType*) {} - void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestructor(m_type, (void*)where); } + void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) + { customTypeDestructor(m_type, const_cast<void *>(static_cast<const void *>(where))); } private: static void customTypeDestructor(const int type, void *where) diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index e6ea27ef58..4d4cccd7b1 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -4103,7 +4103,7 @@ QDebug operator<<(QDebug dbg, const QObject *o) QDebugStateSaver saver(dbg); if (!o) return dbg << "QObject(0x0)"; - dbg.nospace() << o->metaObject()->className() << '(' << (void *)o; + dbg.nospace() << o->metaObject()->className() << '(' << (const void *)o; if (!o->objectName().isEmpty()) dbg << ", name = " << o->objectName(); dbg << ')'; @@ -4908,8 +4908,15 @@ QMetaObject::Connection& QMetaObject::Connection::operator=(const QMetaObject::C return *this; } +/*! + Creates a Connection instance. +*/ + QMetaObject::Connection::Connection() : d_ptr(0) {} +/*! + Destructor for QMetaObject::Connection. +*/ QMetaObject::Connection::~Connection() { if (d_ptr) diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp index ef74b4bdd1..794a4aaa0c 100644 --- a/src/corelib/kernel/qtranslator.cpp +++ b/src/corelib/kernel/qtranslator.cpp @@ -722,7 +722,7 @@ static QString find_translation(const QLocale & locale, For example, an application running in the \a locale with the following \l{QLocale::uiLanguages()}{ui languages} - "es", "fr-CA", "de" might call - load(QLocale::system(), "foo", ".", "/opt/foolib", ".qm"). load() would + load(QLocale(), "foo", ".", "/opt/foolib", ".qm"). load() would replace '-' (dash) with '_' (underscore) in the ui language and then try to open the first existing readable file from this list: diff --git a/src/corelib/plugin/qlibrary_p.h b/src/corelib/plugin/qlibrary_p.h index 3965176ef7..ada90d7bfd 100644 --- a/src/corelib/plugin/qlibrary_p.h +++ b/src/corelib/plugin/qlibrary_p.h @@ -108,7 +108,7 @@ public: raw += strlen("QTMETADATA "); // the size of the embedded JSON object can be found 8 bytes into the data (see qjson_p.h), // but doesn't include the size of the header (8 bytes) - QByteArray json(raw, qFromLittleEndian<uint>(*(uint *)(raw + 8)) + 8); + QByteArray json(raw, qFromLittleEndian<uint>(*(const uint *)(raw + 8)) + 8); return QJsonDocument::fromBinaryData(json); } diff --git a/src/corelib/plugin/qplugin.h b/src/corelib/plugin/qplugin.h index 4b5cafaa06..efab6523ac 100644 --- a/src/corelib/plugin/qplugin.h +++ b/src/corelib/plugin/qplugin.h @@ -112,7 +112,7 @@ void Q_CORE_EXPORT qRegisterStaticPluginFunction(QStaticPlugin staticPlugin); # define QT_MOC_EXPORT_PLUGIN(PLUGINCLASS, PLUGINCLASSNAME) \ static QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance_##PLUGINCLASSNAME() \ Q_PLUGIN_INSTANCE(PLUGINCLASS) \ - static const char *qt_plugin_query_metadata_##PLUGINCLASSNAME() { return (const char *)qt_pluginMetaData; } \ + static const char *qt_plugin_query_metadata_##PLUGINCLASSNAME() { return reinterpret_cast<const char *>(qt_pluginMetaData); } \ const QT_PREPEND_NAMESPACE(QStaticPlugin) qt_static_plugin_##PLUGINCLASSNAME() { \ QT_PREPEND_NAMESPACE(QStaticPlugin) plugin = { qt_plugin_instance_##PLUGINCLASSNAME, qt_plugin_query_metadata_##PLUGINCLASSNAME}; \ return plugin; \ @@ -123,7 +123,7 @@ void Q_CORE_EXPORT qRegisterStaticPluginFunction(QStaticPlugin staticPlugin); # define QT_MOC_EXPORT_PLUGIN(PLUGINCLASS, PLUGINCLASSNAME) \ Q_EXTERN_C Q_DECL_EXPORT \ const char *qt_plugin_query_metadata() \ - { return (const char *)qt_pluginMetaData; } \ + { return reinterpret_cast<const char *>(qt_pluginMetaData); } \ Q_EXTERN_C Q_DECL_EXPORT QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance() \ Q_PLUGIN_INSTANCE(PLUGINCLASS) diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index 72f662dc1e..812e2c9fb6 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -543,7 +543,7 @@ QUuid QUuid::fromRfc4122(const QByteArray &bytes) QString QUuid::toString() const { QString result(38, Qt::Uninitialized); - ushort *data = (ushort *)result.unicode(); + ushort *data = (ushort *)result.data(); _q_uuidToHex(data, data1, data2, data3, data4); diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp index e6477bf5e0..0ea8c4c00f 100644 --- a/src/corelib/thread/qreadwritelock.cpp +++ b/src/corelib/thread/qreadwritelock.cpp @@ -136,11 +136,27 @@ void QReadWriteLock::lockForRead() { QMutexLocker lock(&d->mutex); + Qt::HANDLE self = 0; + if (d->recursive) { + self = QThread::currentThreadId(); + + QHash<Qt::HANDLE, int>::iterator it = d->currentReaders.find(self); + if (it != d->currentReaders.end()) { + ++it.value(); + ++d->accessCount; + Q_ASSERT_X(d->accessCount > 0, "QReadWriteLock::lockForRead()", + "Overflow in lock counter"); + return; + } + } + while (d->accessCount < 0 || d->waitingWriters) { ++d->waitingReaders; d->readerWait.wait(&d->mutex); --d->waitingReaders; } + if (d->recursive) + d->currentReaders.insert(self, 1); ++d->accessCount; Q_ASSERT_X(d->accessCount > 0, "QReadWriteLock::lockForRead()", "Overflow in lock counter"); @@ -166,8 +182,24 @@ bool QReadWriteLock::tryLockForRead() { QMutexLocker lock(&d->mutex); + Qt::HANDLE self = 0; + if (d->recursive) { + self = QThread::currentThreadId(); + + QHash<Qt::HANDLE, int>::iterator it = d->currentReaders.find(self); + if (it != d->currentReaders.end()) { + ++it.value(); + ++d->accessCount; + Q_ASSERT_X(d->accessCount > 0, "QReadWriteLock::tryLockForRead()", + "Overflow in lock counter"); + return true; + } + } + if (d->accessCount < 0) return false; + if (d->recursive) + d->currentReaders.insert(self, 1); ++d->accessCount; Q_ASSERT_X(d->accessCount > 0, "QReadWriteLock::tryLockForRead()", "Overflow in lock counter"); @@ -198,6 +230,20 @@ bool QReadWriteLock::tryLockForRead(int timeout) { QMutexLocker lock(&d->mutex); + Qt::HANDLE self = 0; + if (d->recursive) { + self = QThread::currentThreadId(); + + QHash<Qt::HANDLE, int>::iterator it = d->currentReaders.find(self); + if (it != d->currentReaders.end()) { + ++it.value(); + ++d->accessCount; + Q_ASSERT_X(d->accessCount > 0, "QReadWriteLock::tryLockForRead()", + "Overflow in lock counter"); + return true; + } + } + while (d->accessCount < 0 || d->waitingWriters) { ++d->waitingReaders; bool success = d->readerWait.wait(&d->mutex, timeout < 0 ? ULONG_MAX : ulong(timeout)); @@ -205,6 +251,8 @@ bool QReadWriteLock::tryLockForRead(int timeout) if (!success) return false; } + if (d->recursive) + d->currentReaders.insert(self, 1); ++d->accessCount; Q_ASSERT_X(d->accessCount > 0, "QReadWriteLock::tryLockForRead()", "Overflow in lock counter"); @@ -364,6 +412,15 @@ void QReadWriteLock::unlock() bool unlocked = false; if (d->accessCount > 0) { // releasing a read lock + if (d->recursive) { + Qt::HANDLE self = QThread::currentThreadId(); + QHash<Qt::HANDLE, int>::iterator it = d->currentReaders.find(self); + if (it != d->currentReaders.end()) { + if (--it.value() <= 0) + d->currentReaders.erase(it); + } + } + unlocked = --d->accessCount == 0; } else if (d->accessCount < 0 && ++d->accessCount == 0) { // released a write lock diff --git a/src/corelib/thread/qreadwritelock_p.h b/src/corelib/thread/qreadwritelock_p.h index 15a6d1f57e..e57c0e403f 100644 --- a/src/corelib/thread/qreadwritelock_p.h +++ b/src/corelib/thread/qreadwritelock_p.h @@ -69,6 +69,7 @@ struct QReadWriteLockPrivate bool recursive; Qt::HANDLE currentWriter; + QHash<Qt::HANDLE, int> currentReaders; }; QT_END_NAMESPACE diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 0434cebc15..447e84b3d4 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -511,7 +511,7 @@ QByteArray qCompress(const uchar* data, int nbytes, int compressionLevel) int res; do { bazip.resize(len + 4); - res = ::compress2((uchar*)bazip.data()+4, &len, (uchar*)data, nbytes, compressionLevel); + res = ::compress2((uchar*)bazip.data()+4, &len, data, nbytes, compressionLevel); switch (res) { case Z_OK: @@ -602,7 +602,7 @@ QByteArray qUncompress(const uchar* data, int nbytes) d->size = 0; // Shut up valgrind "uninitialized variable" warning int res = ::uncompress((uchar*)d->data(), &len, - (uchar*)data+4, nbytes-4); + data+4, nbytes-4); switch (res) { case Z_OK: @@ -2186,9 +2186,9 @@ QByteArray &QByteArray::replace(const char *before, int bsize, const char *after } if (a != after) - ::free((char *)a); + ::free(const_cast<char *>(a)); if (b != before) - ::free((char *)b); + ::free(const_cast<char *>(b)); return *this; diff --git a/src/corelib/tools/qcollator.cpp b/src/corelib/tools/qcollator.cpp index 615b7a4e3e..59f8f66869 100644 --- a/src/corelib/tools/qcollator.cpp +++ b/src/corelib/tools/qcollator.cpp @@ -87,7 +87,7 @@ QCollator::QCollator(const QCollator &other) } /*! - Destructor for QCollator. + Destroys the collator. */ QCollator::~QCollator() { diff --git a/src/corelib/tools/qpair.qdoc b/src/corelib/tools/qpair.qdoc index 2a421a1bbf..7cba7480f0 100644 --- a/src/corelib/tools/qpair.qdoc +++ b/src/corelib/tools/qpair.qdoc @@ -109,7 +109,7 @@ \endcode Swap overloads are found in namespace \c std as well as via - argument-dependent lookup (ADL) in \c{T}'s namespace. + argument-dependent lookup (ADL) in the namespace of \c{T} . */ /*! @@ -136,8 +136,7 @@ \fn QPair::QPair(QPair<TT1, TT2> &&p) \since 5.2 - Move-constructs a QPair instance, making it point to the same object that - \a p was pointing to. + Move-constructs a QPair instance, making it point to the same object that \a p was pointing to. */ /*! diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp index d572dd209c..e7917ffdac 100644 --- a/src/corelib/tools/qsimd.cpp +++ b/src/corelib/tools/qsimd.cpp @@ -36,6 +36,10 @@ #include <QByteArray> #include <stdio.h> +#ifdef Q_OS_LINUX +# include "../testlib/3rdparty/valgrind_p.h" +#endif + #if defined(Q_OS_WIN) # if defined(Q_OS_WINCE) # include <qt_windows.h> @@ -256,8 +260,12 @@ static inline uint detectProcessorFeatures() uint features = 0; int cpuidLevel = maxBasicCpuidSupported(); +#if Q_PROCESSOR_X86 < 5 if (cpuidLevel < 1) return 0; +#else + Q_ASSERT(cpuidLevel >= 1); +#endif uint cpuid01ECX = 0, cpuid01EDX = 0; cpuidFeatures01(cpuid01ECX, cpuid01EDX); @@ -497,8 +505,7 @@ static const int features_indices[] = { static const int features_count = (sizeof features_indices - 1) / (sizeof features_indices[0]); // record what CPU features were enabled by default in this Qt build -// don't define for HLE, since the HLE prefix can be run on older CPUs -static const uint minFeature = qCompilerCpuFeatures & ~HLE; +static const uint minFeature = qCompilerCpuFeatures; #ifdef Q_OS_WIN #if defined(Q_CC_GNU) @@ -554,7 +561,12 @@ void qDetectCpuFeatures() } } - if (minFeature != 0 && (f & minFeature) != minFeature) { +#ifdef RUNNING_ON_VALGRIND + bool runningOnValgrind = RUNNING_ON_VALGRIND; +#else + bool runningOnValgrind = false; +#endif + if (!runningOnValgrind && (minFeature != 0 && (f & minFeature) != minFeature)) { uint missing = minFeature & ~f; fprintf(stderr, "Incompatible processor. This Qt build requires the following features:\n "); for (int i = 0; i < features_count; ++i) { diff --git a/src/corelib/tools/qsimd_p.h b/src/corelib/tools/qsimd_p.h index 1f5e743b7f..dd93b4fd26 100644 --- a/src/corelib/tools/qsimd_p.h +++ b/src/corelib/tools/qsimd_p.h @@ -265,9 +265,6 @@ static const uint qCompilerCpuFeatures = 0 #if defined __RTM__ | RTM #endif -#if defined __HLE__ - | HLE -#endif #if defined __AVX2__ | AVX2 #endif diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 345114d907..8bb8953dde 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -215,7 +215,7 @@ void qt_from_latin1(ushort *dst, const char *str, size_t size) // we're going to read str[offset..offset+15] (16 bytes) for ( ; str + offset + 15 < e; offset += 16) { - const __m128i chunk = _mm_loadu_si128((__m128i*)(str + offset)); // load + const __m128i chunk = _mm_loadu_si128((const __m128i*)(str + offset)); // load #ifdef __AVX2__ // zero extend to an YMM register const __m256i extended = _mm256_cvtepu8_epi16(chunk); @@ -316,10 +316,10 @@ static void qt_to_latin1(uchar *dst, const ushort *src, int length) // we're going to write to dst[offset..offset+15] (16 bytes) for ( ; dst + offset + 15 < e; offset += 16) { - __m128i chunk1 = _mm_loadu_si128((__m128i*)(src + offset)); // load + __m128i chunk1 = _mm_loadu_si128((const __m128i*)(src + offset)); // load chunk1 = mergeQuestionMarks(chunk1); - __m128i chunk2 = _mm_loadu_si128((__m128i*)(src + offset + 8)); // load + __m128i chunk2 = _mm_loadu_si128((const __m128i*)(src + offset + 8)); // load chunk2 = mergeQuestionMarks(chunk2); // pack the two vector to 16 x 8bits elements @@ -458,8 +458,8 @@ static int ucstrncmp(const QChar *a, const QChar *b, int l) // we're going to read ptr[0..15] (16 bytes) for ( ; ptr + 15 < reinterpret_cast<const char *>(a); ptr += 16) { - __m128i a_data = _mm_loadu_si128((__m128i*)ptr); - __m128i b_data = _mm_loadu_si128((__m128i*)(ptr + distance)); + __m128i a_data = _mm_loadu_si128((const __m128i*)ptr); + __m128i b_data = _mm_loadu_si128((const __m128i*)(ptr + distance)); __m128i result = _mm_cmpeq_epi16(a_data, b_data); uint mask = ~_mm_movemask_epi8(result); if (ushort(mask)) { @@ -541,14 +541,14 @@ static int ucstrncmp(const QChar *a, const uchar *c, int l) for ( ; uc + offset + 15 < e; offset += 16) { // similar to fromLatin1_helper: // load 16 bytes of Latin 1 data - __m128i chunk = _mm_loadu_si128((__m128i*)(c + offset)); + __m128i chunk = _mm_loadu_si128((const __m128i*)(c + offset)); # ifdef __AVX2__ // expand Latin 1 data via zero extension __m256i ldata = _mm256_cvtepu8_epi16(chunk); // load UTF-16 data and compare - __m256i ucdata = _mm256_loadu_si256((__m256i*)(uc + offset)); + __m256i ucdata = _mm256_loadu_si256((const __m256i*)(uc + offset)); __m256i result = _mm256_cmpeq_epi16(ldata, ucdata); uint mask = ~_mm256_movemask_epi8(result); @@ -558,8 +558,8 @@ static int ucstrncmp(const QChar *a, const uchar *c, int l) __m128i secondHalf = _mm_unpackhi_epi8(chunk, nullmask); // load UTF-16 data and compare - __m128i ucdata1 = _mm_loadu_si128((__m128i*)(uc + offset)); - __m128i ucdata2 = _mm_loadu_si128((__m128i*)(uc + offset + 8)); + __m128i ucdata1 = _mm_loadu_si128((const __m128i*)(uc + offset)); + __m128i ucdata2 = _mm_loadu_si128((const __m128i*)(uc + offset + 8)); __m128i result1 = _mm_cmpeq_epi16(firstHalf, ucdata1); __m128i result2 = _mm_cmpeq_epi16(secondHalf, ucdata2); @@ -577,10 +577,10 @@ static int ucstrncmp(const QChar *a, const uchar *c, int l) // we'll read uc[offset..offset+7] (16 bytes) and c[offset..offset+7] (8 bytes) if (uc + offset + 7 < e) { // same, but we're using an 8-byte load - __m128i chunk = _mm_cvtsi64_si128(*(long long *)(c + offset)); + __m128i chunk = _mm_cvtsi64_si128(*(const long long *)(c + offset)); __m128i secondHalf = _mm_unpacklo_epi8(chunk, nullmask); - __m128i ucdata = _mm_loadu_si128((__m128i*)(uc + offset)); + __m128i ucdata = _mm_loadu_si128((const __m128i*)(uc + offset)); __m128i result = _mm_cmpeq_epi16(secondHalf, ucdata); uint mask = ~_mm_movemask_epi8(result); if (ushort(mask)) { @@ -672,7 +672,7 @@ static int findChar(const QChar *str, int len, QChar ch, int from, // we're going to read n[0..7] (16 bytes) for (const ushort *next = n + 8; next <= e; n = next, next += 8) { - __m128i data = _mm_loadu_si128((__m128i*)n); + __m128i data = _mm_loadu_si128((const __m128i*)n); __m128i result = _mm_cmpeq_epi16(data, mch); uint mask = _mm_movemask_epi8(result); if (ushort(mask)) { @@ -2744,7 +2744,7 @@ bool operator<(const QString &s1, const QString &s2) */ bool QString::operator<(QLatin1String other) const { - const uchar *c = (uchar *) other.latin1(); + const uchar *c = (const uchar *) other.latin1(); if (!c || *c == 0) return false; @@ -2849,7 +2849,7 @@ bool QString::operator<(QLatin1String other) const */ bool QString::operator>(QLatin1String other) const { - const uchar *c = (uchar *) other.latin1(); + const uchar *c = (const uchar *) other.latin1(); if (!c || *c == '\0') return !isEmpty(); @@ -5392,7 +5392,7 @@ int QString::compare_helper(const QChar *data1, int length1, QLatin1String s2, { const ushort *uc = reinterpret_cast<const ushort *>(data1); const ushort *uce = uc + length1; - const uchar *c = (uchar *)s2.latin1(); + const uchar *c = (const uchar *)s2.latin1(); if (!c) return length1; diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp index 7c5e5bd2cf..90ce8e3b68 100644 --- a/src/corelib/tools/qtimezoneprivate_tz.cpp +++ b/src/corelib/tools/qtimezoneprivate_tz.cpp @@ -389,12 +389,19 @@ static int parsePosixOffset(const QByteArray &timeRule) // Format "[+|-]hh[:mm[:ss]]" QList<QByteArray> parts = timeRule.split(':'); int count = parts.count(); - if (count == 3) - return (parts.at(0).toInt() * -60 * 60) + (parts.at(1).toInt() * 60) + parts.at(2).toInt(); - else if (count == 2) - return (parts.at(0).toInt() * -60 * 60) + (parts.at(1).toInt() * 60); - else if (count == 1) - return (parts.at(0).toInt() * -60 * 60); + if (count == 3) { + int hour = parts.at(0).toInt(); + int sign = hour >= 0 ? -1 : 1; + return sign * ((qAbs(hour) * 60 * 60) + (parts.at(1).toInt() * 60) + parts.at(2).toInt()); + } else if (count == 2) { + int hour = parts.at(0).toInt(); + int sign = hour >= 0 ? -1 : 1; + return sign * ((qAbs(hour) * 60 * 60) + (parts.at(1).toInt() * 60)); + } else if (count == 1) { + int hour = parts.at(0).toInt(); + int sign = hour >= 0 ? -1 : 1; + return sign * (qAbs(hour) * 60 * 60); + } return 0; } diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp index bbd751efd0..13c84db9ae 100644 --- a/src/corelib/xml/qxmlstream.cpp +++ b/src/corelib/xml/qxmlstream.cpp @@ -2396,6 +2396,12 @@ QXmlStreamAttribute& QXmlStreamAttribute::operator=(const QXmlStreamAttribute &o */ /*! + \fn QXmlStreamAttributes::QXmlStreamAttributes() + + A constructor for QXmlStreamAttributes. +*/ + +/*! \typedef QXmlStreamNotationDeclarations \relates QXmlStreamNotationDeclaration |