mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
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.
This commit is contained in:
parent
4a7f5a55dc
commit
3ef3c6306d
7 changed files with 137 additions and 25 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue