Le mer. 19 juin 2019 à 12:03, Jeroen Demeyer <J.Demeyer@ugent.be> a écrit :
On 2019-06-19 11:43, Victor Stinner wrote:
The current trend is to *reduce* the size of the C API rather than making it larger. http://pythoncapi.readthedocs.io/
You speak of "the C API" but what do you mean really? I know that you care mostly about the limited API/stable ABI, but I personally care mostly about the default API (when neither Py_LIMITED_API not Py_BUILD_CORE is defined).
Which API does PyPy care about?
The API used by C extension.
Apart PyQt, I'm not aware of any C extension using the limited ABI (stable ABI).
You always say that you don't want C extensions to access implementation details. But in some other thread (I don't recall precisely where) I argued that C extensions access implementation details because they are missing a C API function doing what they need. This is certainly true for Cython. So if you want to fix that, we should rather *increase* our C API to allow clean access to those implementation details.
This problem is hard and that's why it's not fixed yet :-) It's a work-in-progress.
My advice would be to require a discussion before adding a new function. Previously, we added functions without thinking if it makes sense outside CPython or not, simply because there was no clear separation between the "public" and the "private" API.
I introduced a clear separation in Python 3.8: https://docs.python.org/3.8/whatsnew/3.8.html#build-and-c-api-changes
Now we can only add a function to the *internal* C API if it must only be used inside CPython. We can "experiment" new functions there before exposing them in the public API or the private API.
Today I removed one more function from the C API :-) PyImport_Cleanup().
Another example:
commit 0a28f8d379544eee897979da0ce99f0b449b49dd Author: Victor Stinner <vstinner@redhat.com> Date: Wed Jun 19 02:54:39 2019 +0200
bpo-36710: Add tstate parameter in import.c (GH-14218)
* Add 'tstate' parameter to many internal import.c functions.
* _PyImportZip_Init() now gets 'tstate' parameter rather than
'interp'.
* Add 'interp' parameter to _PyState_ClearModules() and rename it
to _PyInterpreterState_ClearModules().
* Move private _PyImport_FindBuiltin() to the internal C API; add
'tstate' parameter to it.
* Remove private _PyImport_AddModuleObject() from the C API:
use public PyImport_AddModuleObject() instead.
* Remove private _PyImport_FindExtensionObjectEx() from the C API:
use private _PyImport_FindExtensionObject() instead.
_PyImport_AddModuleObject() and _PyImport_FindExtensionObjectEx() were added to the C API because they were used outside import.c, not because it makes sense to use them outside CPython.
Previously, technically, these functions were exported even if their name is prefixed by "_Py". Exposing these functions cause issues inside CPython, because I wanted to modify them to pass a new "tstate" parameter and so change their API. Hopefully, they are private so we are free to break their API ;-)
Victor
Night gathers, and now my watch begins. It shall not end until my death.