summaryrefslogtreecommitdiffstats
path: root/Modules/_localemodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2018-01-15 14:58:02 (GMT)
committerGitHub <noreply@github.com>2018-01-15 14:58:02 (GMT)
commitcb064fc2321ce8673fe365e9ef60445a27657f54 (patch)
tree06356d6625f022636e22ed5e8646a3f2e36afac4 /Modules/_localemodule.c
parent7ed7aead9503102d2ed316175f198104e0cd674c (diff)
downloadcpython-cb064fc2321ce8673fe365e9ef60445a27657f54.zip
cpython-cb064fc2321ce8673fe365e9ef60445a27657f54.tar.gz
cpython-cb064fc2321ce8673fe365e9ef60445a27657f54.tar.bz2
bpo-31900: Fix localeconv() encoding for LC_NUMERIC (#4174)
* Add _Py_GetLocaleconvNumeric() function: decode decimal_point and thousands_sep fields of localeconv() from the LC_NUMERIC encoding, rather than decoding from the LC_CTYPE encoding. * Modify locale.localeconv() and "n" formatter of str.format() (for int, float and complex to use _Py_GetLocaleconvNumeric() internally.
Diffstat (limited to 'Modules/_localemodule.c')
-rw-r--r--Modules/_localemodule.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index 324b694..f9eeeb7 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -139,8 +139,9 @@ PyLocale_localeconv(PyObject* self)
PyObject *x;
result = PyDict_New();
- if (!result)
+ if (!result) {
return NULL;
+ }
/* if LC_NUMERIC is different in the C library, use saved value */
l = localeconv();
@@ -171,12 +172,6 @@ PyLocale_localeconv(PyObject* self)
RESULT(#i, x); \
} while (0)
- /* Numeric information */
- RESULT_STRING(decimal_point);
- RESULT_STRING(thousands_sep);
- x = copy_grouping(l->grouping);
- RESULT("grouping", x);
-
/* Monetary information */
RESULT_STRING(int_curr_symbol);
RESULT_STRING(currency_symbol);
@@ -195,10 +190,36 @@ PyLocale_localeconv(PyObject* self)
RESULT_INT(n_sep_by_space);
RESULT_INT(p_sign_posn);
RESULT_INT(n_sign_posn);
+
+ /* Numeric information */
+ PyObject *decimal_point, *thousands_sep;
+ const char *grouping;
+ if (_Py_GetLocaleconvNumeric(&decimal_point,
+ &thousands_sep,
+ &grouping) < 0) {
+ goto failed;
+ }
+
+ if (PyDict_SetItemString(result, "decimal_point", decimal_point) < 0) {
+ Py_DECREF(decimal_point);
+ Py_DECREF(thousands_sep);
+ goto failed;
+ }
+ Py_DECREF(decimal_point);
+
+ if (PyDict_SetItemString(result, "thousands_sep", thousands_sep) < 0) {
+ Py_DECREF(thousands_sep);
+ goto failed;
+ }
+ Py_DECREF(thousands_sep);
+
+ x = copy_grouping(grouping);
+ RESULT("grouping", x);
+
return result;
failed:
- Py_XDECREF(result);
+ Py_DECREF(result);
return NULL;
}