Skip to content

Visit the type of instance of heap types if tp_traverse is not implemented #85208

Closed

Description

@vstinner
BPO 41036
Nosy @vstinner, @corona10, @pablogsal, @shihai1991
PRs
  • bpo-41036: Implement object_traverse() #20983
  • Superseder
  • bpo-42972: [C API] Heap types (PyType_FromSpec) must fully implement the GC protocol
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-01-19.21:55:23.027>
    created_at = <Date 2020-06-19.14:05:01.249>
    labels = ['interpreter-core', 'expert-C-API', '3.9', '3.10']
    title = 'Visit the type of instance of heap types if tp_traverse is not implemented'
    updated_at = <Date 2021-01-19.21:55:23.026>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2021-01-19.21:55:23.026>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-01-19.21:55:23.027>
    closer = 'vstinner'
    components = ['Interpreter Core', 'C API']
    creation = <Date 2020-06-19.14:05:01.249>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41036
    keywords = ['patch']
    message_count = 3.0
    messages = ['371884', '384986', '385298']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'corona10', 'pablogsal', 'shihai1991']
    pr_nums = ['20983']
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '42972'
    type = None
    url = 'https://bugs.python.org/issue41036'
    versions = ['Python 3.9', 'Python 3.10']

    Activity

    1. vstinner commented on Jun 19, 2020

      @vstinner
      MemberAuthor

      While reviewing changes of bpo-40077 "Convert static types to PyType_FromSpec()", I noticed that some static types don't implement tp_traverse.

      The doc says:

      Heap-allocated types (...) hold a reference to their type. Their traversal function must therefore either visit Py_TYPE(self), or delegate this responsibility by calling tp_traverse of another heap-allocated type (such as a heap-allocated superclass). If they do not, the type object may not be garbage-collected.
      

      https://docs.python.org/dev/c-api/typeobj.html#c.PyTypeObject.tp_traverse

      Porting to 3.9 says:

      for types that have a custom tp_traverse function, ensure that all custom tp_traverse functions of heap-allocated types visit the object’s type
      

      https://docs.python.org/dev/whatsnew/3.9.html#changes-in-the-c-api

      --

      It seems like converting a static type to a heap allocated type requires to *add* a new tp_traverse function, if it wasn't the case.

      Maybe we can provide a base tp_traverse implementation in the base object type: visit the type if it's a heap type?

      See attached PR.

      See bpo-35810 and bpo-40217 for more information.

    2. vstinner commented on Jan 12, 2021

      @vstinner
      MemberAuthor

      I created a thread on python-dev:
      "Heap types (PyType_FromSpec) must fully implement the GC protocol"
      https://mail.python.org/archives/list/python-dev@python.org/thread/C4ILXGPKBJQYUN5YDMTJOEOX7RHOD4S3/

    3. vstinner commented on Jan 19, 2021

      @vstinner
      MemberAuthor

      I created bpo-42972 instead.

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions