summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2023-01-27 17:33:26 +0100
committerChristoph Reiter <reiter.christoph@gmail.com>2023-01-27 17:35:29 +0100
commit02bc8a51c572e0720eb3cb8c0e056287197b02f0 (patch)
treea1d73ebdffaa5d975ab55f0b2866d83a00663750
parent36dc79774142ebfc353b53a7fc20d98ef4e454a5 (diff)
downloadpygobject-02bc8a51c572e0720eb3cb8c0e056287197b02f0.tar.gz
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.
-rw-r--r--gi/pygi-resulttuple.c4
-rw-r--r--gi/pygi-util.h8
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) \