diff Python/traceback.c @ 72710:2a8ccff8f337

traceback: fix dump_ascii() for string with kind=PyUnicode_WCHAR_KIND
author Victor Stinner <victor.stinner@haypocalc.com>
date Wed, 05 Oct 2011 22:44:12 +0200
parents 8beaa9a37387
children 5e33219492bc
line wrap: on
line diff
--- a/Python/traceback.c	Wed Oct 05 22:37:06 2011 +0200
+++ b/Python/traceback.c	Wed Oct 05 22:44:12 2011 +0200
@@ -483,7 +483,8 @@
     Py_ssize_t i, size;
     int truncated;
     int kind;
-    void *data;
+    void *data = NULL;
+    wchar_t *wstr = NULL;
     Py_UCS4 ch;
 
     size = ascii->length;
@@ -494,11 +495,17 @@
         else
             data = ((PyCompactUnicodeObject*)text) + 1;
     }
-    else {
+    else if (kind != PyUnicode_WCHAR_KIND) {
         data = ((PyUnicodeObject *)text)->data.any;
         if (data == NULL)
             return;
     }
+    else {
+        wstr = ((PyASCIIObject *)text)->wstr;
+        if (wstr == NULL)
+            return;
+        size = ((PyCompactUnicodeObject *)text)->wstr_length;
+    }
 
     if (MAX_STRING_LENGTH < size) {
         size = MAX_STRING_LENGTH;
@@ -508,7 +515,10 @@
         truncated = 0;
 
     for (i=0; i < size; i++) {
-        ch = PyUnicode_READ(kind, data, i);
+        if (kind != PyUnicode_WCHAR_KIND)
+            ch = PyUnicode_READ(kind, data, i);
+        else
+            ch = wstr[i];
         if (ch < 128) {
             char c = (char)ch;
             write(fd, &c, 1);