diff options
author | Daniel P. Berrangé <berrange@redhat.com> | 2020-11-12 13:30:23 +0000 |
---|---|---|
committer | Daniel P. Berrangé <berrange@redhat.com> | 2020-11-12 13:30:23 +0000 |
commit | 2035a5e2f1583a5dd640542e515b6c1812b44056 (patch) | |
tree | 960bf16b14a80098349d8f2702f8c885fe9f85de /typewrappers.h | |
parent | 4a6f381bd9d1eb23220e1497ee6be646dec8e9ea (diff) | |
download | libvirt-python-2035a5e2f1583a5dd640542e515b6c1812b44056.tar.gz |
Avoid use of thread function deprecated in 3.9
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>
Diffstat (limited to 'typewrappers.h')
-rw-r--r-- | typewrappers.h | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/typewrappers.h b/typewrappers.h index e5bc4c8..3bdc0ae 100644 --- a/typewrappers.h +++ b/typewrappers.h @@ -255,28 +255,48 @@ 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 + #ifndef NULLSTR #define NULLSTR(s) ((s) ? (s) : "<null>") #endif |