diff options
author | David Faure <david.faure@kdab.com> | 2012-02-06 14:31:41 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-08 01:52:00 +0100 |
commit | f41135a9f83d17b319ad050dfacc7a8e88598151 (patch) | |
tree | 19c825c7e0aff03157ed07164bf9811653d1fa91 /src/corelib | |
parent | 2e220e4603d6a0c21efee3a884be76e9f2d7ebb7 (diff) | |
download | qt4-tools-f41135a9f83d17b319ad050dfacc7a8e88598151.tar.gz |
Make QString::latin1() re-entrant, the global QHash needs a mutex.
*Different* instances of QString used in different threads would often
lead to crashes due to the global QHash used by latin1() and ascii().
Basic autotest for latin1() added.
Change-Id: If4fd450deb28f41b1d71f377cacb8815ddeffbee
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qstring.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index bb13ee94b8..06e45089a8 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -57,6 +57,7 @@ #include "qhash.h" #include "qdebug.h" #include "qendian.h" +#include "qmutex.h" #ifdef Q_OS_MAC #include <private/qcore_mac_p.h> @@ -104,6 +105,8 @@ QTextCodec *QString::codecForCStrings; #ifdef QT3_SUPPORT static QHash<void *, QByteArray> *asciiCache = 0; +Q_GLOBAL_STATIC(QMutex, asciiCacheMutex) + #endif #ifdef QT_USE_ICU @@ -111,7 +114,6 @@ static QHash<void *, QByteArray> *asciiCache = 0; extern bool qt_ucol_strcoll(const QChar *source, int sourceLength, const QChar *target, int targetLength, int *result); #endif - // internal int qFindString(const QChar *haystack, int haystackLen, int from, const QChar *needle, int needleLen, Qt::CaseSensitivity cs); @@ -1225,6 +1227,7 @@ void QString::free(Data *d) { #ifdef QT3_SUPPORT if (d->asciiCache) { + QMutexLocker locker(asciiCacheMutex()); Q_ASSERT(asciiCache); asciiCache->remove(d); } @@ -1359,6 +1362,7 @@ void QString::realloc(int alloc) } else { #ifdef QT3_SUPPORT if (d->asciiCache) { + QMutexLocker locker(asciiCacheMutex()); Q_ASSERT(asciiCache); asciiCache->remove(d); } @@ -3905,6 +3909,7 @@ QString QString::fromLatin1(const char *str, int size) */ const char *QString::ascii_helper() const { + QMutexLocker locker(asciiCacheMutex()); if (!asciiCache) asciiCache = new QHash<void *, QByteArray>(); @@ -3922,6 +3927,7 @@ const char *QString::ascii_helper() const */ const char *QString::latin1_helper() const { + QMutexLocker locker(asciiCacheMutex()); if (!asciiCache) asciiCache = new QHash<void *, QByteArray>(); @@ -7239,6 +7245,7 @@ QString &QString::setRawData(const QChar *unicode, int size) } else { #ifdef QT3_SUPPORT if (d->asciiCache) { + QMutexLocker locker(asciiCacheMutex()); Q_ASSERT(asciiCache); asciiCache->remove(d); } |