mirror of
https://github.com/python/cpython.git
synced 2026-04-23 20:31:12 +00:00
_Py_CoerceLegacyLocale() restores LC_CTYPE on fail (GH-9044) (GH-9046)
bpo-34544: If _Py_CoerceLegacyLocale() fails to coerce the C locale,
restore the LC_CTYPE locale to the its previous value.
(cherry picked from commit 8ea09110d4)
This commit is contained in:
parent
f4c865eda8
commit
84b0129b5e
1 changed files with 13 additions and 1 deletions
|
|
@ -475,6 +475,13 @@ void
|
|||
_Py_CoerceLegacyLocale(const _PyCoreConfig *config)
|
||||
{
|
||||
#ifdef PY_COERCE_C_LOCALE
|
||||
char *oldloc = NULL;
|
||||
|
||||
oldloc = _PyMem_RawStrdup(setlocale(LC_CTYPE, NULL));
|
||||
if (oldloc == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char *locale_override = getenv("LC_ALL");
|
||||
if (locale_override == NULL || *locale_override == '\0') {
|
||||
/* LC_ALL is also not set (or is set to an empty string) */
|
||||
|
|
@ -496,11 +503,16 @@ defined(HAVE_LANGINFO_H) && defined(CODESET)
|
|||
#endif
|
||||
/* Successfully configured locale, so make it the default */
|
||||
_coerce_default_locale_settings(config, target);
|
||||
return;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* No C locale warning here, as Py_Initialize will emit one later */
|
||||
|
||||
setlocale(LC_CTYPE, oldloc);
|
||||
|
||||
done:
|
||||
PyMem_RawFree(oldloc);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue