From d8860249697b8f75d74e627e4daf408d7b976cb4 Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Wed, 12 Jun 2019 11:41:19 +0200 Subject: [PATCH 1/4] [3.8] bpo-37250: put back tp_print for backwards compatibility --- Include/cpython/object.h | 3 +++ .../next/C API/2019-06-12-11-45-36.bpo-37221.RhP1E7.rst | 3 +++ Modules/_testcapimodule.c | 4 ++++ 3 files changed, 10 insertions(+) create mode 100644 Misc/NEWS.d/next/C API/2019-06-12-11-45-36.bpo-37221.RhP1E7.rst diff --git a/Include/cpython/object.h b/Include/cpython/object.h index a65aaf6482159c..3d98d33d1645dd 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -256,6 +256,9 @@ typedef struct _typeobject { destructor tp_finalize; vectorcallfunc tp_vectorcall; + /* Unused, kept for backwards compatibility in CPython 3.8 only */ + int (*tp_print)(PyObject *, FILE *, int); + #ifdef COUNT_ALLOCS /* these must be last and never explicitly initialized */ Py_ssize_t tp_allocs; 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..46abfde13462eb --- /dev/null +++ b/Misc/NEWS.d/next/C API/2019-06-12-11-45-36.bpo-37221.RhP1E7.rst @@ -0,0 +1,3 @@ +``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``. 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); From 35f438862c086c776e220f3238e2fb3b7b22bd24 Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Tue, 18 Jun 2019 11:10:59 +0200 Subject: [PATCH 2/4] Fix sizeof test --- Lib/test/test_sys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 49f2722d95140e..a7df7a2fc8c978 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1275,7 +1275,7 @@ def delx(self): del self.__x check((1,2,3), vsize('') + 3*self.P) # type # static type: PyTypeObject - fmt = 'P2nPI13Pl4Pn9Pn11PIPP' + fmt = 'P2nPI13Pl4Pn9Pn11PIPPP' if hasattr(sys, 'getcounts'): fmt += '3n2P' s = vsize(fmt) From 99f11a1ed8160b43ea9e67b8f26c2937e8d50dcc Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Wed, 19 Jun 2019 12:34:49 +0200 Subject: [PATCH 3/4] Use Py_DEPRECATED(3.8) macro but not in _testcapimodule.c --- Include/cpython/object.h | 4 ++-- Include/pyport.h | 2 ++ .../next/C API/2019-06-12-11-45-36.bpo-37221.RhP1E7.rst | 1 + Modules/_testcapimodule.c | 6 +++++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 3d98d33d1645dd..5a0ac4afdae83d 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -256,8 +256,8 @@ typedef struct _typeobject { destructor tp_finalize; vectorcallfunc tp_vectorcall; - /* Unused, kept for backwards compatibility in CPython 3.8 only */ - int (*tp_print)(PyObject *, FILE *, int); + /* bpo-37250: kept for backwards compatibility in CPython 3.8 only */ + Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int); #ifdef COUNT_ALLOCS /* these must be last and never explicitly initialized */ diff --git a/Include/pyport.h b/Include/pyport.h index 32d98c59a7c134..ef79b73a14d368 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -510,6 +510,7 @@ extern "C" { * Py_DEPRECATED(3.4) typedef int T1; * Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void); */ +#ifndef Py_DEPRECATED #if defined(__GNUC__) \ && ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)) #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__)) @@ -519,6 +520,7 @@ extern "C" { #else #define Py_DEPRECATED(VERSION_UNUSED) #endif +#endif /* _Py_HOT_FUNCTION 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 index 46abfde13462eb..96b61dea0d9cde 100644 --- 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 @@ -1,3 +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. diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index bbf6122ec221fd..512440bff96d6b 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -12,6 +12,10 @@ #define PY_SSIZE_T_CLEAN +/* We test deprecated functionality on purpose, + * so we disable the Py_DEPRECATED macro. */ +#define Py_DEPRECATED(VERSION_UNUSED) + #include "Python.h" #include "datetime.h" #include "marshal.h" @@ -6008,7 +6012,7 @@ 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 + /* bpo-37250: old Cython code sets tp_print to 0, we check that * this doesn't break anything. */ MyList_Type.tp_print = 0; From 101163c24d87e2998f17ca8c864ae831ef44e568 Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Wed, 19 Jun 2019 13:50:44 +0200 Subject: [PATCH 4/4] Re-enable deprecation warning during compilation of _testcapimodule --- Include/pyport.h | 2 -- Modules/_testcapimodule.c | 4 ---- 2 files changed, 6 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h index ef79b73a14d368..32d98c59a7c134 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -510,7 +510,6 @@ extern "C" { * Py_DEPRECATED(3.4) typedef int T1; * Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void); */ -#ifndef Py_DEPRECATED #if defined(__GNUC__) \ && ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)) #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__)) @@ -520,7 +519,6 @@ extern "C" { #else #define Py_DEPRECATED(VERSION_UNUSED) #endif -#endif /* _Py_HOT_FUNCTION diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 512440bff96d6b..1042ea701923c2 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -12,10 +12,6 @@ #define PY_SSIZE_T_CLEAN -/* We test deprecated functionality on purpose, - * so we disable the Py_DEPRECATED macro. */ -#define Py_DEPRECATED(VERSION_UNUSED) - #include "Python.h" #include "datetime.h" #include "marshal.h"