Skip to content

Set guidelines to add APIs to the limited C API and to the stable ABI #42

@vstinner

Description

@vstinner

Current limited C API guidelines: https://devguide.python.org/developer-workflow/c-api/index.html#limited-api

Last years, when functions were added to the C API, it was common to also add them directly to the limited C API, and so to the stable ABI.

Later, Misc/stable_abi.toml and tests were added: tests fail if an API is added to the limited C API without being added to Misc/stable_abi.toml. Well, it's just to keep Misc/stable_abi.toml consistent, it wasn't really a strict rule to make sure that added APIs were designed with the stable ABI in mind.

Adding an API to the limited C API requires to put a version with an #if, such as:

#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000

Sadly, there is no automated test to check if the version is tested or not, only manual review can catch it. Recent issue: Py_MOD_PER_INTERPRETER_GIL_SUPPORTED.

When new functions are added to the Python C API, should them be added immediately to the limited C API and the stable ABI, as done currently? Or should it be done on a case by case basis? If yes, based on which criteria?

I don't think that we can predict future ABI issues. The best that we can do is to avoid patterns known to cause ABI issues. For example, exposing structure members in the ABI is risky: any structure change is likely to break the ABI. Another example is that PEP 384 – Defining a Stable ABI asks to not use the FILE* type in the limited C API (but file object or file descriptors).

Metadata

Metadata

Assignees

No one assigned

    Labels

    guidelineTo be included in guidelines PEP

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions