diff options
author | Mark Shannon <mark@hotpy.org> | 2022-08-15 11:29:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-15 11:29:27 (GMT) |
commit | 3ef3c6306def489ba9115f0a8a57ab1e99795a5c (patch) | |
tree | f74aa199f7051f57b4577f9a920cf982766a65b4 /Tools | |
parent | 4a7f5a55dc88c14cef880ae38a96018514ca9d83 (diff) | |
download | cpython-3ef3c6306def489ba9115f0a8a57ab1e99795a5c.zip cpython-3ef3c6306def489ba9115f0a8a57ab1e99795a5c.tar.gz cpython-3ef3c6306def489ba9115f0a8a57ab1e99795a5c.tar.bz2 |
GH-95707: Fix uses of `Py_TPFLAGS_MANAGED_DICT` (GH-95854)
* Make sure that tp_dictoffset is correct with Py_TPFLAGS_MANAGED_DICT is set.
* Avoid traversing managed dict twice when subclassing class with Py_TPFLAGS_MANAGED_DICT set.
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/gdb/libpython.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index d03c637..899cb6c 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -478,13 +478,17 @@ class HeapTypeObjectPtr(PyObjectPtr): dictoffset = int_from_int(typeobj.field('tp_dictoffset')) if dictoffset != 0: if dictoffset < 0: - type_PyVarObject_ptr = gdb.lookup_type('PyVarObject').pointer() - tsize = int_from_int(self._gdbval.cast(type_PyVarObject_ptr)['ob_size']) - if tsize < 0: - tsize = -tsize - size = _PyObject_VAR_SIZE(typeobj, tsize) - dictoffset += size - assert dictoffset % _sizeof_void_p() == 0 + if int_from_int(typeobj.field('tp_flags')) & Py_TPFLAGS_MANAGED_DICT: + assert dictoffset == -1 + dictoffset = -3 * _sizeof_void_p() + else: + type_PyVarObject_ptr = gdb.lookup_type('PyVarObject').pointer() + tsize = int_from_int(self._gdbval.cast(type_PyVarObject_ptr)['ob_size']) + if tsize < 0: + tsize = -tsize + size = _PyObject_VAR_SIZE(typeobj, tsize) + dictoffset += size + assert dictoffset % _sizeof_void_p() == 0 dictptr = self._gdbval.cast(_type_char_ptr()) + dictoffset PyObjectPtrPtr = PyObjectPtr.get_gdb_type().pointer() |