From 02bc8a51c572e0720eb3cb8c0e056287197b02f0 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Fri, 27 Jan 2023 17:33:26 +0100 Subject: Port to Py_TRASHCAN_BEGIN Py_TRASHCAN_SAFE_BEGIN and Py_TRASHCAN_SAFE_END are deprecated since Python 3.11 and result in a deprecation warning when building against Python 3.11. This follows the suggested migration to Py_TRASHCAN_BEGIN and Py_TRASHCAN_END in https://docs.python.org/3/whatsnew/3.11.html Py_TRASHCAN_BEGIN only exists since Python 3.8, while we still support 3.7, so also use the suggested macro to support older Python versions. --- gi/pygi-resulttuple.c | 4 ++-- gi/pygi-util.h | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gi/pygi-resulttuple.c b/gi/pygi-resulttuple.c index 416177bb..93170eaa 100644 --- a/gi/pygi-resulttuple.c +++ b/gi/pygi-resulttuple.c @@ -309,7 +309,7 @@ static void resulttuple_dealloc(PyObject *self) { Py_ssize_t i, len; PyObject_GC_UnTrack (self); - Py_TRASHCAN_SAFE_BEGIN (self) + CPy_TRASHCAN_BEGIN (self, resulttuple_dealloc) /* Free the tuple items and, if there is space, save the tuple object * pointer to the front of the free list for its size. Otherwise free it. @@ -331,7 +331,7 @@ static void resulttuple_dealloc(PyObject *self) { Py_TYPE (self)->tp_free (self); done: - Py_TRASHCAN_SAFE_END (self) + CPy_TRASHCAN_END (self) } #endif diff --git a/gi/pygi-util.h b/gi/pygi-util.h index 5a3becf4..a223730c 100644 --- a/gi/pygi-util.h +++ b/gi/pygi-util.h @@ -16,6 +16,14 @@ gboolean pygi_guint_from_pyssize (Py_ssize_t pyval, guint *result); # define Py_SET_TYPE(obj, type) ((Py_TYPE(obj) = (type)), (void)0) #endif +#if PY_VERSION_HEX >= 0x03080000 +# define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_BEGIN(op, dealloc) +# define CPy_TRASHCAN_END(op) Py_TRASHCAN_END +#else +# define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_SAFE_BEGIN(op) +# define CPy_TRASHCAN_END(op) Py_TRASHCAN_SAFE_END(op) +#endif + #define PYGI_DEFINE_TYPE(typename, symbol, csymbol) \ PyTypeObject symbol = { \ PyVarObject_HEAD_INIT(NULL, 0) \ -- cgit v1.2.1