-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-69998: Fix decoding error in locale.nl_langinfo() #124963
gh-69998: Fix decoding error in locale.nl_langinfo() #124963
Conversation
The function now sets temporarily the LC_CTYPE locale to the locale of the category that determines the requested value if the locales are different and the resulting string is non-ASCII. This temporary change affects other threads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I wrote a similar change in the past using _Py_GetLocaleconvNumeric(). It's used for example in Python/formatter_unicode.c to get the decimal point and thousands separator.
Yes, I used your #4174 as an example. |
&& change_locale(langinfo_constants[i].category, &oldloc) < 0) | ||
{ | ||
return NULL; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't call nl_langinfo() twice anymore? Why changing the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I now think that it was not needed. The result can only be changed if setlocale()
is called with the same category or LC_ALL. And, even if it is not explicitly stated, I think that calls setlocale(..., NULL)
are not counted.
On other hand,I want to avoid duplication of the code for conversion of the result because of #124974.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
locale.localeconv()
calls localeconv()
only once, whereas it changes the LC_CTYPE locale while reading its output. Let's do the same for nl_langinfo()
. If the assumption is wrong, we can adjust the code later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a single call to nl_langinfo()
.
…124963) The function now sets temporarily the LC_CTYPE locale to the locale of the category that determines the requested value if the locales are different and the resulting string is non-ASCII. This temporary change affects other threads.
The function now sets temporarily the LC_CTYPE locale to the locale of the category that determines the requested value if the locales are different and the resulting string is non-ASCII.
This temporary change affects other threads.
📚 Documentation preview 📚: https://cpython-previews--124963.org.readthedocs.build/