Skip to content

Commit 94ee8e2

Browse files
Fix the decimal point and the thousands separator in the decimal module
dotsep_as_utf8() used mbstowcs(), which does not produce Unicode code points in non-UTF-8 locales on the affected platforms. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 44f96df commit 94ee8e2

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Modules/_decimal/_decimal.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3657,20 +3657,20 @@ dotsep_as_utf8(const char *s)
36573657
{
36583658
PyObject *utf8;
36593659
PyObject *tmp;
3660-
wchar_t buf[2];
3661-
size_t n;
36623660

3663-
n = mbstowcs(buf, s, 2);
3664-
if (n != 1) { /* Issue #7442 */
3661+
/* Do not use mbstowcs(): wchar_t values are not Unicode code points
3662+
in non-UTF-8 locales on some platforms (e.g. the BSDs and macOS). */
3663+
tmp = PyUnicode_DecodeLocale(s, NULL);
3664+
if (tmp == NULL) {
3665+
return NULL;
3666+
}
3667+
if (PyUnicode_GET_LENGTH(tmp) != 1) { /* Issue #7442 */
3668+
Py_DECREF(tmp);
36653669
PyErr_SetString(PyExc_ValueError,
36663670
"invalid decimal point or unsupported "
36673671
"combination of LC_CTYPE and LC_NUMERIC");
36683672
return NULL;
36693673
}
3670-
tmp = PyUnicode_FromWideChar(buf, n);
3671-
if (tmp == NULL) {
3672-
return NULL;
3673-
}
36743674
utf8 = PyUnicode_AsUTF8String(tmp);
36753675
Py_DECREF(tmp);
36763676
return utf8;

0 commit comments

Comments
 (0)