Restore Android-conditioning on nl_langinfo() definition

QCoreApplicationPrivate::initLocale()'s check that the selected locale
is UTF-8-based was added with an initial work-around for Android,
specific to NDK <= 15, which Qt 5.15 did not support.

Later the Android-specific #if-ery was changed to test for Qt taking
UTF-8 for granted, for a given reason having to do with QNX; and later
the #if-ery for that was removed. However, we still support versions
of Android that lack nl_langinfo(), so restore the Android #if-ery.
It presently seems that NDK 26 (Android 8) does contain nl_langinfo(),
so we should be able to drop the nl_langinfo() kludge for this and
later versions. That way we'll at least use the real nl_langinfo()
where we have it.

In the process, fix the indentation of #if-ery.

Pick-to: 6.5 6.4 6.2
Change-Id: Ie9e83c3397955c24cea1e9a9ff6bb0187e47dda2
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Edward Welbourne 2022-10-31 15:25:55 +01:00
parent 1cd7bdeceb
commit 10117f78d7

View File

@ -590,12 +590,14 @@ void QCoreApplicationPrivate::initLocale()
return;
qt_locale_initialized = true;
#ifdef Q_OS_INTEGRITY
# ifdef Q_OS_INTEGRITY
setlocale(LC_CTYPE, "UTF-8");
#else
// Android's Bionic didn't get nl_langinfo until NDK 15 (Android 8.0),
// which is too new for Qt, so we just assume it's always UTF-8.
# else
# if defined(Q_OS_QNX) || (defined(Q_OS_ANDROID) && __ANDROID_API__ < __ANDROID_API_O__)
// Android 6 still lacks nl_langinfo(), as does QNX, so we just assume it's
// always UTF-8 on these platforms.
auto nl_langinfo = [](int) { return "UTF-8"; };
# endif // QNX or Android NDK < 26, "O".
const char *locale = setlocale(LC_ALL, "");
const char *codec = nl_langinfo(CODESET);
@ -610,10 +612,10 @@ void QCoreApplicationPrivate::initLocale()
newLocale = setlocale(LC_CTYPE, newLocale);
// if locale doesn't exist, try some fallbacks
# ifdef Q_OS_DARWIN
# ifdef Q_OS_DARWIN
if (newLocale.isEmpty())
newLocale = setlocale(LC_CTYPE, "UTF-8");
# endif
# endif
if (newLocale.isEmpty())
newLocale = setlocale(LC_CTYPE, "C.UTF-8");
if (newLocale.isEmpty())
@ -624,8 +626,8 @@ void QCoreApplicationPrivate::initLocale()
"reconfigure your locale. See the locale(1) manual for more information.",
codec, oldLocale.constData(), newLocale.constData());
}
#endif
#endif
# endif // Integrity
#endif // Unix
}