Skip to content

Commit d917cfe

Browse files
jdemeyerencukou
authored andcommitted
[3.8] bpo-37250: put back tp_print for backwards compatibility (GH-14193)
This is a 3.8-only compatibility measure for third-party Cython-based sdists. https://bugs.python.org/issue37250
1 parent d32594a commit d917cfe

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

Include/cpython/object.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ typedef struct _typeobject {
256256
destructor tp_finalize;
257257
vectorcallfunc tp_vectorcall;
258258

259+
/* bpo-37250: kept for backwards compatibility in CPython 3.8 only */
260+
Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
261+
259262
#ifdef COUNT_ALLOCS
260263
/* these must be last and never explicitly initialized */
261264
Py_ssize_t tp_allocs;

Lib/test/test_sys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ def delx(self): del self.__x
12751275
check((1,2,3), vsize('') + 3*self.P)
12761276
# type
12771277
# static type: PyTypeObject
1278-
fmt = 'P2nPI13Pl4Pn9Pn11PIPP'
1278+
fmt = 'P2nPI13Pl4Pn9Pn11PIPPP'
12791279
if hasattr(sys, 'getcounts'):
12801280
fmt += '3n2P'
12811281
s = vsize(fmt)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``tp_print`` is put back at the end of the ``PyTypeObject`` structure
2+
to restore support for old code (in particular generated by Cython)
3+
setting ``tp_print = 0``.
4+
Note that ``tp_print`` will be removed entirely in Python 3.9.

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+
/* bpo-37250: 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)