mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
gdb: fix representation of non-printable surrogate pairs, and workaround
a bug in ascii().
This commit is contained in:
parent
b1856d7fa7
commit
7c9cf01238
2 changed files with 14 additions and 9 deletions
|
@ -234,7 +234,9 @@ class PrettyPrintTests(DebuggerTests):
|
||||||
text.encode(encoding)
|
text.encode(encoding)
|
||||||
printable = True
|
printable = True
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
self.assertGdbRepr(text, ascii(text))
|
# Workaround ascii() bug on UCS-2 builds: issue #9804
|
||||||
|
asc = "'" + text.encode('unicode-escape').decode('ascii') + "'"
|
||||||
|
self.assertGdbRepr(text, asc)
|
||||||
else:
|
else:
|
||||||
self.assertGdbRepr(text)
|
self.assertGdbRepr(text)
|
||||||
|
|
||||||
|
|
|
@ -1171,9 +1171,8 @@ class PyUnicodeObjectPtr(PyObjectPtr):
|
||||||
# Non-ASCII characters
|
# Non-ASCII characters
|
||||||
else:
|
else:
|
||||||
ucs = ch
|
ucs = ch
|
||||||
orig_ucs = None
|
|
||||||
ch2 = None
|
ch2 = None
|
||||||
if self.char_width() == 2:
|
if sys.maxunicode < 0x10000:
|
||||||
# If sizeof(Py_UNICODE) is 2 here (in gdb), join
|
# If sizeof(Py_UNICODE) is 2 here (in gdb), join
|
||||||
# surrogate pairs before calling _unichr_is_printable.
|
# surrogate pairs before calling _unichr_is_printable.
|
||||||
if (i < len(proxy)
|
if (i < len(proxy)
|
||||||
|
@ -1183,22 +1182,26 @@ class PyUnicodeObjectPtr(PyObjectPtr):
|
||||||
ucs = ch + ch2
|
ucs = ch + ch2
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
# Unfortuately, Python 2's unicode type doesn't seem
|
||||||
|
# to expose the "isprintable" method
|
||||||
printable = _unichr_is_printable(ucs)
|
printable = _unichr_is_printable(ucs)
|
||||||
if printable:
|
if printable:
|
||||||
try:
|
try:
|
||||||
ucs.encode(ENCODING)
|
ucs.encode(ENCODING)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
printable = False
|
printable = False
|
||||||
if orig_ucs is not None:
|
|
||||||
ucs = orig_ucs
|
|
||||||
i -= 1
|
|
||||||
|
|
||||||
# Map Unicode whitespace and control characters
|
# Map Unicode whitespace and control characters
|
||||||
# (categories Z* and C* except ASCII space)
|
# (categories Z* and C* except ASCII space)
|
||||||
if not printable:
|
if not printable:
|
||||||
# Unfortuately, Python 2's unicode type doesn't seem
|
if ch2 is not None:
|
||||||
# to expose the "isprintable" method
|
# Match Python 3's representation of non-printable
|
||||||
code = ord(ucs)
|
# wide characters.
|
||||||
|
code = (ord(ch) & 0x03FF) << 10
|
||||||
|
code |= ord(ch2) & 0x03FF
|
||||||
|
code += 0x00010000
|
||||||
|
else:
|
||||||
|
code = ord(ucs)
|
||||||
|
|
||||||
# Map 8-bit characters to '\\xhh'
|
# Map 8-bit characters to '\\xhh'
|
||||||
if code <= 0xff:
|
if code <= 0xff:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue