diff options
Diffstat (limited to 'src/corelib/global/qglobal.cpp')
-rw-r--r-- | src/corelib/global/qglobal.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 9e19dd7f0f..85d97c7b06 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> @@ -2886,12 +2887,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: @@ -3021,7 +3025,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 &) { @@ -3099,6 +3103,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. /*! @@ -3116,6 +3124,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; @@ -3149,6 +3158,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 @@ -3180,6 +3190,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; @@ -3228,6 +3239,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); @@ -3257,6 +3269,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) @@ -3287,6 +3300,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) |