summaryrefslogtreecommitdiffstats
path: root/gobject/pygobject.h
diff options
context:
space:
mode:
Diffstat (limited to 'gobject/pygobject.h')
-rw-r--r--gobject/pygobject.h22
1 files changed, 10 insertions, 12 deletions
diff --git a/gobject/pygobject.h b/gobject/pygobject.h
index 22e488c..a44f7af 100644
--- a/gobject/pygobject.h
+++ b/gobject/pygobject.h
@@ -223,23 +223,21 @@ struct _PyGObject_Functions *_PyGObject_API;
(* _PyGObject_API->unblock_threads)(); \
} G_STMT_END
-#define pyg_threads_enabled (_PyGObject_API->threads_enabled)
-#define pyg_gil_state_ensure() (_PyGObject_API->threads_enabled? (_PyGObject_API->gil_state_ensure()) : 0)
+#if PY_VERSION_HEX < 0x020400F0
+# define pyg_threads_enabled (_PyGObject_API->threads_enabled)
+#else
+# define pyg_threads_enabled (PyEval_ThreadsInitialized())
+#endif
+
+#define pyg_gil_state_ensure() (pyg_threads_enabled? (_PyGObject_API->gil_state_ensure()) : 0)
#define pyg_gil_state_release(state) G_STMT_START { \
- if (_PyGObject_API->threads_enabled) \
+ if (pyg_threads_enabled) \
_PyGObject_API->gil_state_release(state); \
} G_STMT_END
-#define pyg_begin_allow_threads \
- G_STMT_START { \
- PyThreadState *_save = NULL; \
- if (_PyGObject_API->threads_enabled) \
- _save = PyEval_SaveThread();
-#define pyg_end_allow_threads \
- if (_PyGObject_API->threads_enabled) \
- PyEval_RestoreThread(_save); \
- } G_STMT_END
+#define pyg_begin_allow_threads Py_BEGIN_ALLOW_THREADS
+#define pyg_end_allow_threads Py_END_ALLOW_THREADS
#define init_pygobject() { \
PyObject *gobject = PyImport_ImportModule("gobject"); \