From d5891036de4622e18cf4d68750610224ad201ee0 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 4 Jul 2018 14:50:49 +0200 Subject: Make updateSystemPrivate() local to qlocale.cpp It's not thread-safe so should only be used within systemData()'s locked code. This eliminates the last callers of it by making it a local function of the compilation unit, exposing a method from QSystemLocale() to get round its use of private parts. Make the constructor for QSystemLocale only stomp its _systemLocale global if previously unset, but let instantiation still clear globalLocaleData.m_language_id, so that it can be used as a way to trigger an update to system locale data. Change-Id: I908dca9fd30bbf20f42321ab8f9094f2fa37b7b0 Reviewed-by: Thiago Macieira --- src/corelib/tools/qlocale.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/corelib/tools/qlocale.cpp') diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 7425302857..0081b5d566 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -620,13 +620,18 @@ static QLocalePrivate *c_private() */ /*! - Constructs a QSystemLocale object. The constructor will automatically - install this object as the system locale and remove any earlier installed - system locales. + Constructs a QSystemLocale object. + + The constructor will automatically install this object as the system locale, + if there's not one active. It also resets the flag that'll prompt + QLocale::system() to re-initialize its data, so that instantiating a + QSystemLocale transiently (doesn't install the transient as system locale if + there was one already and) triggers an update to the system locale's data. */ QSystemLocale::QSystemLocale() { - _systemLocale = this; + if (!_systemLocale) + _systemLocale = this; globalLocaleData.m_language_id = 0; } @@ -656,15 +661,17 @@ static const QSystemLocale *systemLocale() return QSystemLocale_globalSystemLocale(); } -void QLocalePrivate::updateSystemPrivate() +static void updateSystemPrivate() { - // this function is NOT thread-safe! + // This function is NOT thread-safe! + // It *should not* be called by anything but systemData() const QSystemLocale *sys_locale = systemLocale(); // tell the object that the system locale has changed. sys_locale->query(QSystemLocale::LocaleChanged, QVariant()); - globalLocaleData = *sys_locale->fallbackUiLocale().d->m_data; + // Populate global with fallback as basis: + globalLocaleData = *sys_locale->fallbackUiLocaleData(); QVariant res = sys_locale->query(QSystemLocale::LanguageId, QVariant()); if (!res.isNull()) { @@ -715,7 +722,7 @@ static const QLocaleData *systemData() static QBasicMutex systemDataMutex; systemDataMutex.lock(); if (globalLocaleData.m_language_id == 0) - QLocalePrivate::updateSystemPrivate(); + updateSystemPrivate(); systemDataMutex.unlock(); } @@ -2351,7 +2358,6 @@ QString QLocale::toString(double i, char f, int prec) const QLocale QLocale::system() { - // this function is NOT thread-safe! QT_PREPEND_NAMESPACE(systemData)(); // trigger updating of the system data if necessary return QLocale(*systemLocalePrivate->data()); } -- cgit v1.2.3