Skip to content

C API: Enable limited C API tests on Free Threading #155561

Description

@vstinner

Currently, the _testlimitedcapi extension module is not built with the limited C API on Free Threading which is misleading and defeats the purpose of this extension.

PEP 803 added Py_TARGET_ABI3T macro to Python 3.15 which makes it possible to build a C extension using the limited C API when using Free Threading. So I propose building _testlimitedcapi using Py_TARGET_ABI3T to test properly the limited C API on Free Threading.

One limitation is that Py_TARGET_ABI3T minimum version is Python 3.15, whereas _testlimitedcapi/<file>.c files target older Python versions. Anyway, we have to only define Py_TARGET_ABI3T on Free Threading, or define Py_LIMITED_API macro otherwise (build with GIL). Example:

#include "pyconfig.h"   // Py_GIL_DISABLED
#ifdef Py_GIL_DISABLED
#  define Py_TARGET_ABI3T 0x030f0000
#else
   // Need limited C API version 3.13 for Py_GetConstant()
#  define Py_LIMITED_API 0x030d0000
#endif

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions