Skip to content

Add PyHeap_GetType() to limited C API to get the value of ht_type from heap types using PyObject pointer. #128351

@AraHaan

Description

@AraHaan

Feature or enhancement

Proposal:

Currently on the Limited C API one can use PyType_FromSpec() using a spec for a type to obtain a special heap type object. However, in order to then call PyModule_AddObject to bind the resulting type object created from this to the module one must first access the PyHeapTypeObject structure which is sadly not defined at all, nor any of it's members when using the limited C API.

The only workaround for this would be a new PyHeap_GetType() to obtain the value (PyTypeObject *) from the input PyHeapTypeObject as a PyObject * without first casting the result from PyType_FromSpec to PyHeapTypeObject. The result is then better usage in C extensions wanting to use the limited API but cannot due to this limitation.

Alternatives as well:

  • A copy of PyType_FromSpec for the limited API that takes in the module object (PyObject *) and calls the PyModule_AddObject function for the user so they never need to worry about heap type object stuffs.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

I seen discussions about allowing PyHeapTypeObject in C extensions on GitHub in the past, but no idea how far the progress is currently on that. I think having PyHeap_GetType or whatever name of a function it could be and/or a function that internally calls PyType_FromSpec AND PyModule_AddObject for C extension developers exposed to the C API could work as well.

See also: #105970 (there could be more)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions