74 lines
2.5 KiB
Diff
74 lines
2.5 KiB
Diff
|
|
From 1cab3de8bc544550bd13926141b3a9a01951f502 Mon Sep 17 00:00:00 2001
|
||
|
|
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
|
||
|
|
Date: Thu, 12 Nov 2020 13:30:23 +0000
|
||
|
|
Subject: [PATCH 5/6] Avoid use of thread function deprecated in 3.9
|
||
|
|
MIME-Version: 1.0
|
||
|
|
Content-Type: text/plain; charset=UTF-8
|
||
|
|
Content-Transfer-Encoding: 8bit
|
||
|
|
|
||
|
|
PyEval_ThreadsInitialized was deprecated in 3.9, with deletion targetted
|
||
|
|
for 3.11. Furthermore since 3.7 it is guaranteed that threads are always
|
||
|
|
initialized by Py_Initialize(), so checking it is redundant.
|
||
|
|
|
||
|
|
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
|
||
|
|
---
|
||
|
|
typewrappers.h | 28 ++++++++++++++++++++++++----
|
||
|
|
1 file changed, 24 insertions(+), 4 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/typewrappers.h b/typewrappers.h
|
||
|
|
index fc923bf..b197d65 100644
|
||
|
|
--- a/typewrappers.h
|
||
|
|
+++ b/typewrappers.h
|
||
|
|
@@ -255,24 +255,44 @@ PyObject * libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node);
|
||
|
|
# endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
|
||
|
|
#endif
|
||
|
|
|
||
|
|
-#define LIBVIRT_BEGIN_ALLOW_THREADS \
|
||
|
|
+#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
|
||
|
|
+# define LIBVIRT_BEGIN_ALLOW_THREADS \
|
||
|
|
LIBVIRT_STMT_START { \
|
||
|
|
PyThreadState *_save = NULL; \
|
||
|
|
if (PyEval_ThreadsInitialized()) \
|
||
|
|
_save = PyEval_SaveThread();
|
||
|
|
|
||
|
|
-#define LIBVIRT_END_ALLOW_THREADS \
|
||
|
|
+# define LIBVIRT_END_ALLOW_THREADS \
|
||
|
|
if (PyEval_ThreadsInitialized()) \
|
||
|
|
PyEval_RestoreThread(_save); \
|
||
|
|
} LIBVIRT_STMT_END
|
||
|
|
|
||
|
|
-#define LIBVIRT_ENSURE_THREAD_STATE \
|
||
|
|
+# define LIBVIRT_ENSURE_THREAD_STATE \
|
||
|
|
LIBVIRT_STMT_START { \
|
||
|
|
PyGILState_STATE _save = PyGILState_UNLOCKED; \
|
||
|
|
if (PyEval_ThreadsInitialized()) \
|
||
|
|
_save = PyGILState_Ensure();
|
||
|
|
|
||
|
|
-#define LIBVIRT_RELEASE_THREAD_STATE \
|
||
|
|
+# define LIBVIRT_RELEASE_THREAD_STATE \
|
||
|
|
if (PyEval_ThreadsInitialized()) \
|
||
|
|
PyGILState_Release(_save); \
|
||
|
|
} LIBVIRT_STMT_END
|
||
|
|
+
|
||
|
|
+#else
|
||
|
|
+
|
||
|
|
+# define LIBVIRT_BEGIN_ALLOW_THREADS \
|
||
|
|
+ LIBVIRT_STMT_START { \
|
||
|
|
+ PyThreadState *_save = PyEval_SaveThread();
|
||
|
|
+
|
||
|
|
+# define LIBVIRT_END_ALLOW_THREADS \
|
||
|
|
+ PyEval_RestoreThread(_save); \
|
||
|
|
+ } LIBVIRT_STMT_END
|
||
|
|
+
|
||
|
|
+# define LIBVIRT_ENSURE_THREAD_STATE \
|
||
|
|
+ LIBVIRT_STMT_START { \
|
||
|
|
+ PyGILState_STATE _save = PyGILState_Ensure();
|
||
|
|
+
|
||
|
|
+# define LIBVIRT_RELEASE_THREAD_STATE \
|
||
|
|
+ PyGILState_Release(_save); \
|
||
|
|
+ } LIBVIRT_STMT_END
|
||
|
|
+#endif
|
||
|
|
--
|
||
|
|
2.27.0
|
||
|
|
|