summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2008-08-06 08:28:12 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-08-06 08:28:12 +0000
commit6bed68913d23d49ea7a774a9e7daebd2e3624b96 (patch)
tree358a5446bcc7de59f0b03209ae360861bef1545d
parent6f9ecc1cd9cc1498ffac79e1271b831a9be6b364 (diff)
downloadpygobject-6bed68913d23d49ea7a774a9e7daebd2e3624b96.tar.gz
pygobject-6bed68913d23d49ea7a774a9e7daebd2e3624b96.tar.xz
pygobject-6bed68913d23d49ea7a774a9e7daebd2e3624b96.zip
Add a pygobject_enable_threads wrapper around pyglib_threads_enable and
2008-08-06 Johan Dahlin <johan@gnome.org> * glib/pyglib.c (pyglib_enable_threads): * gobject/gobjectmodule.c (pyg_threads_init), (pygobject_enable_threads): Add a pygobject_enable_threads wrapper around pyglib_threads_enable and return 0/-1 which existing gobject based applications expect. svn path=/trunk/; revision=927
-rw-r--r--ChangeLog8
-rw-r--r--glib/pyglib.c18
-rw-r--r--gobject/gobjectmodule.c13
3 files changed, 31 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index b7a64dc..4d8118b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2008-08-06 Johan Dahlin <johan@gnome.org>
+ * glib/pyglib.c (pyglib_enable_threads):
+ * gobject/gobjectmodule.c (pyg_threads_init),
+ (pygobject_enable_threads):
+ Add a pygobject_enable_threads wrapper around pyglib_threads_enable
+ and return 0/-1 which existing gobject based applications expect.
+
+2008-08-06 Johan Dahlin <johan@gnome.org>
+
* glib/pyglib.c (pyglib_init):
return in case of error instead of trying to access the internal
types.
diff --git a/glib/pyglib.c b/glib/pyglib.c
index de8cbf9..2bb0d7b 100644
--- a/glib/pyglib.c
+++ b/glib/pyglib.c
@@ -121,25 +121,31 @@ pyglib_gil_state_release(PyGILState_STATE state)
PyGILState_Release(state);
}
+/**
+ * pyglib_enable_threads:
+ *
+ * Returns: TRUE if threading is enabled, FALSE otherwise.
+ *
+ */
#ifdef DISABLE_THREADING
-int
+gboolean
pyglib_enable_threads(void)
{
PyErr_SetString(PyExc_RuntimeError,
"pyglib threading disabled at compile time");
- return -1;
+ return FALSE;
}
#else
/* Enable threading; note that the GIL must be held by the current
* thread when this function is called
*/
-int
+gboolean
pyglib_enable_threads(void)
{
- g_return_val_if_fail (_PyGLib_API != NULL, -1);
+ g_return_val_if_fail (_PyGLib_API != NULL, FALSE);
if (_PyGLib_API->threads_enabled)
- return 0;
+ return TRUE;
PyEval_InitThreads();
if (!g_threads_got_initialized)
@@ -148,7 +154,7 @@ pyglib_enable_threads(void)
_PyGLib_API->threads_enabled = TRUE;
pyglib_thread_state_tls_key = PyThread_create_key();
- return 0;
+ return TRUE;
}
#endif
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index 4d47d71..b7fadfd 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -1788,13 +1788,22 @@ pygobject_gil_state_release (int flag)
static PyObject *
pyg_threads_init (PyObject *unused, PyObject *args, PyObject *kwargs)
{
- if (pyglib_enable_threads())
+ if (!pyglib_enable_threads())
return NULL;
Py_INCREF(Py_None);
return Py_None;
}
+/* Only for backwards compatibility */
+int
+pygobject_enable_threads(void)
+{
+ if (!pyglib_enable_threads())
+ return -1;
+ return 0;
+}
+
static PyObject *
pyg_signal_accumulator_true_handled(PyObject *unused, PyObject *args)
{
@@ -2452,7 +2461,7 @@ struct _PyGObject_Functions pygobject_api_functions = {
pyg_flags_from_gtype,
FALSE, /* threads_enabled */
- pyglib_enable_threads,
+ pygobject_enable_threads,
pygobject_gil_state_ensure,
pygobject_gil_state_release,
pyg_register_class_init,