The PEP 573 was accepted and implemented in Python 3.9. It adds a new METH_METHOD flag which pass the "defining class".
For example, the zlib.Decompress.decompress() function gets this flag by using the new defining_class parameter type in its Argument Clinic definition in Python 3.10:
/*[clinic input]
zlib.Decompress.decompress
cls: defining_class
data: Py_buffer
The binary data to decompress.
/
max_length: Py_ssize_t = 0
The maximum allowable length of the decompressed data.
Unconsumed input data will be stored in
the unconsumed_tail attribute.
(...)
[clinic start generated code]*/
It generates the following calling convention:
#define ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF \
{"decompress", (PyCFunction)(void(*)(void))zlib_Decompress_decompress, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zlib_Decompress_decompress__doc__},
static PyObject *
zlib_Decompress_decompress(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
(...)
}
Notice the second parameter: PyTypeObject *cls.
It seems like __Pyx_PyObject_CallOneArg() doesn't support this new calling convention and simply treat the function as the "fastcall" calling convention. It does not pass the defining type.
As a consequence, zlib_Decompress_decompress() does crash when parsing its arguments.
See https://bugzilla.redhat.com/show_bug.cgi?id=1898157 for a concrete example in scipy.
I tested Cython 0.29.21 (python3-Cython-0.29.21-4.1.fc34.x86_64) on Fedora Rawhide with Python 3.10.
The PEP 573 was accepted and implemented in Python 3.9. It adds a new METH_METHOD flag which pass the "defining class".
For example, the zlib.Decompress.decompress() function gets this flag by using the new
defining_classparameter type in its Argument Clinic definition in Python 3.10:It generates the following calling convention:
Notice the second parameter:
PyTypeObject *cls.It seems like __Pyx_PyObject_CallOneArg() doesn't support this new calling convention and simply treat the function as the "fastcall" calling convention. It does not pass the defining type.
As a consequence, zlib_Decompress_decompress() does crash when parsing its arguments.
See https://bugzilla.redhat.com/show_bug.cgi?id=1898157 for a concrete example in scipy.
I tested Cython 0.29.21 (python3-Cython-0.29.21-4.1.fc34.x86_64) on Fedora Rawhide with Python 3.10.