diff options
| author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-05 22:44:12 +0200 | 
|---|---|---|
| committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-05 22:44:12 +0200 | 
| commit | a336de7ae1c9d836265fc053018c0f11fc804b9a (patch) | |
| tree | e5c085e346d20d403fe387121b4c0fcdebb872e1 /Python/traceback.c | |
| parent | 3484c09c97141f497de9f99c5d2135e41fde8a11 (diff) | |
| download | cpython-git-a336de7ae1c9d836265fc053018c0f11fc804b9a.tar.gz | |
traceback: fix dump_ascii() for string with kind=PyUnicode_WCHAR_KIND
Diffstat (limited to 'Python/traceback.c')
| -rw-r--r-- | Python/traceback.c | 16 | 
1 files changed, 13 insertions, 3 deletions
diff --git a/Python/traceback.c b/Python/traceback.c index 9a11bf2df7..b66c96cda6 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -483,7 +483,8 @@ dump_ascii(int fd, PyObject *text)      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 @@ dump_ascii(int fd, PyObject *text)          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 @@ dump_ascii(int fd, PyObject *text)          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);  | 
