Ensure QLocale's shared C-locale QLocalePrivate is never deleted
Other static data such as QTextStream might be initialized before the static C-locale, in which case QLocale would adopt c_private and bump the ref-count to 2, only to see it reset back to 1 when the c_locale's static initialization happened. The result was that at application shutdown the ref-count would fall down to 0, and we tried deleting the static data. This issue was observed with clang in a debug build, where the c_private is initialized at runtime. Change-Id: If05221a5e87886e1805ad3c1b1520483f425c0fb Reviewed-by: Simon Hausmann <simon.hausmann@digia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
parent
7b2ae0db66
commit
a24ec6b273
@ -531,7 +531,11 @@ static const QLocaleData *default_data = 0;
|
||||
static uint default_number_options = 0;
|
||||
|
||||
static const QLocaleData *const c_data = locale_data;
|
||||
static QLocalePrivate c_private = { c_data, Q_BASIC_ATOMIC_INITIALIZER(1), 0 };
|
||||
static QLocalePrivate *c_private()
|
||||
{
|
||||
static QLocalePrivate c_locale = { c_data, Q_BASIC_ATOMIC_INITIALIZER(1), 0 };
|
||||
return &c_locale;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_SYSTEMLOCALE
|
||||
|
||||
@ -700,7 +704,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer<QLocalePrivate>, defaultLocalePriva
|
||||
static QLocalePrivate *localePrivateByName(const QString &name)
|
||||
{
|
||||
if (name == QLatin1String("C"))
|
||||
return &c_private;
|
||||
return c_private();
|
||||
return QLocalePrivate::create(findLocaleData(name));
|
||||
}
|
||||
|
||||
@ -708,7 +712,7 @@ static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Sc
|
||||
QLocale::Country country)
|
||||
{
|
||||
if (language == QLocale::C)
|
||||
return &c_private;
|
||||
return c_private();
|
||||
|
||||
const QLocaleData *data = QLocaleData::findLocaleData(language, script, country);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user