[Python-checkins] cpython: UnicodeTranslateError uses the new Unicode API

victor.stinner python-checkins at python.org
Mon Nov 21 01:15:15 CET 2011


http://hg.python.org/cpython/rev/244d9159aa38
changeset:   73649:244d9159aa38
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Mon Nov 21 01:17:27 2011 +0100
summary:
  UnicodeTranslateError uses the new Unicode API

The index is a character index, not a index in a Py_UNICODE* string.

files:
  Objects/exceptions.c |  6 +++---
  1 files changed, 3 insertions(+), 3 deletions(-)


diff --git a/Objects/exceptions.c b/Objects/exceptions.c
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -1751,8 +1751,8 @@
     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 @@
             fmt = "can't translate character '\\U%08x' in position %zd: %U";
         result = PyUnicode_FromFormat(
             fmt,
-            badchar,
+            (int)badchar,
             uself->start,
             reason_str
         );

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list