New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C API] Convert a few stdlib extensions to the limited C API (PEP 384) #85283
Comments
|
Python stdlib has around 139 extension modules. Not all of them *need* to use internal C API. I'm interested to try to convert a bunch of them to the limited C API, as part of my work on the PEP-620. IMHO "Eating your own dog food" is a good practice to ensure that the limited C API is usable. Currently, the stdlib has exactly one extension module using the limited C API: the xxlimited module built with Py_LIMITED_API macro defined as 0x03050000 in setup.py. By the way, maybe Py_LIMITED_API should be defined in xxlimited.c, rather than in setup.py. xxlimited.c is not built if Python is built in debug mode. I'm not sure why. The main limitation to use the limited C API for stdlib is Argument Clinic which attempts to always emit the most efficient code, like using the METH_FASTCALL calling convention and use private functions like _PyArg_CheckPositional() or "static _PyArg_Parser _parser". Argument Clinic could be modified to have an option to only use C API of the limited C API. Cython is working on a similar option (restraint emitted code to the limited C API). I already tried to convert stdlib extensions to the limited C API in bpo-39573. I found other issues:
|
|
See also bpo-27499 "PY_SSIZE_T_CLEAN conflicts with Py_LIMITED_API". |
|
Other missing features of the limited C API:
|
|
PyType_FromSpec() doesn't support 11 slots:
https://docs.python.org/dev/c-api/type.html#c.PyType_Slot But it is possible to define tp_weaklistoffset, tp_dictoffset and tp_vectorcall_offset via Py_tp_members slot:
Maybe we can do add new members for the 8 missing slots, especially bf_getbuffer and bf_releasebuffer? commit f7c4e23 of bpo-40724 added Py_bf_getbuffer and Py_bf_releasebuffer slots to the C API, but these slots are still not available in the limited C API: see bpo-10181. |
|
See also bpo-39123: "PyThread_xxx() not available when using limited API". |
|
See also bpo-23903: "Generate PC/python3.def by scraping headers". Steve Dower suggests to convert macros to functions. I'm not sure which functions are still implemented as macro in the limited C API. |
|
See also bpo-16731: "xxlimited/xxmodule docstrings ambiguous". |
|
See also bpo-41073: "[C API] PyType_GetSlot() should accept static types". |
|
See also ./Tools/scripts/abitype.py script and bpo-10943: "abitype: Need better support to port C extension modules to the stable C API". |
|
See also bpo-40077: "Convert static types to PyType_FromSpec()". |
|
See also bpo-29086: "Document C API that is not part of the limited API". |
|
While this might make for an interesting validation experiment, I don't think the results should be checked in. Code churn is to be avoided when there is no visible user benefit. It risks destabilizing code, introducing errors, and making the code less recognizable to the other developers who created and maintained it. |
|
Some related changes in modules: posix, _hashopenssl, _ast (Python-ast.c), zlib, _struct, tkinter, _curses_panel. commit b396663 commit df69e75 commit ac46eb4 commit a1ffad0 commit 4f384af commit d2217a8 commit bc07cb8 |
In bpo-1635741, many extension modules have been ported to the multi-phase initilization API (PEP-489), and many static types have been converted to heap types. |
|
+1. Defining Py_LIMITED_API in xxlimited.c is more direct than in setup.py. so I created the PR-25115. |
|
See also bpo-43688: [C API] Support the limited C API in debug mode (Py_INCREF and Py_DECREF). |
|
The latest commit seems to break the build if configured --with-trace-refs. |
|
I should revise that comment. The xxlimited and xxlimited_35 modules fail to build. That seems suboptimal, but perhaps is to be expected. Perhaps it would be better that compiling them not be attempted with configuring --with-trace-refs? |
+1. The limited C API can't be build under Py_TRACE_REFS now. |
|
Skip Montanaro: "The latest commit seems to break the build if configured --with-trace-refs." Oops, I forgot about this special build mode. Thanks for the reminder Skip, and thanks for the fix Hai ;-) Skip: By the way, I'm curious, why do you use --with-trace-refs? |
I'm still horsing around with register opcodes and got in the habit of |
PR-26080 adds the feature that Argument Clinic to support to use the Limited C API. |
|
METH_VARARGS and METH_KEYWORDS are part of the stable ABI. |
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: