From 1c0f20e627c54118d0c4a57abe4e2035adff02fd Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 21 May 2025 23:09:01 +0200 Subject: [PATCH 1/3] gh-133740: Fix locale.nl_langinfo(ALT_DIGITS) Set the LC_CTYPE locale to the LC_TIME locale even if nl_langinfo(ALT_DIGITS) result is ASCII. The result is a list separated by NUL characters and the code only checks the first list item which can be ASCII whereas following items are non-ASCII. Fix test__locale for the uk_UA locale on RHEL 7. --- Modules/_localemodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index ad618398d5b824..d46e0a877497be 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -692,7 +692,8 @@ _locale_nl_langinfo_impl(PyObject *module, int item) result = result != NULL ? result : ""; char *oldloc = NULL; if (langinfo_constants[i].category != LC_CTYPE - && !is_all_ascii(result) + // gh-133740: Always change the locale for ALT_DIGITS + && (item == ALT_DIGITS || !is_all_ascii(result)) && change_locale(langinfo_constants[i].category, &oldloc) < 0) { return NULL; From 79d373d315e395c0471e48d85b9ccd746ffa21b6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 22 May 2025 14:38:04 +0200 Subject: [PATCH 2/3] Apply Serhiy's suggestion --- Modules/_localemodule.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index d46e0a877497be..45a852fb68aa25 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -692,8 +692,17 @@ _locale_nl_langinfo_impl(PyObject *module, int item) result = result != NULL ? result : ""; char *oldloc = NULL; if (langinfo_constants[i].category != LC_CTYPE - // gh-133740: Always change the locale for ALT_DIGITS - && (item == ALT_DIGITS || !is_all_ascii(result)) + // gh-133740: Always change the locale for ALT_DIGITS and ERA + && ( +#ifdef __GLIBC__ +# ifdef ALT_DIGITS + item == ALT_DIGITS || +# endif +# ifdef ERA + item == ERA || +# endif +#endif + !is_all_ascii(result)) && change_locale(langinfo_constants[i].category, &oldloc) < 0) { return NULL; From 1f3493fc347ebc3013be90e9c1978aec21a22b42 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 22 May 2025 14:53:59 +0200 Subject: [PATCH 3/3] Update Modules/_localemodule.c Co-authored-by: Serhiy Storchaka --- Modules/_localemodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 45a852fb68aa25..c1f56008b7c49e 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -692,9 +692,9 @@ _locale_nl_langinfo_impl(PyObject *module, int item) result = result != NULL ? result : ""; char *oldloc = NULL; if (langinfo_constants[i].category != LC_CTYPE - // gh-133740: Always change the locale for ALT_DIGITS and ERA && ( #ifdef __GLIBC__ + // gh-133740: Always change the locale for ALT_DIGITS and ERA # ifdef ALT_DIGITS item == ALT_DIGITS || # endif