Skip to content

gh-155561: Use PySlot API in Modules/_testlimitedcapi.c - #155693

Open
vstinner wants to merge 3 commits into
python:mainfrom
vstinner:limited_pyslot
Open

gh-155561: Use PySlot API in Modules/_testlimitedcapi.c#155693
vstinner wants to merge 3 commits into
python:mainfrom
vstinner:limited_pyslot

Conversation

@vstinner

@vstinner vstinner commented Aug 13, 2026

Copy link
Copy Markdown
Member

@vstinner

Copy link
Copy Markdown
Member Author

I hesitated to keep PyMethodDef and PyModuleDef code path when the Py_GIL_DISABLED macro is not defined, but this API is already tested by Modules/xxlimited_3_13.c. IMO it's better and simpler to use PySlot in both case (if Py_GIL_DISABLED is defined or not).

cc @encukou

Comment thread Modules/_testlimitedcapi.c
@vstinner

Copy link
Copy Markdown
Member Author

Oh. The build fails on WASI because Modules/config.c refers to PyModExport__testlimitedcapi() which doesn't exist.

wasm-ld: error: Modules/config.o: undefined symbol: PyInit__testlimitedcapi

and

error: undefined symbol: PyInit__testlimitedcapi (referenced by root reference (e.g. compiled C/C++ code))

Modules/config.c is generated Modules/config.c.in by Modules/makesetup.

I tried adding PyInit__testlimitedcapi() by calling PyModule_FromSlotsAndSpec() with NULL spec, but this function does crash. The spec argument must be non-NULL.

// Provide a PyInit function for Modules/config.c when _testlimitedcapi 
// extension module is built as a built-in module (ex: on WASI and Emscripten).
PyMODINIT_FUNC      
PyInit__testlimitedcapi(void)
{      
    return PyModule_FromSlotsAndSpec(_testlimitedcapimodule_slots, NULL);
}

@vstinner

Copy link
Copy Markdown
Member Author

I modified PyModule_FromSlotsAndSpec() to get the module name from slots, but this approach doesn't work. Later, the Tools/build/check_extension_modules.py scripts raises SystemError: initialization of _testlimitedcapi did not return a valid extension module error because _testlimitedcapi has no "def": _PyModule_GetDefOrNull() returns NULL.

@vstinner

Copy link
Copy Markdown
Member Author

Another approach would be to add a variant of _PyRuntime.imports.inittab for "export functions" (PyMODEXPORT_FUNC). We should add a struct _inittab variant where the initfunc returns PySlot*.

@encukou

encukou commented Aug 14, 2026

Copy link
Copy Markdown
Member

Let's keep PyModuleDef, but switch to multi-phase init? See https://github.com/python/cpython/compare/main...encukou:cpython:limited_pyslot?expand=1

We should add a struct _inittab variant where the initfunc returns PySlot*.

That's might be PEP-sized :)

@vstinner

Copy link
Copy Markdown
Member Author

Let's keep PyModuleDef, but switch to multi-phase init? See https://github.com/python/cpython/compare/main...encukou:cpython:limited_pyslot?expand=1

Please go ahead and propose a PR if you think that it's the right approach. I will be on holiday for next 2 weeks anyway.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants