From: Victor Stinner Date: Sun, 20 Nov 2011 21:50:23 +0000 (+0100) Subject: UnicodeEncodeError uses the new Unicode API X-Git-Tag: v3.3.0a1~788 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=da1ddf37c68f76041ca8ebb75e0016e96cc3f67b;p=thirdparty%2FPython%2Fcpython.git UnicodeEncodeError uses the new Unicode API The index is a character index, not a index in a Py_UNICODE* string. --- diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 5b5447a1d7d6..c8f90b89a09a 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -1542,8 +1542,8 @@ UnicodeEncodeError_str(PyObject *self) if (encoding_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 = "'%U' codec can't encode character '\\x%02x' in position %zd: %U"; @@ -1554,7 +1554,7 @@ UnicodeEncodeError_str(PyObject *self) result = PyUnicode_FromFormat( fmt, encoding_str, - badchar, + (int)badchar, uself->start, reason_str); }