bpo-31900: Fix decimal for LC_NUMERIC != LC_CTYPE by vstinner · Pull Request #5191 · python/cpython
/* 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)
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; } }