Hi Simon and Matti,
Making all C structures of Python opaque is a long term goal and it cannot be done in a single step.
Converting macros to static inline functions prepares the C API for opaque function calls, like: PyTypeObject* Py_TYPE(PyObject *op). In CPython, we can likely keep static inline functions (for best performance).
The advantage of using static inline functions is that other Python implementations have more freedom on how they implement Py_TYPE() and Py_SET_TYPE(). They don't have to implement Python objects exactly the same way than CPython does anymore.
Currently, it's simply impossible to implement the Python C API without copying CPython PyObject structure.
For me, the short term goal is to put abstractions on all ways to access Python objects: no longer access directly structure members, but only go through macro, static inline functions, or functions.
In Python 3.9, I addd PyFrame_GetBack() getter function to abstract access to PyFrameObject.f_back. In Python 3.11, if you don't use this function, your C extension will simply break since the PyFrameObject.f_back attribute has been removed. This removal is motivated by optimizing CPython.
We cannot evolve Python (fix bugs, optimize it) without this annoying work of fixing the C API: add more abstractions on top of C structures.
Victor
On Thu, Sep 9, 2021 at 1:12 AM Simon Cross <hodgestar@gmail.com> wrote:
On Wed, Sep 8, 2021 at 11:50 PM Matti Picus <matti.picus@gmail.com> wrote:
How does this change move the needle on that goal? The macros become static inline functions defined in the C headers. Nothing changes in the C struct itself.
Agreed. My point is that at the level of the C code itself there *is* a function Py_SET_TYPE(obj, type) that needs to be called and one can't just write "Py_TYPE(obj) = type" which effectively limits how setting a type works to a very particular implementation.
Yes, this change by itself doesn't make PyType completely opaque, but that is the direction that Victor is trying to head in I believe.
capi-sig mailing list -- capi-sig@python.org To unsubscribe send an email to capi-sig-leave@python.org https://mail.python.org/mailman3/lists/capi-sig.python.org/ Member address: vstinner@python.org
-- Night gathers, and now my watch begins. It shall not end until my death.