[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
This commit is contained in:
Jeroen Demeyer 2019-06-25 12:58:58 +02:00 committed by Petr Viktorin
parent d32594ad27
commit d917cfe405
4 changed files with 12 additions and 1 deletions

View File

@ -256,6 +256,9 @@ typedef struct _typeobject {
destructor tp_finalize; destructor tp_finalize;
vectorcallfunc tp_vectorcall; vectorcallfunc tp_vectorcall;
/* bpo-37250: kept for backwards compatibility in CPython 3.8 only */
Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
#ifdef COUNT_ALLOCS #ifdef COUNT_ALLOCS
/* these must be last and never explicitly initialized */ /* these must be last and never explicitly initialized */
Py_ssize_t tp_allocs; Py_ssize_t tp_allocs;

View File

@ -1275,7 +1275,7 @@ class SizeofTest(unittest.TestCase):
check((1,2,3), vsize('') + 3*self.P) check((1,2,3), vsize('') + 3*self.P)
# type # type
# static type: PyTypeObject # static type: PyTypeObject
fmt = 'P2nPI13Pl4Pn9Pn11PIPP' fmt = 'P2nPI13Pl4Pn9Pn11PIPPP'
if hasattr(sys, 'getcounts'): if hasattr(sys, 'getcounts'):
fmt += '3n2P' fmt += '3n2P'
s = vsize(fmt) s = vsize(fmt)

View File

@ -0,0 +1,4 @@
``tp_print`` is put back at the end of the ``PyTypeObject`` structure
to restore support for old code (in particular generated by Cython)
setting ``tp_print = 0``.
Note that ``tp_print`` will be removed entirely in Python 3.9.

View File

@ -6008,6 +6008,10 @@ PyInit__testcapi(void)
Py_INCREF(&MyList_Type); Py_INCREF(&MyList_Type);
PyModule_AddObject(m, "MyList", (PyObject *)&MyList_Type); PyModule_AddObject(m, "MyList", (PyObject *)&MyList_Type);
/* bpo-37250: 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) if (PyType_Ready(&MethodDescriptorBase_Type) < 0)
return NULL; return NULL;
Py_INCREF(&MethodDescriptorBase_Type); Py_INCREF(&MethodDescriptorBase_Type);