python / python/cpython

C API: Enable limited C API tests on Free Threading

Open
#155,561 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

tests topic-C-API
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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
  • gh-155570
  • gh-155693
  • gh-156052

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 with the _testlimitedcapi/.c sources and the pyconfig.h macros described in the issue, then inspect how _testlimitedcapi is built for Free Threading. Check the limited C API tests under the _testlimitedcapi extension and confirm they build and run with Py_TARGET_ABI3T on Free Threading while retaining Py_LIMITED_API for GIL builds.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.