From 23d9966751566028c50ca95ca203d20f36c64f30 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 11 May 2020 22:46:12 +0200 Subject: Fix initialization of Python-3.8--only at-end tp_print member Until Python 3.7, PyTypeObject had a member tp_print following tp_dealloc, which had then been repurposed as > /* Methods to implement standard operations */ > > destructor tp_dealloc; > - printfunc tp_print; > + Py_ssize_t tp_vectorcall_offset; > getattrfunc tp_getattr; > setattrfunc tp_setattr; > PyAsyncMethods *tp_as_async; /* formerly known as tp_compare (Python 2) in "bpo-36974: implement PEP 590 (GH-13185)" towards Python 3.8. Then only on the 3.8 branch (and prior to tag v3.8.0), "[3.8] bpo-37250: put back tp_print for backwards compatibility (GH-14193)" added > destructor tp_finalize; > 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 > /* these must be last and never explicitly initialized */ > Py_ssize_t tp_allocs; at the end of PyTypeObject. This was apparently done so that third-party code containing initialization code like X.tp_print = 0; would continue to compile (by just adding back a member with that name, even if at a "random" new---and otherwise unused---location). However, for our way of list-initializing PyTypeObject instances in pyuno that new member caused "missing field 'tp_print' initializer" -Wmissing-field-initializers warnings, so 50ccb7e82b7053306721cbe220323be072306a29 "python 3.8.2 compile: add tp_print to PyTypeObject" added initializers for this new at-end member. But it did so in a way that raises three concerns: 1 The new member was already added in Python 3.8.0 (prior to tag v3.8.0), not only in 3.8.2. 2 The new member was only added to Python 3.8. It has not been added to current master towards 3.9. 3 It is unclear why the comments mention "Py_ssize_t" as the type of that new member, when actually it is of a function pointer type (see above). Probably best to just drop that from the comments, to avoid confusion. Change-Id: Ib44f43befd5f28d4c1ac1e9e14bd55bfb4473507 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94019 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- pyuno/source/module/pyuno.cxx | 4 ++-- pyuno/source/module/pyuno_callable.cxx | 4 ++-- pyuno/source/module/pyuno_iterator.cxx | 8 ++++---- pyuno/source/module/pyuno_runtime.cxx | 4 ++-- pyuno/source/module/pyuno_struct.cxx | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) (limited to 'pyuno') diff --git a/pyuno/source/module/pyuno.cxx b/pyuno/source/module/pyuno.cxx index ba60f04bbcaa..25aea6436032 100644 --- a/pyuno/source/module/pyuno.cxx +++ b/pyuno/source/module/pyuno.cxx @@ -1660,12 +1660,12 @@ static PyTypeObject PyUNOType = , nullptr #if PY_VERSION_HEX >= 0x03080000 , nullptr // vectorcallfunc tp_vectorcall -#if PY_VERSION_HEX >= 0x03080200 +#if PY_VERSION_HEX < 0x03090000 #if defined __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif - , nullptr //Py_ssize_t tp_print + , nullptr // tp_print #if defined __clang__ #pragma clang diagnostic pop #endif diff --git a/pyuno/source/module/pyuno_callable.cxx b/pyuno/source/module/pyuno_callable.cxx index 867a7f917aa0..1c138f71b419 100644 --- a/pyuno/source/module/pyuno_callable.cxx +++ b/pyuno/source/module/pyuno_callable.cxx @@ -235,12 +235,12 @@ static PyTypeObject PyUNO_callable_Type = , nullptr #if PY_VERSION_HEX >= 0x03080000 , nullptr // vectorcallfunc tp_vectorcall -#if PY_VERSION_HEX >= 0x03080200 +#if PY_VERSION_HEX < 0x03090000 #if defined __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif - , nullptr //Py_ssize_t tp_print + , nullptr // tp_print #if defined __clang__ #pragma clang diagnostic pop #endif diff --git a/pyuno/source/module/pyuno_iterator.cxx b/pyuno/source/module/pyuno_iterator.cxx index 8337feba9a9d..840fc977014a 100644 --- a/pyuno/source/module/pyuno_iterator.cxx +++ b/pyuno/source/module/pyuno_iterator.cxx @@ -167,12 +167,12 @@ static PyTypeObject PyUNO_iterator_Type = , nullptr #if PY_VERSION_HEX >= 0x03080000 , nullptr // vectorcallfunc tp_vectorcall -#if PY_VERSION_HEX >= 0x03080200 +#if PY_VERSION_HEX < 0x03090000 #if defined __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif - , nullptr //Py_ssize_t tp_print + , nullptr // tp_print #if defined __clang__ #pragma clang diagnostic pop #endif @@ -313,12 +313,12 @@ static PyTypeObject PyUNO_list_iterator_Type = , nullptr #if PY_VERSION_HEX >= 0x03080000 , nullptr // vectorcallfunc tp_vectorcall -#if PY_VERSION_HEX >= 0x03080200 +#if PY_VERSION_HEX < 0x03090000 #if defined __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif - , nullptr //Py_ssize_t tp_print + , nullptr // tp_print #if defined __clang__ #pragma clang diagnostic pop #endif diff --git a/pyuno/source/module/pyuno_runtime.cxx b/pyuno/source/module/pyuno_runtime.cxx index 790395bf9a60..91005f1e13aa 100644 --- a/pyuno/source/module/pyuno_runtime.cxx +++ b/pyuno/source/module/pyuno_runtime.cxx @@ -127,12 +127,12 @@ static PyTypeObject RuntimeImpl_Type = , nullptr #if PY_VERSION_HEX >= 0x03080000 , nullptr // vectorcallfunc tp_vectorcall -#if PY_VERSION_HEX >= 0x03080200 +#if PY_VERSION_HEX < 0x03090000 #if defined __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif - , nullptr //Py_ssize_t tp_print + , nullptr // tp_print #if defined __clang__ #pragma clang diagnostic pop #endif diff --git a/pyuno/source/module/pyuno_struct.cxx b/pyuno/source/module/pyuno_struct.cxx index 7696a231f24a..a5b127dc23c6 100644 --- a/pyuno/source/module/pyuno_struct.cxx +++ b/pyuno/source/module/pyuno_struct.cxx @@ -347,12 +347,12 @@ static PyTypeObject PyUNOStructType = , nullptr #if PY_VERSION_HEX >= 0x03080000 , nullptr // vectorcallfunc tp_vectorcall -#if PY_VERSION_HEX >= 0x03080200 +#if PY_VERSION_HEX < 0x03090000 #if defined __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif - , nullptr //Py_ssize_t tp_print + , nullptr // tp_print #if defined __clang__ #pragma clang diagnostic pop #endif -- cgit