◐ Shell
clean mode source ↗

bpo-31900: Fix decimal for LC_NUMERIC != LC_CTYPE by vstinner · Pull Request #5191 · python/cpython

Expand Up @@ -3076,32 +3076,6 @@ dec_replace_fillchar(char *dest) } }
/* Convert decimal_point or thousands_sep, which may be multibyte or in the range [128, 255], to a UTF8 string. */ static PyObject * dotsep_as_utf8(const char *s) { PyObject *utf8; PyObject *tmp; wchar_t buf[2]; size_t n;
n = mbstowcs(buf, s, 2); if (n != 1) { /* Issue #7442 */ PyErr_SetString(PyExc_ValueError, "invalid decimal point or unsupported " "combination of LC_CTYPE and LC_NUMERIC"); return NULL; } tmp = PyUnicode_FromWideChar(buf, n); if (tmp == NULL) { return NULL; } utf8 = PyUnicode_AsUTF8String(tmp); Py_DECREF(tmp); return utf8; }
/* Formatted representation of a PyDecObject. */ static PyObject * dec_format(PyObject *dec, PyObject *args) Expand Down Expand Up @@ -3196,24 +3170,25 @@ dec_format(PyObject *dec, PyObject *args) goto finish; } } else { size_t n = strlen(spec.dot); if (n > 1 || (n == 1 && !isascii((uchar)spec.dot[0]))) { /* fix locale dependent non-ascii characters */ dot = dotsep_as_utf8(spec.dot); if (dot == NULL) { goto finish; } spec.dot = PyBytes_AS_STRING(dot); else if (spec.locale) { if (_Py_GetLocaleconvNumeric(&dot, &sep, &spec.grouping) < 0) { goto finish; } n = strlen(spec.sep); if (n > 1 || (n == 1 && !isascii((uchar)spec.sep[0]))) { /* fix locale dependent non-ascii characters */ sep = dotsep_as_utf8(spec.sep); if (sep == NULL) { goto finish; } spec.sep = PyBytes_AS_STRING(sep);
spec.dot = PyUnicode_AsUTF8(dot); if (spec.dot == NULL) { goto finish; }
spec.sep = PyUnicode_AsUTF8(sep); if (spec.sep == NULL) { goto finish; }
if (mpd_validate_lconv(&spec) < 0) { PyErr_SetString(PyExc_ValueError, "invalid localeconv()"); goto finish; } }
Expand Down