summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Feltman <sfeltman@src.gnome.org>2013-05-02 03:57:05 -0700
committerSimon Feltman <sfeltman@src.gnome.org>2013-05-03 02:02:34 -0700
commitc9e95663d05de98a9abd3d1479554b1f09753382 (patch)
treee8fb415bc9b4e6f72d12a9744eae5b051c8b41ba
parent05498a5732582a5ed1944bd1383af154ca5fc4e6 (diff)
downloadpygobject-c9e95663d05de98a9abd3d1479554b1f09753382.tar.gz
Remove and deprecate API for setting of thread blocking functions
Remove pyglib_set_thread_block_funcs and deprecate pyg_set_thread_block_funcs. The thread block function APIs are no longer be neccessary because PyGObject can use the Python C API directly when working with threads. https://bugzilla.gnome.org/show_bug.cgi?id=699440
-rw-r--r--gi/_glib/pyglib.c41
-rw-r--r--gi/_glib/pyglib.h9
-rw-r--r--gi/_gobject/gobjectmodule.c25
-rw-r--r--gi/_gobject/pygobject-private.h33
-rw-r--r--gi/_gobject/pygobject.h48
-rw-r--r--gi/gimodule.c15
6 files changed, 46 insertions, 125 deletions
diff --git a/gi/_glib/pyglib.c b/gi/_glib/pyglib.c
index 54b2d90a..9753a52e 100644
--- a/gi/_glib/pyglib.c
+++ b/gi/_glib/pyglib.c
@@ -77,47 +77,6 @@ pyglib_init_internal(PyObject *api)
}
/**
- * pyglib_block_threads:
- *
- */
-void
-pyglib_block_threads(void)
-{
- g_return_if_fail (_PyGLib_API != NULL);
-
- if (_PyGLib_API->block_threads != NULL)
- (* _PyGLib_API->block_threads)();
-}
-
-/**
- * pyglib_unblock_threads:
- *
- */
-void
-pyglib_unblock_threads(void)
-{
- g_return_if_fail (_PyGLib_API != NULL);
- if (_PyGLib_API->unblock_threads != NULL)
- (* _PyGLib_API->unblock_threads)();
-}
-
-/**
- * pyglib_set_thread_block_funcs:
- *
- * hooks to register handlers for getting GDK threads to cooperate
- * with python threading
- */
-void
-pyglib_set_thread_block_funcs (PyGLibThreadBlockFunc block_threads_func,
- PyGLibThreadBlockFunc unblock_threads_func)
-{
- g_return_if_fail (_PyGLib_API != NULL);
-
- _PyGLib_API->block_threads = block_threads_func;
- _PyGLib_API->unblock_threads = unblock_threads_func;
-}
-
-/**
* pyglib_error_marshal:
* @error: a pointer to the GError.
*
diff --git a/gi/_glib/pyglib.h b/gi/_glib/pyglib.h
index 0b587b83..35be4eb7 100644
--- a/gi/_glib/pyglib.h
+++ b/gi/_glib/pyglib.h
@@ -46,15 +46,16 @@ void pyglib_init_internal(PyObject *api);
# define pyglib_end_allow_threads Py_END_ALLOW_THREADS
#endif
+/* Deprecated, only available for API compatibility. */
+#define pyg_set_thread_block_funcs(a, b)
+#define pyglib_block_threads()
+#define pyglib_unblock_threads()
+
gboolean pyglib_error_check(GError **error);
PyObject *pyglib_error_marshal (GError **error);
gboolean pyglib_gerror_exception_check(GError **error);
PyObject *pyglib_register_exception_for_domain(gchar *name,
gint error_domain);
-void pyglib_set_thread_block_funcs(PyGLibThreadBlockFunc block_threads_func,
- PyGLibThreadBlockFunc unblock_threads_func);
-void pyglib_block_threads(void);
-void pyglib_unblock_threads(void);
PyObject * pyglib_option_context_new(GOptionContext *context);
PyObject * pyglib_option_group_new(GOptionGroup *group);
GOptionGroup * pyglib_option_group_transfer_group(PyObject *self);
diff --git a/gi/_gobject/gobjectmodule.c b/gi/_gobject/gobjectmodule.c
index 3de839d4..1e1cbd84 100644
--- a/gi/_gobject/gobjectmodule.c
+++ b/gi/_gobject/gobjectmodule.c
@@ -48,24 +48,17 @@ static void pyg_flags_add_constants(PyObject *module, GType flags_type,
/**
* pyg_set_thread_block_funcs:
- * @block_threads_func: a function to block Python threads.
- * @unblock_threads_func: a function to unblock Python threads.
- *
- * an interface to allow pygtk to add hooks to handle threading
- * similar to the old PyGTK 0.6.x releases. May not work quite right
- * anymore.
+ * Deprecated, only available for ABI compatibility.
*/
static void
-pyg_set_thread_block_funcs (PyGThreadBlockFunc block_threads_func,
- PyGThreadBlockFunc unblock_threads_func)
+_pyg_set_thread_block_funcs (PyGThreadBlockFunc block_threads_func,
+ PyGThreadBlockFunc unblock_threads_func)
{
- g_return_if_fail(pygobject_api_functions.block_threads == NULL &&
- pygobject_api_functions.unblock_threads == NULL);
-
- pygobject_api_functions.block_threads = block_threads_func;
- pygobject_api_functions.unblock_threads = unblock_threads_func;
- pyglib_set_thread_block_funcs(block_threads_func,
- unblock_threads_func);
+ PyGILState_STATE state = pyglib_gil_state_ensure ();
+ PyErr_Warn (PyExc_DeprecationWarning,
+ "Using pyg_set_thread_block_funcs is not longer needed. "
+ "PyGObject always uses Py_BLOCK/UNBLOCK_THREADS.");
+ pyglib_gil_state_release (state);
}
/**
@@ -2031,7 +2024,7 @@ struct _PyGObject_Functions pygobject_api_functions = {
pyg_error_check,
- pyg_set_thread_block_funcs,
+ _pyg_set_thread_block_funcs,
(PyGThreadBlockFunc)0, /* block_threads */
(PyGThreadBlockFunc)0, /* unblock_threads */
diff --git a/gi/_gobject/pygobject-private.h b/gi/_gobject/pygobject-private.h
index 5de7488d..e2a0af74 100644
--- a/gi/_gobject/pygobject-private.h
+++ b/gi/_gobject/pygobject-private.h
@@ -21,39 +21,6 @@
/* from gobjectmodule.c */
extern struct _PyGObject_Functions pygobject_api_functions;
-#define pyg_block_threads() G_STMT_START { \
- if (pygobject_api_functions.block_threads != NULL) \
- (* pygobject_api_functions.block_threads)(); \
- } G_STMT_END
-#define pyg_unblock_threads() G_STMT_START { \
- if (pygobject_api_functions.unblock_threads != NULL) \
- (* pygobject_api_functions.unblock_threads)(); \
- } G_STMT_END
-
-#define pyg_threads_enabled (pygobject_api_functions.threads_enabled)
-
-#ifdef DISABLE_THREADING
-#define pyg_gil_state_ensure() 0
-#define pyg_gil_state_release(state) G_STMT_START { \
- } G_STMT_END
-
-#else
-#define pyg_gil_state_ensure() (pygobject_api_functions.threads_enabled? (PyGILState_Ensure()) : 0)
-#define pyg_gil_state_release(state) G_STMT_START { \
- if (pygobject_api_functions.threads_enabled) \
- PyGILState_Release(state); \
- } G_STMT_END
-#endif
-
-#define pyg_begin_allow_threads \
- G_STMT_START { \
- PyThreadState *_save = NULL; \
- if (pygobject_api_functions.threads_enabled) \
- _save = PyEval_SaveThread();
-#define pyg_end_allow_threads \
- if (pygobject_api_functions.threads_enabled) \
- PyEval_RestoreThread(_save); \
- } G_STMT_END
#ifndef Py_CLEAR /* since Python 2.4 */
diff --git a/gi/_gobject/pygobject.h b/gi/_gobject/pygobject.h
index 3c5e384a..f6b531d0 100644
--- a/gi/_gobject/pygobject.h
+++ b/gi/_gobject/pygobject.h
@@ -140,6 +140,7 @@ struct _PyGObject_Functions {
PyGThreadBlockFunc unblock_threads_func);
PyGThreadBlockFunc block_threads;
PyGThreadBlockFunc unblock_threads;
+
PyTypeObject *paramspec_type;
PyObject *(* paramspec_new)(GParamSpec *spec);
GParamSpec *(*paramspec_get)(PyObject *tuple);
@@ -196,6 +197,28 @@ struct _PyGObject_Functions {
PyTypeObject *object_type;
};
+
+#ifdef DISABLE_THREADING
+# define pyg_threads_enabled FALSE
+# define pyg_gil_state_ensure() 0
+# define pyg_gil_state_release(state)
+# define pyg_begin_allow_threads G_STMT_START {
+# define pyg_end_allow_threads } G_STMT_END
+#else
+# define pyg_threads_enabled TRUE
+# define pyg_gil_state_ensure PyGILState_Ensure
+# define pyg_gil_state_release PyGILState_Release
+# define pyg_begin_allow_threads Py_BEGIN_ALLOW_THREADS
+# define pyg_end_allow_threads Py_END_ALLOW_THREADS
+#endif
+
+/* Deprecated, only available for API compatibility. */
+#define pyg_enable_threads()
+#define pyg_set_thread_block_funcs(a, b)
+#define pyg_block_threads()
+#define pyg_unblock_threads()
+
+
#ifndef _INSIDE_PYGOBJECT_
#if defined(NO_IMPORT) || defined(NO_IMPORT_PYGOBJECT)
@@ -233,7 +256,6 @@ struct _PyGObject_Functions *_PyGObject_API;
#define pyg_flags_add_constants (_PyGObject_API->flags_add_constants)
#define pyg_constant_strip_prefix (_PyGObject_API->constant_strip_prefix)
#define pyg_error_check (_PyGObject_API->error_check)
-#define pyg_set_thread_block_funcs (_PyGObject_API->set_thread_block_funcs)
#define PyGParamSpec_Type (*_PyGObject_API->paramspec_type)
#define pyg_param_spec_new (_PyGObject_API->paramspec_new)
#define pyg_param_spec_from_object (_PyGObject_API->paramspec_get)
@@ -247,9 +269,6 @@ struct _PyGObject_Functions *_PyGObject_API;
#define PyGFlags_Type (*_PyGObject_API->flags_type)
#define pyg_flags_add (_PyGObject_API->flags_add)
#define pyg_flags_from_gtype (_PyGObject_API->flags_from_gtype)
-#define pyg_enable_threads (_PyGObject_API->enable_threads)
-#define pyg_gil_state_ensure (_PyGObject_API->gil_state_ensure)
-#define pyg_gil_state_release (_PyGObject_API->gil_state_release)
#define pyg_register_class_init (_PyGObject_API->register_class_init)
#define pyg_register_interface_info (_PyGObject_API->register_interface_info)
#define pyg_add_warning_redirection (_PyGObject_API->add_warning_redirection)
@@ -257,27 +276,6 @@ struct _PyGObject_Functions *_PyGObject_API;
#define pyg_gerror_exception_check (_PyGObject_API->gerror_exception_check)
#define pyg_option_group_new (_PyGObject_API->option_group_new)
-#define pyg_block_threads() G_STMT_START { \
- if (_PyGObject_API->block_threads != NULL) \
- (* _PyGObject_API->block_threads)(); \
- } G_STMT_END
-#define pyg_unblock_threads() G_STMT_START { \
- if (_PyGObject_API->unblock_threads != NULL) \
- (* _PyGObject_API->unblock_threads)(); \
- } G_STMT_END
-
-#define pyg_threads_enabled (_PyGObject_API->threads_enabled)
-
-#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
-
/**
* pygobject_init:
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 108fc77f..3952f91f 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -534,6 +534,7 @@ pyg_channel_read(PyObject* self, PyObject *args, PyObject *kwargs)
gsize total_read = 0;
GError* error = NULL;
GIOStatus status = G_IO_STATUS_NORMAL;
+ GIOChannel *iochannel = NULL;
if (!PyArg_ParseTuple (args, "Oi:pyg_channel_read", &py_iochannel, &max_count)) {
return NULL;
@@ -545,7 +546,9 @@ pyg_channel_read(PyObject* self, PyObject *args, PyObject *kwargs)
if (max_count == 0)
return PYGLIB_PyBytes_FromString("");
-
+
+ iochannel = pyg_boxed_get (py_iochannel, GIOChannel);
+
while (status == G_IO_STATUS_NORMAL
&& (max_count == -1 || total_read < max_count)) {
gsize single_read;
@@ -572,11 +575,11 @@ pyg_channel_read(PyObject* self, PyObject *args, PyObject *kwargs)
buf = PYGLIB_PyBytes_AsString(ret_obj) + total_read;
- pyglib_unblock_threads();
- status = g_io_channel_read_chars(pyg_boxed_get (py_iochannel, GIOChannel),
- buf, buf_size, &single_read, &error);
- pyglib_block_threads();
- if (pyglib_error_check(&error))
+ pyglib_begin_allow_threads;
+ status = g_io_channel_read_chars (iochannel, buf, buf_size, &single_read, &error);
+ pyglib_end_allow_threads;
+
+ if (pyglib_error_check(&error))
goto failure;
total_read += single_read;