diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2016-08-03 16:12:32 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-03-21 18:46:46 +0000 |
commit | ceb859bf036dfdd1c54eec403006eac62a0d09b8 (patch) | |
tree | da78830719637ab469225b82eb4321019986ef62 /src/corelib/global/qlogging.cpp | |
parent | 6445aa4b064931cda36243aafc1600915fac093e (diff) |
Implement a counted QT_FATAL_WARNINGS
[ChangeLog][QtCore][Logging] If you set QT_FATAL_WARNINGS to a number
greater than 1, Qt will stop the application at that nth warning,
instead of on the first one. For compatibility reasons with previous
versions, if the variable is set to any non-empty and non-numeric value
different from 0, Qt will understand as "stop on first warning".
Change-Id: I0031aa609e714ae983c3fffd14676f1826f34600
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/global/qlogging.cpp')
-rw-r--r-- | src/corelib/global/qlogging.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 6573e0a53e..927c1bb76b 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -153,19 +153,39 @@ Q_NORETURN static void qt_message_fatal(QtMsgType, const QMessageLogContext &context, const QString &message); static void qt_message_print(QtMsgType, const QMessageLogContext &context, const QString &message); +static int checked_var_value(const char *varname) +{ + // qEnvironmentVariableIntValue returns 0 on both parsing failure and on + // empty, but we need to distinguish between the two for backwards + // compatibility reasons. + QByteArray str = qgetenv(varname); + if (str.isEmpty()) + return 0; + + bool ok; + int value = str.toInt(&ok, 0); + return ok ? value : 1; +} + static bool isFatal(QtMsgType msgType) { if (msgType == QtFatalMsg) return true; if (msgType == QtCriticalMsg) { - static bool fatalCriticals = !qEnvironmentVariableIsEmpty("QT_FATAL_CRITICALS"); - return fatalCriticals; + static QAtomicInt fatalCriticals = checked_var_value("QT_FATAL_CRITICALS"); + + // it's fatal if the current value is exactly 1, + // otherwise decrement if it's non-zero + return fatalCriticals.load() && fatalCriticals.fetchAndAddRelaxed(-1) == 1; } if (msgType == QtWarningMsg || msgType == QtCriticalMsg) { - static bool fatalWarnings = !qEnvironmentVariableIsEmpty("QT_FATAL_WARNINGS"); - return fatalWarnings; + static QAtomicInt fatalWarnings = checked_var_value("QT_FATAL_WARNINGS"); + + // it's fatal if the current value is exactly 1, + // otherwise decrement if it's non-zero + return fatalWarnings.load() && fatalWarnings.fetchAndAddRelaxed(-1) == 1; } return false; |