Skip to content

Commit 24fa983

Browse files
committed
Update for PEP 393.
1 parent d63a3b8 commit 24fa983

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

Tools/gdb/libpython.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
_type_unsigned_char_ptr = gdb.lookup_type('unsigned char').pointer() # unsigned char*
5151
_type_void_ptr = gdb.lookup_type('void').pointer() # void*
5252
_type_size_t = gdb.lookup_type('size_t')
53+
_type_unsigned_short_ptr = gdb.lookup_type('unsigned short').pointer()
54+
_type_unsigned_int_ptr = gdb.lookup_type('unsigned int').pointer()
5355

5456
_is_pep393 = 'data' in [f.name for f in gdb.lookup_type('PyUnicodeObject').target().fields()]
5557

@@ -1124,25 +1126,36 @@ def proxyval(self, visited):
11241126
# From unicodeobject.h:
11251127
# Py_ssize_t length; /* Length of raw Unicode data in buffer */
11261128
# Py_UNICODE *str; /* Raw Unicode buffer */
1127-
field_length = long(self.field('length'))
11281129
if _is_pep393:
11291130
# Python 3.3 and newer
11301131
may_have_surrogates = False
1131-
field_state = long(self.field('state'))
1132-
repr_kind = (field_state & 0xC) >> 2
1133-
if repr_kind == 0:
1132+
compact = self.field('_base')
1133+
ascii = compact['_base']
1134+
state = ascii['state']
1135+
field_length = long(ascii['length'])
1136+
if not int(state['ready']):
11341137
# string is not ready
11351138
may_have_surrogates = True
1136-
field_str = self.field('wstr')
1137-
field_length = self.field('wstr_length')
1138-
elif repr_kind == 1:
1139-
field_str = self.field('data')['latin1']
1140-
elif repr_kind == 2:
1141-
field_str = self.field('data')['ucs2']
1142-
elif repr_kind == 3:
1143-
field_str = self.field('data')['ucs4']
1139+
field_str = ascii['wstr']
1140+
if not int(state['ascii']):
1141+
field_length = compact('wstr_length')
1142+
else:
1143+
if int(state['ascii']):
1144+
field_str = ascii.address + 1
1145+
elif int(state['compact']):
1146+
field_str = compact.address + 1
1147+
else:
1148+
field_str = self.field('data')['any']
1149+
repr_kind = int(state['kind'])
1150+
if repr_kind == 1:
1151+
field_str = field_str.cast(_type_unsigned_char_ptr)
1152+
elif repr_kind == 2:
1153+
field_str = field_str.cast(_type_unsigned_short_ptr)
1154+
elif repr_kind == 3:
1155+
field_str = field_str.cast(_type_unsigned_int_ptr)
11441156
else:
11451157
# Python 3.2 and earlier
1158+
field_length = long(self.field('length'))
11461159
field_str = self.field('str')
11471160
may_have_surrogates = self.char_width() == 2
11481161

0 commit comments

Comments
 (0)