Skip to content

bpo-35697, decimal: Fix locale formatting#11474

Closed
vstinner wants to merge 3 commits intopython:masterfrom
vstinner:decimal_locale
Closed

bpo-35697, decimal: Fix locale formatting#11474
vstinner wants to merge 3 commits intopython:masterfrom
vstinner:decimal_locale

Conversation

@vstinner
Copy link
Member

@vstinner 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

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
Copy link
Member Author

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
Copy link
Member Author

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]

@vstinner
Copy link
Member Author

I'm no longer interested to rewrite my patch to avoid _Py_GetLocaleconvNumeric() which comes from the internal API, so I close my PR.

@vstinner vstinner closed this Apr 16, 2019
@vstinner vstinner deleted the decimal_locale branch April 16, 2019 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants