Skip to content

gh-155561: Build most _testlimitedcapi files with Py_TARGET_ABI3T - #155570

Open
vstinner wants to merge 2 commits into
python:mainfrom
vstinner:test_target_abi3t
Open

gh-155561: Build most _testlimitedcapi files with Py_TARGET_ABI3T#155570
vstinner wants to merge 2 commits into
python:mainfrom
vstinner:test_target_abi3t

Conversation

@vstinner

@vstinner vstinner commented Aug 11, 2026

Copy link
Copy Markdown
Member

The following files are not build with Py_TARGET_ABI3T:

  • Modules/_testlimitedcapi.c
  • Modules/_testlimitedcapi/heaptype_relative.c
  • Modules/_testlimitedcapi/vectorcall_limited.c

The following files are not build with Py_TARGET_ABI3T:

* Modules/_testlimitedcapi.c
* Modules/_testlimitedcapi/heaptype_relative.c
* Modules/_testlimitedcapi/vectorcall_limited.c
@vstinner

Copy link
Copy Markdown
Member Author

@encukou @ngoldbaum: Here is a first uncontroversial change to build most of the _testlimitedcapi extension module with Py_TARGET_ABI3T on Free Threading. Would you mind to review it?

If this change lands, I plan to write one or multiple PRs to use Py_TARGET_ABI3T in the 3 remaining files, which will require more work.

The 3.15 branch is frozen for release candidate releases. IMO this change should be backported to 3.15, but it can wait for Python 3.15.1. So I will do that once the 3.15 branch will be unblocked.

@ngoldbaum ngoldbaum left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly nitpicks except maybe the comment in parts.h.

I can confirm that everything works as advertised here and the skipped modules besides parts.h all have nontrivial fixes.

#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
// need limited C API version 3.5 for PyModule_AddFunctions()
#ifdef Py_GIL_DISABLED
// FIXME: use the Py_TARGET_ABI3T

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there are also other nontrivial cases buried in here, but this guard is used in abstract.c, bytearray.c, bytes.c, capsule.c, complex.c, dict.c, eval.c, float.c, pyos.c, run.c, set.c, threadstate.c, tuple.c instead of a per-file guard. It's also not clear to me why you added this skip, I'm able to build correctly if I make this use a limited API builds like e.g. object.c.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the main branch, Py_TARGET_ABI3T macro is not set. So I'm not sure of what you mean when you say "added this skip"?

If I add # define Py_TARGET_ABI3T 0x030f0000 here, Modules/_testlimitedcapi/heaptype_relative.c and Modules/_testlimitedcapi.c fail to build. I would prefer to not have to add #undef Py_TARGET_ABI3T to these files.

As I wrote, anyway, I plan to write follow-up PRs to use Py_TARGET_ABI3T in all _testlimitedcapi C files.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not putting FIXMEs in code; we have the issue tracker for that.

Comment thread Modules/_testlimitedcapi.c Outdated
Comment thread Modules/_testlimitedcapi/version.c Outdated
@vstinner

Copy link
Copy Markdown
Member Author

@ngoldbaum: I tried to address your review. Please review the updated PR.

@encukou encukou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; two details.

Ideally, run buildbots before merging this one.

Comment on lines +1 to +7
#include "pyconfig.h" // Py_GIL_DISABLED
#ifdef Py_GIL_DISABLED
# define Py_TARGET_ABI3T 0x030f0000
#else
// Need limited C API version 3.15 for PyType_FromSlots()
# define Py_LIMITED_API 0x030f0000
#endif

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they're the same we shouldn't need the if.

Suggested change
#include "pyconfig.h" // Py_GIL_DISABLED
#ifdef Py_GIL_DISABLED
# define Py_TARGET_ABI3T 0x030f0000
#else
// Need limited C API version 3.15 for PyType_FromSlots()
# define Py_LIMITED_API 0x030f0000
#endif
// Need limited C API version 3.15 for PyType_FromSlots()
#define Py_LIMITED_API 0x030f0000

(same in sys.c)

#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
// need limited C API version 3.5 for PyModule_AddFunctions()
#ifdef Py_GIL_DISABLED
// FIXME: use the Py_TARGET_ABI3T

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not putting FIXMEs in code; we have the issue tracker for that.

@encukou

encukou commented Aug 12, 2026

Copy link
Copy Markdown
Member

Thanks for doing this!

IMO this change should be backported to 3.15, but it can wait for Python 3.15.1. So I will do that once the 3.15 branch will be unblocked.

As a test-only change, Hugo would probably approve it -- but you're right, it can definitely wait until 3.15.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants