[issue39573] [C API] Make PyObject an opaque structure in the limited C API
STINNER Victor
report at bugs.python.org
Wed Nov 18 09:24:55 EST 2020
STINNER Victor <vstinner at python.org> added the comment:
I wrote PR 23366 to revert the Py_TYPE() and Py_SIZE() changes: convert them back to macros to allow again "Py_TYPE(obj) = type;" and "Py_SIZE(obj) = size;" syntaxes.
Miro Hrončok:
> Another batch of broken projects:
> PyPAM https://bugzilla.redhat.com/show_bug.cgi?id=1897264
"Py_TYPE="
> bitarray https://bugzilla.redhat.com/show_bug.cgi?id=1897536
"Py_TYPE=/Py_SIZE="
> boost https://bugzilla.redhat.com/show_bug.cgi?id=1896382
"Py_TYPE="
> duplicity https://bugzilla.redhat.com/show_bug.cgi?id=1896684
"Py_TYPE="
> gobject-introspection https://bugzilla.redhat.com/show_bug.cgi?id=1893194
"Py_TYPE="
> mercurial https://bugzilla.redhat.com/show_bug.cgi?id=1897178
"Py_TYPE=/Py_SIZE="
> pybluez https://bugzilla.redhat.com/show_bug.cgi?id=1897256
"Py_TYPE="
> pygobject3 https://bugzilla.redhat.com/show_bug.cgi?id=1894522
"Py_TYPE="
> pylibacl https://bugzilla.redhat.com/show_bug.cgi?id=1897529
"Py_TYPE="
> pyside2 https://bugzilla.redhat.com/show_bug.cgi?id=1898974
"Py_TYPE="
> rdiff-backup https://bugzilla.redhat.com/show_bug.cgi?id=1898980
"Py_TYPE="
> Those are just the initial set of packages we have discovered so far. I think there will be more.
Well, since the PEP 620 is not accepted, I prefer to revert the Py_TYPE() and the Py_SIZE() changes for now. We should have a wider discussion on how to introduce incompatible changes into the C API before being able to push more incompatible changes which impact a so wide range of C extension modules.
One practical problem is how to estimate the number of broken Python projects to decide if an incompatible change can be introduced or not. When I did early experiment before merging the PR 20290, it seems like only a minority of C extensions rely on "Py_TYPE(obj) = type;" syntax. It's a common pattern to define a type statically. Pseudo-code:
---
PyTypeObject MyType = {...};
PyInit_MyExtension(...)
{
Py_TYPE(&MyType) = ...;
PyType_Ready(&MyType);
...
}
---
"Py_TYPE(&MyType) = ...;" is required since some C compilers don't support setting ob_type directly in the MyType static declaration. The type must be set at runtime.
Also I considered that the change is trivial enough to be accepable. Well, I was wrong, and that's why I'm not proposing to revert thes changes.
About the rationale for introducing C API incompatible changes, see the PEP 620.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39573>
_______________________________________
More information about the Python-bugs-list
mailing list