From c3b62edd3b3b8a231f13818f5722ad948d6f962b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 5 Aug 2011 10:24:59 +0200 Subject: Re-introduce Q_GLOBAL_STATIC_INIT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing this macro in abff4d5090c1706c44485bbe3689a0e339c26a9b breaks code that used it in providing their own class-scope safe Q_GLOBAL_STATIC variations, the feature introduced in that commit. There may be other use cases for the macro. Anyway, even if this isn't part of the public API, there isn't a strong reason to remove the macro, so it is back now. Task-number: QTBUG-20627 Reviewed-by: Samuel Rødal --- src/corelib/global/qglobal.h | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 9c7f1c6..cfe5eea 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1924,50 +1924,51 @@ public: } }; +#define Q_GLOBAL_STATIC_INIT(TYPE, NAME) \ + static QGlobalStatic this_ ## NAME \ + = { Q_BASIC_ATOMIC_INITIALIZER(0), false } + #define Q_GLOBAL_STATIC(TYPE, NAME) \ static TYPE *NAME() \ { \ - static QGlobalStatic thisGlobalStatic \ - = { Q_BASIC_ATOMIC_INITIALIZER(0), false }; \ - if (!thisGlobalStatic.pointer && !thisGlobalStatic.destroyed) { \ + Q_GLOBAL_STATIC_INIT(TYPE, _StaticVar_); \ + if (!this__StaticVar_.pointer && !this__StaticVar_.destroyed) { \ TYPE *x = new TYPE; \ - if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) \ + if (!this__StaticVar_.pointer.testAndSetOrdered(0, x)) \ delete x; \ else \ - static QGlobalStaticDeleter cleanup(thisGlobalStatic); \ + static QGlobalStaticDeleter cleanup(this__StaticVar_); \ } \ - return thisGlobalStatic.pointer; \ + return this__StaticVar_.pointer; \ } #define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \ static TYPE *NAME() \ { \ - static QGlobalStatic thisGlobalStatic \ - = { Q_BASIC_ATOMIC_INITIALIZER(0), false }; \ - if (!thisGlobalStatic.pointer && !thisGlobalStatic.destroyed) { \ + Q_GLOBAL_STATIC_INIT(TYPE, _StaticVar_); \ + if (!this__StaticVar_.pointer && !this__StaticVar_.destroyed) { \ TYPE *x = new TYPE ARGS; \ - if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) \ + if (!this__StaticVar_.pointer.testAndSetOrdered(0, x)) \ delete x; \ else \ - static QGlobalStaticDeleter cleanup(thisGlobalStatic); \ + static QGlobalStaticDeleter cleanup(this__StaticVar_); \ } \ - return thisGlobalStatic.pointer; \ + return this__StaticVar_.pointer; \ } #define Q_GLOBAL_STATIC_WITH_INITIALIZER(TYPE, NAME, INITIALIZER) \ static TYPE *NAME() \ { \ - static QGlobalStatic thisGlobalStatic \ - = { Q_BASIC_ATOMIC_INITIALIZER(0), false }; \ - if (!thisGlobalStatic.pointer && !thisGlobalStatic.destroyed) { \ + Q_GLOBAL_STATIC_INIT(TYPE, _StaticVar_); \ + if (!this__StaticVar_.pointer && !this__StaticVar_.destroyed) { \ QScopedPointer x(new TYPE); \ INITIALIZER; \ - if (thisGlobalStatic.pointer.testAndSetOrdered(0, x.data())) { \ - static QGlobalStaticDeleter cleanup(thisGlobalStatic); \ + if (this__StaticVar_.pointer.testAndSetOrdered(0, x.data())) { \ + static QGlobalStaticDeleter cleanup(this__StaticVar_); \ x.take(); \ } \ } \ - return thisGlobalStatic.pointer; \ + return this__StaticVar_.pointer; \ } #endif -- cgit v0.12 From 50b84b716d3932e8c75c9fb4edac257c02d2c361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Wed, 10 Aug 2011 18:11:25 +0200 Subject: Fix warning when compiling with VS 2008 warning C4308: negative integral constant converted to unsigned type --- src/corelib/tools/qbytearray.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 767b713..a8edea4 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -541,7 +541,7 @@ QByteArray qUncompress(const uchar* data, int nbytes) forever { ulong alloc = len; - if (len >= (1 << 31) - sizeof(QByteArray::Data)) { + if (len >= ulong(1 << 31) - sizeof(QByteArray::Data)) { //QByteArray does not support that huge size anyway. qWarning("qUncompress: Input data is corrupted"); return QByteArray(); @@ -561,7 +561,7 @@ QByteArray qUncompress(const uchar* data, int nbytes) switch (res) { case Z_OK: if (len != alloc) { - if (len >= (1 << 31) - sizeof(QByteArray::Data)) { + if (len >= ulong(1 << 31) - sizeof(QByteArray::Data)) { //QByteArray does not support that huge size anyway. qWarning("qUncompress: Input data is corrupted"); return QByteArray(); -- cgit v0.12 From cb7cb1d3884ae8a032f3ad2ed3a6d8e3ffc06206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 5 Aug 2011 10:30:32 +0200 Subject: Modulus of negative dividends is undefined or negative ... depending on who you ask. Since it is possible for applicationPid to return negative values this means we would introduce garbage ['()*+,-./] in the generated filenames. Reviewed-by: Denis Dzyubenko --- src/corelib/io/qtemporaryfile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 0855d93..5bc07cb 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -118,7 +118,7 @@ static int createFileFromTemplate(char *const path, char *rIter = placeholderEnd; #if defined(QT_BUILD_CORE_LIB) - qint64 pid = QCoreApplication::applicationPid(); + quint64 pid = quint64(QCoreApplication::applicationPid()); do { *--rIter = (pid % 10) + '0'; pid /= 10; -- cgit v0.12 From 3596db6c9bb8db42476d0c7b52fa2043dc67135b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 5 Aug 2011 10:32:08 +0200 Subject: Changed if/if/else/if/eleven chain to switch Inlined isdigit in switch statement. Removed unused #includes. Documented unreachable segment with code (Q_ASSERT). Reviewed-by: Denis Dzyubenko --- src/corelib/io/qtemporaryfile.cpp | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 5bc07cb..9753332 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -53,10 +53,6 @@ # include #endif -#include -#include -#include - #if defined(Q_OS_UNIX) # include "private/qcore_unix_p.h" // overrides QT_OPEN #endif @@ -153,23 +149,34 @@ static int createFileFromTemplate(char *const path, for (char *iter = placeholderStart;;) { // Character progression: [0-9] => 'a' ... 'z' => 'A' .. 'Z' // String progression: "ZZaiC" => "aabiC" - if (*iter == 'Z') { - *iter++ = 'a'; - if (iter == placeholderEnd) - return -1; - } else { - if (isdigit(*iter)) + switch (*iter) { + case 'Z': + // Rollover, advance next character *iter = 'a'; - else if (*iter == 'z') /* inc from z to A */ + if (++iter == placeholderEnd) + return -1; + + continue; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + *iter = 'a'; + break; + + case 'z': + // increment 'z' to 'A' *iter = 'A'; - else { + break; + + default: ++*iter; - } - break; + break; } + break; } } - /*NOTREACHED*/ + + Q_ASSERT(false); } //************* QTemporaryFileEngine -- cgit v0.12 From 19880c1bdf75455b645fb8d5ee12bcb6e37e5aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 5 Aug 2011 10:32:25 +0200 Subject: Don't convert template's path separators again --- src/corelib/io/qtemporaryfile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 9753332..aae3eb6 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -330,7 +330,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode) return true; } - d->fileEntry = QFileSystemEntry(template_); + d->fileEntry = QFileSystemEntry(template_, QFileSystemEntry::FromInternalPath()); return false; #endif } -- cgit v0.12 From 023976f9dd48a3deb947905d32d5fc0692da7318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 5 Aug 2011 10:32:51 +0200 Subject: Use fromLocal8Bit for reversing toLocal8Bit path is converted to 8-bit encoding using toLocal8Bit in QTemporaryFileEngine::open. The reverse operation should be used here. --- src/corelib/io/qtemporaryfile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index aae3eb6..d457601 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -141,7 +141,7 @@ static int createFileFromTemplate(char *const path, return -1; } #else - if (!QFileInfo(QLatin1String(path)).exists()) + if (!QFileInfo(QString::fromLocal8Bit(path)).exists()) return 1; #endif -- cgit v0.12 From 773a6df46243831dee7559f90e33d7eff3c5c71e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 5 Aug 2011 10:40:46 +0200 Subject: Avoid spurious detaching in QDir::to/fromNativeSeparators The new code avoids non-const detaching operations until needed and uses a pointer into the "raw" QChar data from then on, thus skipping unneeded checks on the reference count for further detaching. These functions are used all the time by the file system classes so this small optimization won't hurt. In particular, it will help users who already use '/' when passing paths into Qt. Reviewed-by: Peter Hartmann --- src/corelib/io/qdir.cpp | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index b31cf69..f9196e0 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -802,14 +802,23 @@ QString QDir::convertSeparators(const QString &pathName) */ QString QDir::toNativeSeparators(const QString &pathName) { - QString n(pathName); #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN) - for (int i = 0; i < (int)n.length(); ++i) { - if (n[i] == QLatin1Char('/')) - n[i] = QLatin1Char('\\'); + int i = pathName.indexOf(QLatin1Char('/')); + if (i != -1) { + QString n(pathName); + + QChar * const data = n.data(); + data[i++] = QLatin1Char('\\'); + + for (; i < n.length(); ++i) { + if (data[i] == QLatin1Char('/')) + data[i] = QLatin1Char('\\'); + } + + return n; } #endif - return n; + return pathName; } /*! @@ -826,14 +835,23 @@ QString QDir::toNativeSeparators(const QString &pathName) */ QString QDir::fromNativeSeparators(const QString &pathName) { - QString n(pathName); #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN) - for (int i = 0; i < (int)n.length(); ++i) { - if (n[i] == QLatin1Char('\\')) - n[i] = QLatin1Char('/'); + int i = pathName.indexOf(QLatin1Char('\\')); + if (i != -1) { + QString n(pathName); + + QChar * const data = n.data(); + data[i++] = QLatin1Char('/'); + + for (; i < n.length(); ++i) { + if (data[i] == QLatin1Char('\\')) + data[i] = QLatin1Char('/'); + } + + return n; } #endif - return n; + return pathName; } /*! -- cgit v0.12