On 07.09.2018 11:46, Victor Stinner wrote:
Le ven. 7 sept. 2018 à 11:02, M.-A. Lemburg mal@egenix.com a écrit :
I think this discussion is a bit misleading.
This is why I'm asking for help to clarify it :-)
Cython allows you to wrap existing C code, but if you want to use Python objects in C or details which are not exposed at the Python level, you still need the Python C API to work with those.
I'm trying to remove functions from the C API which allow to do things which are not possible at the Python level: https://pythoncapi.readthedocs.io/bad_api.html#no-public-c-functions-if-it-c...
It's a request coming from PyPy developers.
There are always things which you have to be able to do at the C level but cannot do at the Python level and that's intentional, since you're working at the C level and want to have direct access to the data, avoiding copying things around all the time and creating intermediate temporary objects or buffers for this.
You also want callbacks to work from both worlds (Python into C and C into Python), or embed the interpreter, or provide new ways of working with the existing objects, or work with code in a way which bypasses the exception machinery (in C you very often raise exceptions and catch them without the exception object itself every being created).
Overall, the C API provides a more low level access to the Python world. This has to be acknowledged. It's not just another way to run Python.
I know I'm stating the obvious, but the Python C API is meant for direct interfacing from Python to C and vice-versa. Since C is a different language with different data types, of course, there are things which you can do with this API and which you cannot do in Python, so the statement "There should not be C APIs that do something that you can’t do in Python." is too broad.
Please don't forget that the Python C API was key in making it so popular for integration. It's generally a very nice API to work with as C programmer.
*I* am well aware of that and I tried to repeat it in my document :-) Since some people like to repeat "Let's just remove the C A API!", I added a new page to explain why it's not possible today: https://pythoncapi.readthedocs.io/remove_c_api.html
The Python C API has grown some warts, definitely, and it could use an overhaul in parts where APIs were added too quickly, without staying within the original design patterns, etc.
That's certainly something which can happen without adding a Cython layer, forcing extension writers to rewrite their extensions.
-- Marc-Andre Lemburg eGenix.com
Professional Python Services directly from the Experts (#1, Sep 07 2018)
Python Projects, Coaching and Consulting ... http://www.egenix.com/ Python Database Interfaces ... http://products.egenix.com/ Plone/Zope Database Interfaces ... http://zope.egenix.com/
::: We implement business ideas - efficiently in both time and costs :::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/