On 5 Sep 2018, at 00:17, Victor Stinner vstinner@redhat.com wrote:
Le mer. 5 sept. 2018 à 00:12, Jeroen Demeyer J.Demeyer@ugent.be a écrit :
On 2018-09-04 23:50, Victor Stinner wrote:
I would like to design a new C API without borrow references. So Py_TYPE() should go, replaced by something else.
I don't see the problem with Py_TYPE(). Consider it an accessor macro, just a nice way to access to ob_type field.
I'm trying to design an API which allows to remove the ob_type field from PyObject. I would to do that for many reasons. I wrote a whole website to explain why: https://pythoncapi.readthedocs.io/
In short:
- Leaking ob_field prevents to compile a C extension to the stable ABI
- Accessing directly ob_field prevents to change the structure and so experiment optimizations
- Accessing directly ob_field by derefering pointers expect that a pointer can be dereference which prevents to used tagged pointers
All of these are unrelated to borrowed references. Conceptually every instance owns a reference to its type, regardless of how and where that reference is stored, and it should be possible to return a borrowed reference.
The current ("old") C API prevents to experiment many optimizations (in CPython or CPython forks), make cpyext of PyPy inefficient, and make it really hard to write a new Python implementation which supports the C API.
As others have mentioned before it is unclear if your plans w.r.t. creating a new API will help in this regard.
Ronald