Skip to content

Commit 08ed9c7

Browse files
committed
bpo-37250: define tp_print for backwards compatibility
1 parent 32dda26 commit 08ed9c7

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Include/cpython/object.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ typedef struct {
174174
* backwards-compatibility */
175175
typedef Py_ssize_t printfunc;
176176

177+
/* Define tp_print as alias of tp_vectorcall to allow for code accessing
178+
* this field (hopefully not actually doing anything with it). */
179+
#define tp_print tp_vectorcall
180+
177181
typedef struct _typeobject {
178182
PyObject_VAR_HEAD
179183
const char *tp_name; /* For printing, in format "<module>.<name>" */
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``tp_print`` is defined as alias of ``tp_vectorcall`` to restore support for
2+
old code (in particular generated by Cython) setting ``tp_print = 0``.

Modules/_testcapimodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6008,6 +6008,10 @@ PyInit__testcapi(void)
60086008
Py_INCREF(&MyList_Type);
60096009
PyModule_AddObject(m, "MyList", (PyObject *)&MyList_Type);
60106010

6011+
/* Old Cython code sets tp_print to 0, we check that
6012+
* this doesn't break anything. */
6013+
MyList_Type.tp_print = 0;
6014+
60116015
if (PyType_Ready(&MethodDescriptorBase_Type) < 0)
60126016
return NULL;
60136017
Py_INCREF(&MethodDescriptorBase_Type);

0 commit comments

Comments
 (0)