Skip to content

tp_dictoffset and Py_TPFLAGS_MANAGED_DICT can get out of sync with multiple inheritance in C extensions using PyType_FromSpecWithBases #108595

Open
@dlech

Description

@dlech

Bug report

Checklist

  • I am confident this is a bug in CPython, not a bug in a third-party project
  • I have searched the CPython issue tracker,
    and am confident this bug has not been reported before

CPython versions tested on:

3.11, 3.12

Operating systems tested on:

Windows

Output from running 'python -VV' on the command line:

No response

A clear and concise description of the bug:

Background: I am working on a Python C Extension that creates new types using PyType_FromMetaclass (PyType_FromModuleAndSpec in Python < 3.12) and ran into an assertions error at

assert(dictoffset != -1);

So I fired up the debugger to find out where tp_dictoffset is getting set to -1 (my extension isn't doing anything explicitly with this). I found the culprit at

COPYSLOT(tp_dictoffset);

This type inherits from another C extension type and a type implemented in Python. The type implemented in Python has tp_dictoffset set to -1 and it is being copied to the new type.

In other cases in the file where tp_dictoffset is explicitly set to -1, Py_TPFLAGS_MANAGED_DICT is also set. This fact combined with the the fact that other slot assignments in inherit_slots() also set flags when needed make me thing that perhaps this one was overlooked?

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions