Commit da1ddf37 authored by Victor Stinner's avatar Victor Stinner

UnicodeEncodeError uses the new Unicode API

The index is a character index, not a index in a Py_UNICODE* string.
parent 4ead7c7b
...@@ -1542,8 +1542,8 @@ UnicodeEncodeError_str(PyObject *self) ...@@ -1542,8 +1542,8 @@ UnicodeEncodeError_str(PyObject *self)
if (encoding_str == NULL) if (encoding_str == NULL)
goto done; goto done;
if (uself->start < PyUnicode_GET_SIZE(uself->object) && uself->end == uself->start+1) { if (uself->start < PyUnicode_GET_LENGTH(uself->object) && uself->end == uself->start+1) {
int badchar = (int)PyUnicode_AS_UNICODE(uself->object)[uself->start]; Py_UCS4 badchar = PyUnicode_ReadChar(uself->object, uself->start);
const char *fmt; const char *fmt;
if (badchar <= 0xff) if (badchar <= 0xff)
fmt = "'%U' codec can't encode character '\\x%02x' in position %zd: %U"; fmt = "'%U' codec can't encode character '\\x%02x' in position %zd: %U";
...@@ -1554,7 +1554,7 @@ UnicodeEncodeError_str(PyObject *self) ...@@ -1554,7 +1554,7 @@ UnicodeEncodeError_str(PyObject *self)
result = PyUnicode_FromFormat( result = PyUnicode_FromFormat(
fmt, fmt,
encoding_str, encoding_str,
badchar, (int)badchar,
uself->start, uself->start,
reason_str); reason_str);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment