Update for PEP 393.
This commit is contained in:
parent
d63a3b8beb
commit
24fa9832be
|
@ -50,6 +50,8 @@ _type_char_ptr = gdb.lookup_type('char').pointer() # char*
|
||||||
_type_unsigned_char_ptr = gdb.lookup_type('unsigned char').pointer() # unsigned char*
|
_type_unsigned_char_ptr = gdb.lookup_type('unsigned char').pointer() # unsigned char*
|
||||||
_type_void_ptr = gdb.lookup_type('void').pointer() # void*
|
_type_void_ptr = gdb.lookup_type('void').pointer() # void*
|
||||||
_type_size_t = gdb.lookup_type('size_t')
|
_type_size_t = gdb.lookup_type('size_t')
|
||||||
|
_type_unsigned_short_ptr = gdb.lookup_type('unsigned short').pointer()
|
||||||
|
_type_unsigned_int_ptr = gdb.lookup_type('unsigned int').pointer()
|
||||||
|
|
||||||
_is_pep393 = 'data' in [f.name for f in gdb.lookup_type('PyUnicodeObject').target().fields()]
|
_is_pep393 = 'data' in [f.name for f in gdb.lookup_type('PyUnicodeObject').target().fields()]
|
||||||
|
|
||||||
|
@ -1124,25 +1126,36 @@ class PyUnicodeObjectPtr(PyObjectPtr):
|
||||||
# From unicodeobject.h:
|
# From unicodeobject.h:
|
||||||
# Py_ssize_t length; /* Length of raw Unicode data in buffer */
|
# Py_ssize_t length; /* Length of raw Unicode data in buffer */
|
||||||
# Py_UNICODE *str; /* Raw Unicode buffer */
|
# Py_UNICODE *str; /* Raw Unicode buffer */
|
||||||
field_length = long(self.field('length'))
|
|
||||||
if _is_pep393:
|
if _is_pep393:
|
||||||
# Python 3.3 and newer
|
# Python 3.3 and newer
|
||||||
may_have_surrogates = False
|
may_have_surrogates = False
|
||||||
field_state = long(self.field('state'))
|
compact = self.field('_base')
|
||||||
repr_kind = (field_state & 0xC) >> 2
|
ascii = compact['_base']
|
||||||
if repr_kind == 0:
|
state = ascii['state']
|
||||||
|
field_length = long(ascii['length'])
|
||||||
|
if not int(state['ready']):
|
||||||
# string is not ready
|
# string is not ready
|
||||||
may_have_surrogates = True
|
may_have_surrogates = True
|
||||||
field_str = self.field('wstr')
|
field_str = ascii['wstr']
|
||||||
field_length = self.field('wstr_length')
|
if not int(state['ascii']):
|
||||||
elif repr_kind == 1:
|
field_length = compact('wstr_length')
|
||||||
field_str = self.field('data')['latin1']
|
else:
|
||||||
elif repr_kind == 2:
|
if int(state['ascii']):
|
||||||
field_str = self.field('data')['ucs2']
|
field_str = ascii.address + 1
|
||||||
elif repr_kind == 3:
|
elif int(state['compact']):
|
||||||
field_str = self.field('data')['ucs4']
|
field_str = compact.address + 1
|
||||||
|
else:
|
||||||
|
field_str = self.field('data')['any']
|
||||||
|
repr_kind = int(state['kind'])
|
||||||
|
if repr_kind == 1:
|
||||||
|
field_str = field_str.cast(_type_unsigned_char_ptr)
|
||||||
|
elif repr_kind == 2:
|
||||||
|
field_str = field_str.cast(_type_unsigned_short_ptr)
|
||||||
|
elif repr_kind == 3:
|
||||||
|
field_str = field_str.cast(_type_unsigned_int_ptr)
|
||||||
else:
|
else:
|
||||||
# Python 3.2 and earlier
|
# Python 3.2 and earlier
|
||||||
|
field_length = long(self.field('length'))
|
||||||
field_str = self.field('str')
|
field_str = self.field('str')
|
||||||
may_have_surrogates = self.char_width() == 2
|
may_have_surrogates = self.char_width() == 2
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue