]> granicus.if.org Git - python/commitdiff
UnicodeTranslateError uses the new Unicode API
authorVictor Stinner <victor.stinner@haypocalc.com>
Mon, 21 Nov 2011 00:17:27 +0000 (01:17 +0100)
committerVictor Stinner <victor.stinner@haypocalc.com>
Mon, 21 Nov 2011 00:17:27 +0000 (01:17 +0100)
The index is a character index, not a index in a Py_UNICODE* string.

Objects/exceptions.c

index c8f90b89a09a4be15e6f7d32e24fad9c5f0b5d82..a1b79a86bc4c1026df765833e28503bec60415aa 100644 (file)
@@ -1751,8 +1751,8 @@ UnicodeTranslateError_str(PyObject *self)
     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";
@@ -1762,7 +1762,7 @@ UnicodeTranslateError_str(PyObject *self)
             fmt = "can't translate character '\\U%08x' in position %zd: %U";
         result = PyUnicode_FromFormat(
             fmt,
-            badchar,
+            (int)badchar,
             uself->start,
             reason_str
         );