diff options
author | Liang Qi <liang.qi@qt.io> | 2017-06-07 12:05:33 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-06-07 14:02:43 +0200 |
commit | 7cbee5629604aa49c618829c8e3e55fc64e94df7 (patch) | |
tree | d12041105160c1cb21226b365edb9653d87b5853 /src/corelib | |
parent | e400b7e326c554ccd819448866265953d2a0f24d (diff) | |
parent | 5f0ce2333f7e11a3ffb5d16a27cd9303efa712d5 (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts:
src/widgets/widgets/qmenu.cpp
Change-Id: I6d3baf56eb24501cddb129a3cb6b958ccc25a308
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/global/qcompilerdetection.h | 5 | ||||
-rw-r--r-- | src/corelib/global/qglobal.cpp | 41 | ||||
-rw-r--r-- | src/corelib/global/qglobal.h | 7 | ||||
-rw-r--r-- | src/corelib/global/qprocessordetection.h | 9 | ||||
-rw-r--r-- | src/corelib/io/qstorageinfo_unix.cpp | 6 | ||||
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.cpp | 2 | ||||
-rw-r--r-- | src/corelib/kernel/qobject_p.h | 1 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qarraydataops.h | 6 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 22 | ||||
-rw-r--r-- | src/corelib/tools/qstring.cpp | 55 |
11 files changed, 111 insertions, 45 deletions
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 173ada89de..c221115e8f 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -1246,6 +1246,11 @@ #else # define QT_HAS_INCLUDE_NEXT(x) 0 #endif +#ifdef __has_feature +# define QT_HAS_FEATURE(x) __has_feature(x) +#else +# define QT_HAS_FEATURE(x) 0 +#endif /* * Warning/diagnostic handling diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index ea9d207177..c2c9ea4e67 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -86,6 +86,12 @@ # include <sys/systeminfo.h> #endif +#if defined(Q_OS_DARWIN) +# include <mach/machine.h> +# include <sys/sysctl.h> +# include <sys/types.h> +#endif + #ifdef Q_OS_UNIX #include <sys/utsname.h> #include <private/qcore_unix_p.h> @@ -2484,6 +2490,20 @@ QString QSysInfo::currentCpuArchitecture() case PROCESSOR_ARCHITECTURE_IA64: return QStringLiteral("ia64"); } +#elif defined(Q_OS_DARWIN) + cpu_type_t type; + size_t size = sizeof(type); + sysctlbyname("hw.cputype", &type, &size, NULL, 0); + switch (type) { + case CPU_TYPE_X86: + return QStringLiteral("i386"); + case CPU_TYPE_X86_64: + return QStringLiteral("x86_64"); + case CPU_TYPE_ARM: + return QStringLiteral("arm"); + case CPU_TYPE_ARM64: + return QStringLiteral("arm64"); + } #elif defined(Q_OS_UNIX) long ret = -1; struct utsname u; @@ -3306,20 +3326,26 @@ bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT Equivalent to \code - qgetenv(varName).toInt() + qgetenv(varName).toInt(ok, 0) \endcode except that it's much faster, and can't throw exceptions. + \note there's a limit on the length of the value, which is sufficient for + all valid values of int, not counting leading zeroes or spaces. Values that + are too long will either be truncated or this function will set \a ok to \c + false. + \sa qgetenv(), qEnvironmentVariableIsSet() */ int qEnvironmentVariableIntValue(const char *varName, bool *ok) Q_DECL_NOEXCEPT { - QMutexLocker locker(&environmentMutex); -#if defined(_MSC_VER) && _MSC_VER >= 1400 - // we provide a buffer that can hold any int value: static const int NumBinaryDigitsPerOctalDigit = 3; static const int MaxDigitsForOctalInt = (std::numeric_limits<uint>::digits + NumBinaryDigitsPerOctalDigit - 1) / NumBinaryDigitsPerOctalDigit; + + QMutexLocker locker(&environmentMutex); +#if defined(_MSC_VER) && _MSC_VER >= 1400 + // we provide a buffer that can hold any int value: char buffer[MaxDigitsForOctalInt + 2]; // +1 for NUL +1 for optional '-' size_t dummy; if (getenv_s(&dummy, buffer, sizeof buffer, varName) != 0) { @@ -3329,15 +3355,16 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) Q_DECL_NOEXCEPT } #else const char * const buffer = ::getenv(varName); - if (!buffer || !*buffer) { + if (!buffer || strlen(buffer) > MaxDigitsForOctalInt + 2) { if (ok) *ok = false; return 0; } #endif bool ok_ = true; - const qlonglong value = qstrtoll(buffer, Q_NULLPTR, 0, &ok_); - if (int(value) != value) { // this is the check in QByteArray::toInt(), keep it in sync + const char *endptr; + const qlonglong value = qstrtoll(buffer, &endptr, 0, &ok_); + if (int(value) != value || *endptr != '\0') { // this is the check in QByteArray::toInt(), keep it in sync if (ok) *ok = false; return 0; diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index cfc6ef8b16..0628b524fb 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -647,7 +647,12 @@ inline void qt_noop(void) {} */ #if !defined(QT_NO_EXCEPTIONS) -# if defined(QT_BOOTSTRAPPED) || (defined(Q_CC_GNU) && !defined (__EXCEPTIONS) && !defined(Q_MOC_RUN)) +# if !defined(Q_MOC_RUN) +# if (defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !QT_HAS_FEATURE(cxx_exceptions)) || \ + (defined(Q_CC_GNU) && !defined(__EXCEPTIONS)) +# define QT_NO_EXCEPTIONS +# endif +# elif defined(QT_BOOTSTRAPPED) # define QT_NO_EXCEPTIONS # endif #endif diff --git a/src/corelib/global/qprocessordetection.h b/src/corelib/global/qprocessordetection.h index ed11e013f2..0b260d01e3 100644 --- a/src/corelib/global/qprocessordetection.h +++ b/src/corelib/global/qprocessordetection.h @@ -94,8 +94,8 @@ ARM is bi-endian, detect using __ARMEL__ or __ARMEB__, falling back to auto-detection implemented below. */ -#if defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM) || defined(__aarch64__) -# if defined(__aarch64__) +#if defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM) || defined(__aarch64__) || defined(__ARM64__) +# if defined(__aarch64__) || defined(__ARM64__) # define Q_PROCESSOR_ARM_64 # define Q_PROCESSOR_WORDSIZE 8 # else @@ -109,7 +109,8 @@ # define Q_PROCESSOR_ARM _M_ARM # elif defined(__ARM64_ARCH_8__) \ || defined(__aarch64__) \ - || defined(__CORE_CORTEXAV8__) // GHS-specific for INTEGRITY + || defined(__ARMv8__) \ + || defined(__ARMv8_A__) # define Q_PROCESSOR_ARM 8 # elif defined(__ARM_ARCH_7__) \ || defined(__ARM_ARCH_7A__) \ @@ -117,7 +118,7 @@ || defined(__ARM_ARCH_7M__) \ || defined(__ARM_ARCH_7S__) \ || defined(_ARM_ARCH_7) \ - || defined(__CORE_CORTEXA__) // GHS-specific for INTEGRITY + || defined(__CORE_CORTEXA__) # define Q_PROCESSOR_ARM 7 # elif defined(__ARM_ARCH_6__) \ || defined(__ARM_ARCH_6J__) \ diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp index b9c9883609..9072b34f54 100644 --- a/src/corelib/io/qstorageinfo_unix.cpp +++ b/src/corelib/io/qstorageinfo_unix.cpp @@ -195,8 +195,12 @@ static bool shouldIncludeFs(const QStorageIterator &it) #if defined(Q_OS_BSD4) +#ifndef MNT_NOWAIT +# define MNT_NOWAIT 0 +#endif + inline QStorageIterator::QStorageIterator() - : entryCount(::getmntinfo(&stat_buf, 0)), + : entryCount(::getmntinfo(&stat_buf, MNT_NOWAIT)), currentIndex(-1) { } diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index c0737ffb36..f893cf06e3 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -2044,7 +2044,7 @@ Qt::DropActions QAbstractItemModel::supportedDropActions() const Qt::DropActions QAbstractItemModel::supportedDragActions() const { Q_D(const QAbstractItemModel); - if (d->supportedDragActions != Qt::IgnoreAction) + if (int(d->supportedDragActions) != -1) return d->supportedDragActions; return supportedDropActions(); } diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index 0a5d003b05..ad88bcf274 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -198,6 +198,7 @@ public: static QObjectPrivate *get(QObject *o) { return o->d_func(); } + static const QObjectPrivate *get(const QObject *o) { return o->d_func(); } int signalIndex(const char *signalName, const QMetaObject **meta = 0) const; inline bool isSignalConnected(uint signalIdx, bool checkDeclarative = true) const; diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index e636c6fe52..17c94e4e9d 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -2363,7 +2363,7 @@ QByteArray QVariant::toByteArray() const \fn QPoint QVariant::toPoint() const Returns the variant as a QPoint if the variant has userType() - \l QMetaType::QPointF or \l QMetaType::QPointF; otherwise returns a null + \l QMetaType::QPoint or \l QMetaType::QPointF; otherwise returns a null QPoint. \sa canConvert(), convert() diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index ae83e6986e..b7c3bc1287 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -49,6 +49,11 @@ QT_BEGIN_NAMESPACE namespace QtPrivate { +QT_WARNING_PUSH +#if defined(Q_CC_GNU) && Q_CC_GNU >= 700 +QT_WARNING_DISABLE_GCC("-Wstringop-overflow") +#endif + template <class T> struct QPodArrayOps : QTypedArrayData<T> @@ -131,6 +136,7 @@ struct QPodArrayOps this->size -= (e - b); } }; +QT_WARNING_POP template <class T> struct QGenericArrayOps diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index b5b48324e7..19c27d9ff8 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -4791,4 +4791,26 @@ QByteArray QByteArray::toPercentEncoding(const QByteArray &exclude, const QByteA \internal */ +/*! + \macro QByteArrayLiteral(ba) + \relates QByteArray + + The macro generates the data for a QByteArray out of the string literal + \a ba at compile time. Creating a QByteArray from it is free in this case, and + the generated byte array data is stored in the read-only segment of the + compiled object file. + + For instance: + + \code + QByteArray ba = QByteArrayLiteral("byte array contents"); + \endcode + + Using QByteArrayLiteral instead of a double quoted plain C++ string literal + can significantly speed up creation of QByteArray instances from data known + at compile time. + + \sa QStringLiteral +*/ + QT_END_NAMESPACE diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 907de3cb4b..3826d7531a 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -11576,52 +11576,47 @@ QString QString::toHtmlEscaped() const \macro QStringLiteral(str) \relates QString - The macro generates the data for a QString out of \a str at compile time if the compiler supports it. - Creating a QString from it is free in this case, and the generated string data is stored in - the read-only segment of the compiled object file. + The macro generates the data for a QString out of the string literal \a str + at compile time. Creating a QString from it is free in this case, and the + generated string data is stored in the read-only segment of the compiled + object file. - For compilers not supporting the creation of compile time strings, QStringLiteral will fall back to - QString::fromUtf8(). + If you have code that looks like this: - If you have code looking like: \code + // hasAttribute takes a QString argument if (node.hasAttribute("http-contents-length")) //... \endcode - One temporary QString will be created to be passed as the hasAttribute function parameter. - This can be quite expensive, as it involves a memory allocation and the copy and the conversion - of the data into QString's internal encoding. - This can be avoided by doing + then a temporary QString will be created to be passed as the \c{hasAttribute} + function parameter. This can be quite expensive, as it involves a memory + allocation and the copy/conversion of the data into QString's internal + encoding. + + This cost can be avoided by using QStringLiteral instead: + \code if (node.hasAttribute(QStringLiteral("http-contents-length"))) //... \endcode - Then the QString's internal data will be generated at compile time and no conversion or allocation - will occur at runtime - Using QStringLiteral instead of a double quoted ascii literal can significantly speed up creation - of QString's from data known at compile time. + In this case, QString's internal data will be generated at compile time; no + conversion or allocation will occur at runtime. + + Using QStringLiteral instead of a double quoted plain C++ string literal can + significantly speed up creation of QString instances from data known at + compile time. - If the compiler is C++11 enabled the string \a str can actually contain unicode data. + \note QLatin1String can still be more efficient than QStringLiteral + when the string is passed to a function that has an overload taking + QLatin1String and this overload avoids conversion to QString. For + instance, QString::operator==() can compare to a QLatin1String + directly: - \note There are still a few cases in which QLatin1String is more efficient than QStringLiteral: - If it is passed to a function that has an overload that takes the QLatin1String directly, without - conversion to QString. For instance, this is the case of QString::operator== \code if (attribute.name() == QLatin1String("http-contents-length")) //... \endcode - \note There are some restrictions when using the MSVC 2010 or 2012 compilers. The example snippets - provided here fail to compile with them. - \list - \li Concatenated string literals cannot be used with QStringLiteral. - \code - QString s = QStringLiteral("a" "b"); - \endcode - \li QStringLiteral cannot be used to initialize lists or arrays of QString. - \code - QString a[] = { QStringLiteral("a"), QStringLiteral("b") }; - \endcode - \endlist + \sa QByteArrayLiteral */ /*! |