diff --git a/Include/cpython/object.h b/Include/cpython/object.h index a65aaf6482159c..b70c736b0b7b53 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -174,6 +174,10 @@ typedef struct { * backwards-compatibility */ typedef Py_ssize_t printfunc; +/* Define tp_print as alias of tp_vectorcall to allow for code accessing + * this field (hopefully not actually doing anything with it). */ +#define tp_print tp_vectorcall + typedef struct _typeobject { PyObject_VAR_HEAD const char *tp_name; /* For printing, in format "." */ diff --git a/Misc/NEWS.d/next/C API/2019-06-12-11-45-36.bpo-37221.RhP1E7.rst b/Misc/NEWS.d/next/C API/2019-06-12-11-45-36.bpo-37221.RhP1E7.rst new file mode 100644 index 00000000000000..98a51b7c84e15b --- /dev/null +++ b/Misc/NEWS.d/next/C API/2019-06-12-11-45-36.bpo-37221.RhP1E7.rst @@ -0,0 +1,2 @@ +``tp_print`` is defined as alias of ``tp_vectorcall`` to restore support for +old code (in particular generated by Cython) setting ``tp_print = 0``. diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 07aadea3e98395..bbf6122ec221fd 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -6008,6 +6008,10 @@ PyInit__testcapi(void) Py_INCREF(&MyList_Type); PyModule_AddObject(m, "MyList", (PyObject *)&MyList_Type); + /* Old Cython code sets tp_print to 0, we check that + * this doesn't break anything. */ + MyList_Type.tp_print = 0; + if (PyType_Ready(&MethodDescriptorBase_Type) < 0) return NULL; Py_INCREF(&MethodDescriptorBase_Type);