summaryrefslogtreecommitdiffstats
path: root/Tools/gdb
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-09-08 21:57:37 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-09-08 21:57:37 (GMT)
commit7c9cf01238cdfb597041d12e71d5a11a98402b34 (patch)
treeaefbf95baaf6c169e0c256261e742547610e1b3f /Tools/gdb
parentb1856d7fa74e045473a530197a0dedd9052a5e95 (diff)
downloadcpython-7c9cf01238cdfb597041d12e71d5a11a98402b34.zip
cpython-7c9cf01238cdfb597041d12e71d5a11a98402b34.tar.gz
cpython-7c9cf01238cdfb597041d12e71d5a11a98402b34.tar.bz2
gdb: fix representation of non-printable surrogate pairs, and workaround
a bug in ascii().
Diffstat (limited to 'Tools/gdb')
-rw-r--r--Tools/gdb/libpython.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py
index 361fb03..8a69803 100644
--- a/Tools/gdb/libpython.py
+++ b/Tools/gdb/libpython.py
@@ -1171,9 +1171,8 @@ class PyUnicodeObjectPtr(PyObjectPtr):
# Non-ASCII characters
else:
ucs = ch
- orig_ucs = None
ch2 = None
- if self.char_width() == 2:
+ if sys.maxunicode < 0x10000:
# If sizeof(Py_UNICODE) is 2 here (in gdb), join
# surrogate pairs before calling _unichr_is_printable.
if (i < len(proxy)
@@ -1183,22 +1182,26 @@ class PyUnicodeObjectPtr(PyObjectPtr):
ucs = ch + ch2
i += 1
+ # Unfortuately, Python 2's unicode type doesn't seem
+ # to expose the "isprintable" method
printable = _unichr_is_printable(ucs)
if printable:
try:
ucs.encode(ENCODING)
except UnicodeEncodeError:
printable = False
- if orig_ucs is not None:
- ucs = orig_ucs
- i -= 1
# Map Unicode whitespace and control characters
# (categories Z* and C* except ASCII space)
if not printable:
- # Unfortuately, Python 2's unicode type doesn't seem
- # to expose the "isprintable" method
- code = ord(ucs)
+ if ch2 is not None:
+ # Match Python 3's representation of non-printable
+ # wide characters.
+ code = (ord(ch) & 0x03FF) << 10
+ code |= ord(ch2) & 0x03FF
+ code += 0x00010000
+ else:
+ code = ord(ucs)
# Map 8-bit characters to '\\xhh'
if code <= 0xff: