Skip to content

Manage memory lifetime for all type-related objects. #81451

Open

Description

@llllllllll
BPO 37270
Nosy @llllllllll
PRs
  • gh-81451: Manage memory lifetime for all type-related objects. #14066
  • 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 = None
    created_at = <Date 2019-06-13.21:31:34.693>
    labels = ['extension-modules', '3.9']
    title = 'Manage memory lifetime for all type-related objects.'
    updated_at = <Date 2019-06-13.21:33:06.241>
    user = 'https://github.com/llllllllll'

    bugs.python.org fields:

    activity = <Date 2019-06-13.21:33:06.241>
    actor = 'llllllllll'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Extension Modules']
    creation = <Date 2019-06-13.21:31:34.693>
    creator = 'llllllllll'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37270
    keywords = ['patch']
    message_count = 1.0
    messages = ['345539']
    nosy_count = 1.0
    nosy_names = ['llllllllll']
    pr_nums = ['14066']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue37270'
    versions = ['Python 3.9']

    Activity

    1. llllllllll commented on Jun 13, 2019

      llllllllllmannequin
      MannequinAuthor

      When using PyType_FromSpec, the memory for PyType_Spec.name, Py_tp_methods, and Py_tp_members needs to somehow outlive the resulting type. This makes it hard to use this interface to generate types without just leaking the memory for these arrays, which is bad if you are programatically creating short-lived types.

      I posted about this on capi-sig, and the response seemed to be that it would be to replace the things that currently hold pointers into the array with copies of the data.

      Remove internal usages of PyMethodDef and PyGetSetDef.

      For PyMethodDef, change PyCFunctionObject to replace the PyMethodDef* member
      with a PyCFunctionBase member. The PyCFunctionBase is a new struct to hold the
      managed values of a PyMethodDef. This type is shared between PyCFunction and the
      various callable descriptor objects. A PyCFunctionBase is like a PyMethodDef but
      replaces the char* members with PyObject* members.

      For PyGetSetDef, inline the members on the resulting PyGetSetDescrObject,
      replacing all char* members with PyObject* members. The memory for the closure
      is *not* managed, adding support for that would likely require an API change and
      can be done in a future change.

      For the tp_name field, instead of setting it directly to the value of
      PyType_Spec.name, set it to the result of PyUnicode_AsUTF8(ht_name), where
      ht_name is the PyUnicode object created from the original spec name. This is the
      same trick used to properly manage this pointer for heap types when the __name__
      is reassigned.

    2. added
      3.9 (EOL)
      extension-modules
      on Jun 13, 2019
    3. 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

      Labels

      3.9 (EOL)extension-modules

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions