FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-69998: Fix decoding error in locale.nl_langinfo() by serhiy-storchaka · Pull Request #124963 · python/cpython · GitHub

Repository navigation

gh-69998: Fix decoding error in locale.nl_langinfo() - #124963

Merged
serhiy-storchaka merged 4 commits into
python:mainfrom
serhiy-storchaka:locale-nl_langinfo
Oct 8, 2024
Merged

serhiy-storchaka merged 4 commits into
python:mainfrom
serhiy-storchaka:locale-nl_langinfo

Conversation

serhiy-storchaka commented Oct 4, 2024 •
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

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/

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.

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Comment thread Modules/_localemodule.c Outdated

Copy link
Copy Markdown
Member Author

Yes, I used your #4174 as an example.

Comment thread Modules/_localemodule.c
&& change_locale(langinfo_constants[i].category, &oldloc) < 0)
{
return NULL;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You don't call nl_langinfo() twice anymore? Why changing the code?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM with a single call to nl_langinfo().

serhiy-storchaka merged commit 93b9e6b into python:main Oct 8, 2024
serhiy-storchaka deleted the locale-nl_langinfo branch October 8, 2024 08:27
efimov-mikhail pushed a commit to efimov-mikhail/cpython that referenced this pull request Oct 9, 2024
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL