traceback: fix dump_ascii() for string with kind=PyUnicode_WCHAR_KIND
This commit is contained in:
parent
3484c09c97
commit
a336de7ae1
|
@ -483,7 +483,8 @@ dump_ascii(int fd, PyObject *text)
|
||||||
Py_ssize_t i, size;
|
Py_ssize_t i, size;
|
||||||
int truncated;
|
int truncated;
|
||||||
int kind;
|
int kind;
|
||||||
void *data;
|
void *data = NULL;
|
||||||
|
wchar_t *wstr = NULL;
|
||||||
Py_UCS4 ch;
|
Py_UCS4 ch;
|
||||||
|
|
||||||
size = ascii->length;
|
size = ascii->length;
|
||||||
|
@ -494,11 +495,17 @@ dump_ascii(int fd, PyObject *text)
|
||||||
else
|
else
|
||||||
data = ((PyCompactUnicodeObject*)text) + 1;
|
data = ((PyCompactUnicodeObject*)text) + 1;
|
||||||
}
|
}
|
||||||
else {
|
else if (kind != PyUnicode_WCHAR_KIND) {
|
||||||
data = ((PyUnicodeObject *)text)->data.any;
|
data = ((PyUnicodeObject *)text)->data.any;
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
wstr = ((PyASCIIObject *)text)->wstr;
|
||||||
|
if (wstr == NULL)
|
||||||
|
return;
|
||||||
|
size = ((PyCompactUnicodeObject *)text)->wstr_length;
|
||||||
|
}
|
||||||
|
|
||||||
if (MAX_STRING_LENGTH < size) {
|
if (MAX_STRING_LENGTH < size) {
|
||||||
size = MAX_STRING_LENGTH;
|
size = MAX_STRING_LENGTH;
|
||||||
|
@ -508,7 +515,10 @@ dump_ascii(int fd, PyObject *text)
|
||||||
truncated = 0;
|
truncated = 0;
|
||||||
|
|
||||||
for (i=0; i < size; i++) {
|
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) {
|
if (ch < 128) {
|
||||||
char c = (char)ch;
|
char c = (char)ch;
|
||||||
write(fd, &c, 1);
|
write(fd, &c, 1);
|
||||||
|
|
Loading…
Reference in New Issue