summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qprocess_p.h
diff options
context:
space:
mode:
authorThomas Sondergaard <thomas.sondergaard@karoshealth.com>2017-06-11 18:41:57 +0200
committerThomas Sondergaard <thomas@sondergaard.cc>2017-06-13 06:09:40 +0000
commit65a317e6745ee267bef7295f4dfe31d5ec62f7aa (patch)
tree85a937b1a896bdeffd3d0bb602ee9791363e1006 /src/corelib/io/qprocess_p.h
parentb4381100280adbfa4cb6c4d8c84eed8f1dc126b9 (diff)
Use QMap in QProcessEnvironment so variables are sorted
The motivation for this change is to make it simple to pass a correctly sorted environment block to Win32 CreateProcess(). It is also nice in other contexts that the environment variables are sorted. The change is made for all platforms. This keeps it simple and the only ill effect is slightly slower lookups. Concerning the environment block passed to Win32 CreateProcess: The environment block that is passed to CreateProcess() must be sorted case-insensitively and without regard to locale. See https://msdn.microsoft.com/en-us/library/windows/desktop/ms682009(v=vs.85).aspx The need for sorting the environment block is also mentioned in the CreateProcess() documentation, but with less details: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx Task-number: QTBUG-61315 Change-Id: Ie1edd443301de79cf5f699d45beab01b7c0f9de3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qprocess_p.h')
-rw-r--r--src/corelib/io/qprocess_p.h35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h
index b8820510b3..c5abf7b762 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;
}
@@ -206,8 +203,8 @@ public:
}
#endif
- typedef QHash<Key, Value> Hash;
- Hash vars;
+ using Map = QMap<Key, Value>;
+ Map vars;
#ifdef Q_OS_UNIX
typedef QHash<QString, Key> NameHash;