diff options
Diffstat (limited to 'src/corelib/global/qglobal.cpp')
-rw-r--r-- | src/corelib/global/qglobal.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index d6f5162648..91e8699472 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -42,6 +42,7 @@ #include <private/qlocale_tools_p.h> #include <private/qsystemlibrary_p.h> +#include <qmutex.h> #ifndef QT_NO_QOBJECT #include <private/qthread_p.h> @@ -1151,6 +1152,9 @@ bool qSharedBuild() Q_DECL_NOTHROW \value MV_IOS_7_0 iOS 7.0 \value MV_IOS_7_1 iOS 7.1 \value MV_IOS_8_0 iOS 8.0 + \value MV_IOS_8_1 iOS 8.1 + \value MV_IOS_8_2 iOS 8.2 + \value MV_IOS_8_3 iOS 8.3 \value MV_None Not a Darwin operating system @@ -2879,12 +2883,15 @@ QString QSysInfo::prettyProductName() \macro void Q_CHECK_PTR(void *pointer) \relates <QtGlobal> - If \a pointer is 0, prints a warning message containing the source + If \a pointer is 0, prints a message containing the source code's file name and line number, saying that the program ran out - of memory. + of memory and aborts program execution. It throws \c std::bad_alloc instead + if exceptions are enabled. - Q_CHECK_PTR does nothing if \c QT_NO_DEBUG was defined during - compilation. + Q_CHECK_PTR does nothing if \c QT_NO_DEBUG and \c QT_NO_EXCEPTIONS were + defined during compilation. Therefore you must not use Q_CHECK_PTR to check + for successful memory allocations because the check will be disabled in + some cases. Example: @@ -3014,7 +3021,7 @@ namespace { // depending on the return type static inline Q_DECL_UNUSED QString fromstrerror_helper(int, const QByteArray &buf) { - return QString::fromLocal8Bit(buf); + return QString::fromLocal8Bit(buf.constData()); } static inline Q_DECL_UNUSED QString fromstrerror_helper(const char *str, const QByteArray &) { @@ -3092,6 +3099,10 @@ QString qt_error_string(int errorCode) return ret.trimmed(); } +// In the C runtime on all platforms access to the environment is not thread-safe. We +// add thread-safety for the Qt wrappers. +static QBasicMutex environmentMutex; + // getenv is declared as deprecated in VS2005. This function // makes use of the new secure getenv function. /*! @@ -3109,6 +3120,7 @@ QString qt_error_string(int errorCode) */ QByteArray qgetenv(const char *varName) { + QMutexLocker locker(&environmentMutex); #if defined(_MSC_VER) && _MSC_VER >= 1400 size_t requiredSize = 0; QByteArray buffer; @@ -3142,6 +3154,7 @@ QByteArray qgetenv(const char *varName) */ bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT { + QMutexLocker locker(&environmentMutex); #if defined(_MSC_VER) && _MSC_VER >= 1400 // we provide a buffer that can only hold the empty string, so // when the env.var isn't empty, we'll get an ERANGE error (buffer @@ -3173,6 +3186,7 @@ bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT */ 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; @@ -3221,6 +3235,7 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) Q_DECL_NOEXCEPT */ bool qEnvironmentVariableIsSet(const char *varName) Q_DECL_NOEXCEPT { + QMutexLocker locker(&environmentMutex); #if defined(_MSC_VER) && _MSC_VER >= 1400 size_t requiredSize = 0; (void)getenv_s(&requiredSize, 0, 0, varName); @@ -3250,6 +3265,7 @@ bool qEnvironmentVariableIsSet(const char *varName) Q_DECL_NOEXCEPT */ bool qputenv(const char *varName, const QByteArray& value) { + QMutexLocker locker(&environmentMutex); #if defined(_MSC_VER) && _MSC_VER >= 1400 return _putenv_s(varName, value.constData()) == 0; #elif (defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L) || defined(Q_OS_HAIKU) @@ -3280,6 +3296,7 @@ bool qputenv(const char *varName, const QByteArray& value) */ bool qunsetenv(const char *varName) { + QMutexLocker locker(&environmentMutex); #if defined(_MSC_VER) && _MSC_VER >= 1400 return _putenv_s(varName, "") == 0; #elif (defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L) || defined(Q_OS_BSD4) || defined(Q_OS_HAIKU) |