Skip to content

Add PyObject_GetItemData() and PyObject_GetItemData_DuringGC() to the stable ABI #103

@vstinner

Description

@vstinner

Functions requested by @wjakob who works on nanobind. Copy/paste of PR python/cpython#148324 description.


This PR promotes PyObject_GetItemData() and PyObject_GetItemData_DuringGC() to the stable ABI (analogous to PyObject_GetTypeData() and PyObject_GetTypeData_DuringGC() that are already in the stable ABI).

The function PyObject_GetItemData() is needed to access the entries of variable sized objects (PyVarObject).

Why this change?

  • PyVarObject becomes opaque in abi3t.
  • nanobind (used by large-scale ML and compiler projects like Google's JAX, Apple's MLX, LLVM, MLIR, ...) uses a variable sized function object
  • Ergo: without access to PyObject_GetItemData(), nanobind cannot run on abi3t.

The function was added by PEP 697 "Limited C API for Extending Opaque Types" to Python 3.12. The function is documented and tested (by test_capi.test_misc). IMO it makes sense to add it to the stable ABI. Without this function, it's not possible to access data of PyVarObject objects in the stable ABI.

Vote:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions