Skip to content

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

Open
encukou wants to merge 9 commits into
python:mainfrom
encukou:limited_pyslot
Open

gh-155561: Use multi-phase init for Modules/_testlimitedcapi.c#156052
encukou wants to merge 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!

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

Labels

awaiting merge skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants