The index is a character index, not a index in a Py_UNICODE* string.
if (reason_str == NULL)
goto done;
- if (uself->start < PyUnicode_GET_SIZE(uself->object) && uself->end == uself->start+1) {
- int badchar = (int)PyUnicode_AS_UNICODE(uself->object)[uself->start];
+ if (uself->start < PyUnicode_GET_LENGTH(uself->object) && uself->end == uself->start+1) {
+ Py_UCS4 badchar = PyUnicode_ReadChar(uself->object, uself->start);
const char *fmt;
if (badchar <= 0xff)
fmt = "can't translate character '\\x%02x' in position %zd: %U";
fmt = "can't translate character '\\U%08x' in position %zd: %U";
result = PyUnicode_FromFormat(
fmt,
- badchar,
+ (int)badchar,
uself->start,
reason_str
);