Skip to content

gh-155561: Use multi-phase init for Modules/_testlimitedcapi.c - #156052

Merged
encukou merged 9 commits into
python:mainfrom
encukou:limited_pyslot
Sep 4, 2026
Merged

encukou merged 9 commits into
python:mainfrom
encukou:limited_pyslot

Conversation

@encukou

@encukou encukou commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

This is a continuation of #155693

We can't use PyModExport for modules that might be in inittab, but we can move to multi-phase init.

@vstinner

Copy link
Copy Markdown
Member

According to CIs, building _testlimitedcapi fails on Free Threading:

./Modules/_testlimitedcapi.c:103:5: error: use of undeclared identifier 'PyModuleDef_HEAD_INIT'
  103 |     PyModuleDef_HEAD_INIT,
      |     ^~~~~~~~~~~~~~~~~~~~~
./Modules/_testlimitedcapi.c:102:27: error: variable has incomplete type 'struct PyModuleDef'
  102 | static struct PyModuleDef _testlimitedcapimodule_def = {
      |                           ^
./Include/pytypedefs.h:12:16: note: forward declaration of 'struct PyModuleDef'
   12 | typedef struct PyModuleDef PyModuleDef;
      |                ^
2 errors generated.

Comment thread Modules/_testlimitedcapi.c Outdated
// Use the oldest limited C API version
# define Py_LIMITED_API 0x03020000
#endif
// Need limited C API version 3.15 for PySlot

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.

PySlot is not used. I suppose that this comment is outdated.

@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 3, 2026
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit 009ce74 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F156052%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 3, 2026
@vstinner

vstinner commented Sep 3, 2026

Copy link
Copy Markdown
Member

The Alpine Linux buildbot failure looks like a legit bug, but it's unrelated to this change:

  /usr/lib/ccache/bin/g++ -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-strict-overflow -Wsign-compare -g -Og -Wall -fPIC -I/buildbot/buildarea/pull_request.ware-alpine.nogil/build/build/test_python_92877æ/tempcwd/env/include -I/buildbot/buildarea/pull_request.ware-alpine.nogil/build/Include -I/buildbot/buildarea/pull_request.ware-alpine.nogil/build -c extension.cpp -o build/temp.linux-x86_64-cpython-316t-pydebug/extension.o -Werror -DMODULE_NAME=_testcppext_internal -DTEST_INTERNAL_C_API=1
  In file included from /buildbot/buildarea/pull_request.ware-alpine.nogil/build/Include/internal/pycore_object.h:13,
                   from /buildbot/buildarea/pull_request.ware-alpine.nogil/build/Include/internal/pycore_cell.h:5,
                   from extension.cpp:29:
  /buildbot/buildarea/pull_request.ware-alpine.nogil/build/Include/internal/pycore_interpframe.h: In function 'PyFrameObject* _PyFrame_GetFrameObject(_PyInterpreterFrame*)':
  /buildbot/buildarea/pull_request.ware-alpine.nogil/build/Include/internal/pycore_pyatomic_ft_wrappers.h:33:32: error: invalid conversion from 'void*' to 'PyFrameObject*' {aka '_frame*'} [-fpermissive]
     33 |     _Py_atomic_load_ptr_acquire(&value)
        |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
        |                                |
        |                                void*
  /buildbot/buildarea/pull_request.ware-alpine.nogil/build/Include/internal/pycore_interpframe.h:348:26: note: in expansion of macro 'FT_ATOMIC_LOAD_PTR_ACQUIRE'
    348 |     PyFrameObject *res = FT_ATOMIC_LOAD_PTR_ACQUIRE(frame->frame_obj);
        |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~
  error: command '/usr/lib/ccache/bin/g++' failed with exit code 1

@vstinner

vstinner commented Sep 3, 2026

Copy link
Copy Markdown
Member

The Alpine Linux buildbot failure looks like a legit bug, but it's unrelated to this change:

Ah, in fact the AMD64 Alpine Linux NoGIL 3.x buildbot already fails on the main branch: I wrote PR gh-156893 to fix the issue.

@vstinner

vstinner commented Sep 3, 2026

Copy link
Copy Markdown
Member

The "buildbot/AMD64 CentOS9 NoGIL PR" failure is the same as the Alpine Linux issue: test_cppext fails, so PR #156893 will fix it.

@vstinner vstinner 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.

LGTM.

This change doesn't build Modules/_testlimitedcapi.c with the limited C API on Free Threading yet, but it converts the module to multi-phase init which is already a good step forwards!

@encukou
encukou merged commit 112560e into python:main Sep 4, 2026
132 of 136 checks passed
@encukou
encukou deleted the limited_pyslot branch September 4, 2026 10:35
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
vstinner added a commit that referenced this pull request Oct 10, 2026
…I3T (#155570) (#159144)

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

The following files are not build with Py_TARGET_ABI3T:

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

(cherry picked from commit 5dfa606)

* gh-155561: Use multi-phase init for Modules/_testlimitedcapi.c (GH-156052)

Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 112560e)

---------

Co-authored-by: Petr Viktorin <encukou@gmail.com>
@vstinner vstinner added the needs backport to 3.15 bugs and security fixes label Oct 13, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @encukou, I could not cleanly backport this to 3.15 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 112560ee34a70c02baebdc11519d1f77e90ecab8 3.15

@vstinner vstinner removed the needs backport to 3.15 bugs and security fixes label Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants