python / python/cpython

Promote `PyUnstable_Object_GC_NewWithExtraData()` to the stable API

Open
#148,498 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core topic-C-API type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

Allocating variable sized Python objects via the C API is a genuinely useful operation. It is e.g. needed to

  • implement custom data structures (tuples, lists)
  • implement binding libraries (like nanobind) that co-locate binding data structures with Python objects

So far, the standard way to create them was via PyVarObject, and this was supported even in stable ABI builds. Unfortunately, this data structure becomes inaccessible with the upcoming free-threaded flavor of the stable ABI.

I would like to propose that the function PyUnstable_Object_GC_NewWithExtraData() be promoted to the stable API to provide an escape hatch for extensions that require variable sized objects in abi3t. This will enable extensions to implement variable sized objects without depending on the specifics of PyVarObject.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-148499

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the C API documentation for PyUnstable_Object_GC_NewWithExtraData() and the issue's discussion of PyVarObject, free-threaded builds, and the stable ABI. The work is done when this function is promoted to the stable API and extensions can use it for variable-sized objects in abi3t.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.