diff options
author | Miss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-10-20 11:58:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-20 11:58:06 (GMT) |
commit | 4cde523aa467c92a713674c793ab87e7c56486c4 (patch) | |
tree | be9cd1a92551d5940442ae759d948cacfad9708f /Modules/_localemodule.c | |
parent | d1eb75585ef4c108732ec815cdc0adef087b1c3e (diff) | |
download | cpython-4cde523aa467c92a713674c793ab87e7c56486c4.zip cpython-4cde523aa467c92a713674c793ab87e7c56486c4.tar.gz cpython-4cde523aa467c92a713674c793ab87e7c56486c4.tar.bz2 |
bpo-38324: Fix test__locale.py Windows failures (GH-20529)
Use wide-char _W_* fields of lconv structure on Windows
Remove "ps_AF" from test__locale.known_numerics on Windows
(cherry picked from commit f2312037e3a974d26ed3e23884f94c6af111a27a)
Co-authored-by: TIGirardi <tiagoigirardi@gmail.com>
Diffstat (limited to 'Modules/_localemodule.c')
-rw-r--r-- | Modules/_localemodule.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 036bdb3..d54f709 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -131,6 +131,7 @@ locale_is_ascii(const char *str) static int locale_decode_monetary(PyObject *dict, struct lconv *lc) { +#ifndef MS_WINDOWS int change_locale; change_locale = (!locale_is_ascii(lc->int_curr_symbol) || !locale_is_ascii(lc->currency_symbol) @@ -166,12 +167,18 @@ locale_decode_monetary(PyObject *dict, struct lconv *lc) } } +#define GET_LOCALE_STRING(ATTR) PyUnicode_DecodeLocale(lc->ATTR, NULL) +#else /* MS_WINDOWS */ +/* Use _W_* fields of Windows struct lconv */ +#define GET_LOCALE_STRING(ATTR) PyUnicode_FromWideChar(lc->_W_ ## ATTR, -1) +#endif /* MS_WINDOWS */ + int res = -1; #define RESULT_STRING(ATTR) \ do { \ PyObject *obj; \ - obj = PyUnicode_DecodeLocale(lc->ATTR, NULL); \ + obj = GET_LOCALE_STRING(ATTR); \ if (obj == NULL) { \ goto done; \ } \ @@ -187,14 +194,17 @@ locale_decode_monetary(PyObject *dict, struct lconv *lc) RESULT_STRING(mon_decimal_point); RESULT_STRING(mon_thousands_sep); #undef RESULT_STRING +#undef GET_LOCALE_STRING res = 0; done: +#ifndef MS_WINDOWS if (loc != NULL) { setlocale(LC_CTYPE, oldloc); } PyMem_Free(oldloc); +#endif return res; } @@ -230,9 +240,15 @@ PyLocale_localeconv(PyObject* self, PyObject *Py_UNUSED(ignored)) Py_DECREF(obj); \ } while (0) +#ifdef MS_WINDOWS +/* Use _W_* fields of Windows struct lconv */ +#define GET_LOCALE_STRING(ATTR) PyUnicode_FromWideChar(lc->_W_ ## ATTR, -1) +#else +#define GET_LOCALE_STRING(ATTR) PyUnicode_DecodeLocale(lc->ATTR, NULL) +#endif #define RESULT_STRING(s)\ do { \ - x = PyUnicode_DecodeLocale(lc->s, NULL); \ + x = GET_LOCALE_STRING(s); \ RESULT(#s, x); \ } while (0) @@ -261,8 +277,10 @@ PyLocale_localeconv(PyObject* self, PyObject *Py_UNUSED(ignored)) RESULT_INT(n_sign_posn); /* Numeric information: LC_NUMERIC encoding */ - PyObject *decimal_point, *thousands_sep; + PyObject *decimal_point = NULL, *thousands_sep = NULL; if (_Py_GetLocaleconvNumeric(lc, &decimal_point, &thousands_sep) < 0) { + Py_XDECREF(decimal_point); + Py_XDECREF(thousands_sep); goto failed; } @@ -291,6 +309,7 @@ PyLocale_localeconv(PyObject* self, PyObject *Py_UNUSED(ignored)) #undef RESULT #undef RESULT_STRING #undef RESULT_INT +#undef GET_LOCALE_STRING } #if defined(HAVE_WCSCOLL) |