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

bpo-35697, decimal: Fix locale formatting #11474

Open
wants to merge 3 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@vstinner
Copy link
Member

vstinner commented Jan 9, 2019

The decimal module now supports formatting number to the "n" type
when the LC_NUMERIC locale uses a different encoding than the
LC_CTYPE locale. It now sets temporarily the LC_CTYPE locale to the
LC_NUMERIC locale to decode decimal_point and thousands_sep byte
strings if they are non-ASCII or longer than 1 byte, and the
LC_NUMERIC locale is different than the LC_CTYPE locale. This
temporary change affects other threads.

Fix also #define guard of pycore_fileutils.h: allow also
Py_BUILD_CORE_BUILTIN.

https://bugs.python.org/issue35697

bpo-35697, decimal: Fix locale formatting
The decimal module now supports formatting number to the "n" type
when the LC_NUMERIC locale uses a different encoding than the
LC_CTYPE locale. It now sets temporarily the LC_CTYPE locale to the
LC_NUMERIC locale to decode decimal_point and thousands_sep byte
strings if they are non-ASCII or longer than 1 byte, and the
LC_NUMERIC locale is different than the LC_CTYPE locale. This
temporary change affects other threads.

Fix also #define guard of pycore_fileutils.h: allow also
Py_BUILD_CORE_BUILTIN.

@vstinner vstinner requested a review from skrah Jan 9, 2019

@vstinner vstinner requested a review from rhettinger as a code owner Jan 9, 2019

@skrah skrah self-assigned this Jan 9, 2019

@vstinner

This comment has been minimized.

Copy link
Member

vstinner commented Jan 9, 2019

This PR is based on my previous attempt: PR #5191 that I abandoned.

I'm not sure of the implementation of this change. It's a little bit weird that mpd_parse_fmt_str() calls localeconv() to get the decimal point and thousands separator, but then dec_format() calls again localeconv(). I chose this implementation to restrict changes in libmpdec.

@vstinner

This comment has been minimized.

Copy link
Member

vstinner commented Jan 10, 2019

Oh, I forgot to update the Windows VS project:

  _decimal.c
c:\projects\cpython\include\internal\pycore_fileutils.h(8): fatal error C1189: #error:  "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN defined" [C:\projects\cpython\PCbuild\_decimal.vcxproj]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment