diff options
author | Liang Qi <liang.qi@qt.io> | 2017-06-19 13:25:11 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-06-19 16:12:34 +0200 |
commit | ce09ef431373f45d14ce0a6e7de24aee3666093d (patch) | |
tree | 7c998b21f02db55e233e7eeb1599663f1c6b51ca /src/corelib/io | |
parent | 7ad55ca65f42351e231f31f7a9253ae6eaf1ebb3 (diff) | |
parent | 97eec16e4ff6367c233f8ea6c4a343c286c3a514 (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts:
src/corelib/io/qprocess_unix.cpp
src/corelib/io/qprocess_win.cpp
src/plugins/platforms/android/qandroidplatformintegration.h
src/plugins/platforms/windows/qwindowscontext.cpp
src/plugins/platforms/windows/windows.pri
src/tools/uic/cpp/cppwriteinitialization.cpp
src/widgets/doc/src/widgets-and-layouts/gallery.qdoc
Change-Id: I8d0834c77f350ea7540140c2c7f372814afc2d0f
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qloggingcategory.cpp | 26 | ||||
-rw-r--r-- | src/corelib/io/qprocess.cpp | 36 | ||||
-rw-r--r-- | src/corelib/io/qprocess_darwin.mm | 2 | ||||
-rw-r--r-- | src/corelib/io/qprocess_p.h | 39 | ||||
-rw-r--r-- | src/corelib/io/qprocess_unix.cpp | 14 | ||||
-rw-r--r-- | src/corelib/io/qprocess_win.cpp | 14 |
6 files changed, 75 insertions, 56 deletions
diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp index 967a614a2d..69af936bca 100644 --- a/src/corelib/io/qloggingcategory.cpp +++ b/src/corelib/io/qloggingcategory.cpp @@ -63,6 +63,7 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift) \class QLoggingCategory \inmodule QtCore \since 5.2 + \threadsafe \brief The QLoggingCategory class represents a category, or 'area' in the logging infrastructure. @@ -95,6 +96,9 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift) \li Category names starting with \c{qt} are reserved for Qt modules. \endlist + QLoggingCategory objects implicitly defined by Q_LOGGING_CATEGORY() + are created on first use in a thread-safe manner. + \section1 Checking Category Configuration QLoggingCategory provides \l isDebugEnabled(), \l isInfoEnabled(), @@ -458,6 +462,8 @@ void QLoggingCategory::setFilterRules(const QString &rules) \note Arguments are not processed if debug output for the category is not enabled, so do not rely on any side effects. + \note Using the macro is thread-safe. + \sa qDebug() */ @@ -477,6 +483,8 @@ void QLoggingCategory::setFilterRules(const QString &rules) \note Arguments might not be processed if debug output for the category is not enabled, so do not rely on any side effects. + \note Using the macro is thread-safe. + \sa qDebug() */ @@ -499,6 +507,8 @@ void QLoggingCategory::setFilterRules(const QString &rules) \note Arguments are not processed if debug output for the category is not enabled, so do not rely on any side effects. + \note Using the macro is thread-safe. + \sa qInfo() */ @@ -518,6 +528,8 @@ void QLoggingCategory::setFilterRules(const QString &rules) \note Arguments might not be processed if debug output for the category is not enabled, so do not rely on any side effects. + \note Using the macro is thread-safe. + \sa qInfo() */ @@ -540,6 +552,8 @@ void QLoggingCategory::setFilterRules(const QString &rules) \note Arguments are not processed if warning output for the category is not enabled, so do not rely on any side effects. + \note Using the macro is thread-safe. + \sa qWarning() */ @@ -559,6 +573,8 @@ void QLoggingCategory::setFilterRules(const QString &rules) \note Arguments might not be processed if warning output for the category is not enabled, so do not rely on any side effects. + \note Using the macro is thread-safe. + \sa qWarning() */ @@ -581,6 +597,8 @@ void QLoggingCategory::setFilterRules(const QString &rules) \note Arguments are not processed if critical output for the category is not enabled, so do not rely on any side effects. + \note Using the macro is thread-safe. + \sa qCritical() */ @@ -600,6 +618,8 @@ void QLoggingCategory::setFilterRules(const QString &rules) \note Arguments might not be processed if critical output for the category is not enabled, so do not rely on any side effects. + \note Using the macro is thread-safe. + \sa qCritical() */ /*! @@ -624,7 +644,8 @@ void QLoggingCategory::setFilterRules(const QString &rules) \a string identifier. By default, all message types are enabled. Only one translation unit in a library or executable can define a category - with a specific name. + with a specific name. The implicitly defined QLoggingCategory object is + created on first use, in a thread-safe manner. This macro must be used outside of a class or method. */ @@ -640,7 +661,8 @@ void QLoggingCategory::setFilterRules(const QString &rules) and more severe are enabled, types with a lower severity are disabled. Only one translation unit in a library or executable can define a category - with a specific name. + with a specific name. The implicitly defined QLoggingCategory object is + created on first use, in a thread-safe manner. This macro must be used outside of a class or method. It is only defined if variadic macros are supported. diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index a3343423db..9da0fe59b5 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -154,8 +154,8 @@ QT_BEGIN_NAMESPACE QStringList QProcessEnvironmentPrivate::toList() const { QStringList result; - result.reserve(hash.size()); - for (Hash::const_iterator it = hash.cbegin(), end = hash.cend(); it != end; ++it) + result.reserve(vars.size()); + for (auto it = vars.cbegin(), end = vars.cend(); it != end; ++it) result << nameToString(it.key()) + QLatin1Char('=') + valueToString(it.value()); return result; } @@ -181,9 +181,9 @@ QProcessEnvironment QProcessEnvironmentPrivate::fromList(const QStringList &list QStringList QProcessEnvironmentPrivate::keys() const { QStringList result; - result.reserve(hash.size()); - Hash::ConstIterator it = hash.constBegin(), - end = hash.constEnd(); + result.reserve(vars.size()); + auto it = vars.constBegin(); + const auto end = vars.constEnd(); for ( ; it != end; ++it) result << nameToString(it.key()); return result; @@ -191,14 +191,14 @@ QStringList QProcessEnvironmentPrivate::keys() const void QProcessEnvironmentPrivate::insert(const QProcessEnvironmentPrivate &other) { - Hash::ConstIterator it = other.hash.constBegin(), - end = other.hash.constEnd(); + auto it = other.vars.constBegin(); + const auto end = other.vars.constEnd(); for ( ; it != end; ++it) - hash.insert(it.key(), it.value()); + vars.insert(it.key(), it.value()); #ifdef Q_OS_UNIX - QHash<QString, Key>::ConstIterator nit = other.nameMap.constBegin(), - nend = other.nameMap.constEnd(); + auto nit = other.nameMap.constBegin(); + const auto nend = other.nameMap.constEnd(); for ( ; nit != nend; ++nit) nameMap.insert(nit.key(), nit.value()); #endif @@ -271,7 +271,7 @@ bool QProcessEnvironment::operator==(const QProcessEnvironment &other) const if (d) { if (other.d) { QProcessEnvironmentPrivate::OrderedMutexLocker locker(d, other.d); - return d->hash == other.d->hash; + return d->vars == other.d->vars; } else { return isEmpty(); } @@ -289,7 +289,7 @@ bool QProcessEnvironment::operator==(const QProcessEnvironment &other) const bool QProcessEnvironment::isEmpty() const { // Needs no locking, as no hash nodes are accessed - return d ? d->hash.isEmpty() : true; + return d ? d->vars.isEmpty() : true; } /*! @@ -301,7 +301,7 @@ bool QProcessEnvironment::isEmpty() const void QProcessEnvironment::clear() { if (d) - d->hash.clear(); + d->vars.clear(); // Unix: Don't clear d->nameMap, as the environment is likely to be // re-populated with the same keys again. } @@ -318,7 +318,7 @@ bool QProcessEnvironment::contains(const QString &name) const if (!d) return false; QProcessEnvironmentPrivate::MutexLocker locker(d); - return d->hash.contains(d->prepareName(name)); + return d->vars.contains(d->prepareName(name)); } /*! @@ -337,7 +337,7 @@ void QProcessEnvironment::insert(const QString &name, const QString &value) { // our re-impl of detach() detaches from null d.detach(); // detach before prepareName() - d->hash.insert(d->prepareName(name), d->prepareValue(value)); + d->vars.insert(d->prepareName(name), d->prepareValue(value)); } /*! @@ -352,7 +352,7 @@ void QProcessEnvironment::remove(const QString &name) { if (d) { d.detach(); // detach before prepareName() - d->hash.remove(d->prepareName(name)); + d->vars.remove(d->prepareName(name)); } } @@ -369,8 +369,8 @@ QString QProcessEnvironment::value(const QString &name, const QString &defaultVa return defaultValue; QProcessEnvironmentPrivate::MutexLocker locker(d); - QProcessEnvironmentPrivate::Hash::ConstIterator it = d->hash.constFind(d->prepareName(name)); - if (it == d->hash.constEnd()) + const auto it = d->vars.constFind(d->prepareName(name)); + if (it == d->vars.constEnd()) return defaultValue; return d->valueToString(it.value()); diff --git a/src/corelib/io/qprocess_darwin.mm b/src/corelib/io/qprocess_darwin.mm index dd7a8275b9..2c3c296cb4 100644 --- a/src/corelib/io/qprocess_darwin.mm +++ b/src/corelib/io/qprocess_darwin.mm @@ -48,7 +48,7 @@ QProcessEnvironment QProcessEnvironment::systemEnvironment() __block QProcessEnvironment env; [[[NSProcessInfo processInfo] environment] enumerateKeysAndObjectsUsingBlock:^(NSString *name, NSString *value, BOOL *__unused stop) { - env.d->hash.insert( + env.d->vars.insert( QProcessEnvironmentPrivate::Key(QString::fromNSString(name).toLocal8Bit()), QProcessEnvironmentPrivate::Value(QString::fromNSString(value).toLocal8Bit())); }]; diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h index bea54f86da..deb29dca0a 100644 --- a/src/corelib/io/qprocess_p.h +++ b/src/corelib/io/qprocess_p.h @@ -55,6 +55,7 @@ #include "QtCore/qprocess.h" #include "QtCore/qstringlist.h" #include "QtCore/qhash.h" +#include "QtCore/qmap.h" #include "QtCore/qshareddata.h" #include "private/qiodevice_p.h" @@ -90,22 +91,19 @@ public: QProcEnvKey(const QProcEnvKey &other) : QString(other) {} bool operator==(const QProcEnvKey &other) const { return !compare(other, Qt::CaseInsensitive); } }; -inline uint qHash(const QProcEnvKey &key) { return qHash(key.toCaseFolded()); } -typedef QString QProcEnvValue; -#else -class QProcEnvKey +inline bool operator<(const QProcEnvKey &a, const QProcEnvKey &b) { -public: - QProcEnvKey() : hash(0) {} - explicit QProcEnvKey(const QByteArray &other) : key(other), hash(qHash(key)) {} - QProcEnvKey(const QProcEnvKey &other) { *this = other; } - bool operator==(const QProcEnvKey &other) const { return key == other.key; } + // On windows use case-insensitive ordering because that is how Windows needs the environment + // block sorted (https://msdn.microsoft.com/en-us/library/windows/desktop/ms682009(v=vs.85).aspx) + return a.compare(b, Qt::CaseInsensitive) < 0; +} - QByteArray key; - uint hash; -}; -inline uint qHash(const QProcEnvKey &key) Q_DECL_NOTHROW { return key.hash; } +Q_DECLARE_TYPEINFO(QProcEnvKey, Q_MOVABLE_TYPE); + +typedef QString QProcEnvValue; +#else +using QProcEnvKey = QByteArray; class QProcEnvValue { @@ -138,7 +136,6 @@ public: }; Q_DECLARE_TYPEINFO(QProcEnvValue, Q_MOVABLE_TYPE); #endif -Q_DECLARE_TYPEINFO(QProcEnvKey, Q_MOVABLE_TYPE); class QProcessEnvironmentPrivate: public QSharedData { @@ -161,13 +158,13 @@ public: inline Key prepareName(const QString &name) const { Key &ent = nameMap[name]; - if (ent.key.isEmpty()) - ent = Key(name.toLocal8Bit()); + if (ent.isEmpty()) + ent = name.toLocal8Bit(); return ent; } inline QString nameToString(const Key &name) const { - const QString sname = QString::fromLocal8Bit(name.key); + const QString sname = QString::fromLocal8Bit(name); nameMap[sname] = name; return sname; } @@ -197,17 +194,17 @@ public: // do not need a lock, as they detach objects (however, we need to // ensure that they really detach before using prepareName()). MutexLocker locker(&other); - hash = other.hash; + vars = other.vars; nameMap = other.nameMap; // We need to detach our members, so that our mutex can protect them. // As we are being detached, they likely would be detached a moment later anyway. - hash.detach(); + vars.detach(); nameMap.detach(); } #endif - typedef QHash<Key, Value> Hash; - Hash hash; + using Map = QMap<Key, Value>; + Map vars; #ifdef Q_OS_UNIX typedef QHash<QString, Key> NameHash; diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 2b47f3e5b1..35bb44fed4 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -137,7 +137,7 @@ QProcessEnvironment QProcessEnvironment::systemEnvironment() QByteArray name(entry, equal - entry); QByteArray value(equal + 1); - env.d->hash.insert(QProcessEnvironmentPrivate::Key(name), + env.d->vars.insert(QProcessEnvironmentPrivate::Key(name), QProcessEnvironmentPrivate::Value(value)); } return env; @@ -339,7 +339,7 @@ bool QProcessPrivate::openChannel(Channel &channel) } } -static char **_q_dupEnvironment(const QProcessEnvironmentPrivate::Hash &environment, int *envc) +static char **_q_dupEnvironment(const QProcessEnvironmentPrivate::Map &environment, int *envc) { *envc = 0; if (environment.isEmpty()) @@ -349,10 +349,10 @@ static char **_q_dupEnvironment(const QProcessEnvironmentPrivate::Hash &environm envp[environment.count()] = 0; envp[environment.count() + 1] = 0; - QProcessEnvironmentPrivate::Hash::ConstIterator it = environment.constBegin(); - const QProcessEnvironmentPrivate::Hash::ConstIterator end = environment.constEnd(); + auto it = environment.constBegin(); + const auto end = environment.constEnd(); for ( ; it != end; ++it) { - QByteArray key = it.key().key; + QByteArray key = it.key(); QByteArray value = it.value().bytes(); key.reserve(key.length() + 1 + value.length()); key.append('='); @@ -445,7 +445,7 @@ void QProcessPrivate::startProcess() char **envp = 0; if (environment.d.constData()) { QProcessEnvironmentPrivate::MutexLocker locker(environment.d); - envp = _q_dupEnvironment(environment.d.constData()->hash, &envc); + envp = _q_dupEnvironment(environment.d.constData()->vars, &envc); } // Encode the working directory if it's non-empty, otherwise just pass 0. @@ -969,7 +969,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) char **envp = nullptr; if (environment.d.constData()) { QProcessEnvironmentPrivate::MutexLocker locker(environment.d); - envp = _q_dupEnvironment(environment.d.constData()->hash, &envc); + envp = _q_dupEnvironment(environment.d.constData()->vars, &envc); } QByteArray tmp; diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index 0f6a61496d..2bbc4eddd0 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -75,7 +75,7 @@ QProcessEnvironment QProcessEnvironment::systemEnvironment() int nameLen = equal - entry; QString name = QString::fromWCharArray(entry, nameLen); QString value = QString::fromWCharArray(equal + 1, entryLen - nameLen - 1); - env.d->hash.insert(QProcessEnvironmentPrivate::Key(name), value); + env.d->vars.insert(QProcessEnvironmentPrivate::Key(name), value); } entry += entryLen + 1; } @@ -398,11 +398,11 @@ static QString qt_create_commandline(const QString &program, const QStringList & return args; } -static QByteArray qt_create_environment(const QProcessEnvironmentPrivate::Hash &environment) +static QByteArray qt_create_environment(const QProcessEnvironmentPrivate::Map &environment) { QByteArray envlist; if (!environment.isEmpty()) { - QProcessEnvironmentPrivate::Hash copy = environment; + QProcessEnvironmentPrivate::Map copy = environment; // add PATH if necessary (for DLL loading) QProcessEnvironmentPrivate::Key pathKey(QLatin1String("PATH")); @@ -421,8 +421,8 @@ static QByteArray qt_create_environment(const QProcessEnvironmentPrivate::Hash & } int pos = 0; - QProcessEnvironmentPrivate::Hash::ConstIterator it = copy.constBegin(), - end = copy.constEnd(); + auto it = copy.constBegin(); + const auto end = copy.constEnd(); static const wchar_t equal = L'='; static const wchar_t nul = L'\0'; @@ -507,7 +507,7 @@ void QProcessPrivate::startProcess() const QString args = qt_create_commandline(program, arguments, nativeArguments); QByteArray envlist; if (environment.d.constData()) - envlist = qt_create_environment(environment.d.constData()->hash); + envlist = qt_create_environment(environment.d.constData()->vars); #if defined QPROCESS_DEBUG qDebug("Creating process"); @@ -891,7 +891,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) void *envPtr = nullptr; QByteArray envlist; if (environment.d.constData()) { - envlist = qt_create_environment(environment.d.constData()->hash); + envlist = qt_create_environment(environment.d.constData()->vars); envPtr = envlist.data(); } |