diff options
author | Johan Dahlin <johan@src.gnome.org> | 2004-08-02 11:03:05 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2004-08-02 11:03:05 +0000 |
commit | 3e41db376f6e40c2df01a1f83c2ecf10a5315084 (patch) | |
tree | a4146d2ca0d7516cbcd334048286a710e2692a58 | |
parent | fa82703297dadadf71b26650a8bafd55fc101dce (diff) | |
download | pygobject-3e41db376f6e40c2df01a1f83c2ecf10a5315084.tar.gz |
Call PyEval_InitThreads. Perhaps its something that always should bePYGTK_2_3_95
* gobject/gobjectmodule.c (initgobject): Call
PyEval_InitThreads. Perhaps its something that always should be
called.
* README (Author): Add a requirements section
* configure.in: Require Python 2.3
* setup.py (version): Ditto
* gobject/pygtype.c, gobject/pygobject.h: Remove 2.2 compat.
* All over the place: Add support for PyGILState.
-rw-r--r-- | gobject/gobjectmodule.c | 18 | ||||
-rw-r--r-- | gobject/pygenum.c | 9 | ||||
-rw-r--r-- | gobject/pygflags.c | 9 | ||||
-rw-r--r-- | gobject/pygobject.c | 5 | ||||
-rw-r--r-- | gobject/pygobject.h | 6 | ||||
-rw-r--r-- | gobject/pygtype.c | 20 |
6 files changed, 51 insertions, 16 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index 60272541..709ecd0e 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -328,8 +328,10 @@ pyg_object_set_property (GObject *object, guint property_id, { PyObject *object_wrapper, *retval; PyObject *py_pspec, *py_value; + PyGILState_STATE state; pyg_block_threads(); + state = PyGILState_Ensure(); object_wrapper = pygobject_new(object); @@ -353,6 +355,7 @@ pyg_object_set_property (GObject *object, guint property_id, Py_DECREF(py_pspec); Py_DECREF(py_value); + PyGILState_Release(state); pyg_unblock_threads(); } @@ -362,8 +365,10 @@ pyg_object_get_property (GObject *object, guint property_id, { PyObject *object_wrapper, *retval; PyObject *py_pspec; + PyGILState_STATE state; pyg_block_threads(); + state = PyGILState_Ensure(); object_wrapper = pygobject_new(object); @@ -382,6 +387,7 @@ pyg_object_get_property (GObject *object, guint property_id, Py_DECREF(py_pspec); Py_XDECREF(retval); + PyGILState_Release(state); pyg_unblock_threads(); } @@ -1249,10 +1255,12 @@ handler_marshal(gpointer user_data) { PyObject *tuple, *ret; gboolean res; + PyGILState_STATE state; g_return_val_if_fail(user_data != NULL, FALSE); pyg_block_threads(); + state = PyGILState_Ensure(); tuple = (PyObject *)user_data; ret = PyObject_CallObject(PyTuple_GetItem(tuple, 0), @@ -1264,6 +1272,8 @@ handler_marshal(gpointer user_data) res = PyObject_IsTrue(ret); Py_DECREF(ret); } + + PyGILState_Release(state); pyg_unblock_threads(); return res; @@ -1348,12 +1358,14 @@ pyg_timeout_add(PyObject *self, PyObject *args, PyObject *kwargs) static gboolean iowatch_marshal(GIOChannel *source, GIOCondition condition, gpointer user_data) { + PyGILState_STATE state; PyObject *tuple, *func, *firstargs, *args, *ret; gboolean res; g_return_val_if_fail(user_data != NULL, FALSE); pyg_block_threads(); + state = PyGILState_Ensure(); tuple = (PyObject *)user_data; func = PyTuple_GetItem(tuple, 0); @@ -1373,6 +1385,7 @@ iowatch_marshal(GIOChannel *source, GIOCondition condition, gpointer user_data) Py_DECREF(ret); } + PyGILState_Release(state); pyg_unblock_threads(); return res; @@ -1599,6 +1612,8 @@ pyg_flags_add_constants(PyObject *module, GType flags_type, static gboolean pyg_error_check(GError **error) { + PyGILState_STATE state; + g_return_val_if_fail(error != NULL, FALSE); if (*error != NULL) { @@ -1606,6 +1621,7 @@ pyg_error_check(GError **error) PyObject *d; pyg_block_threads(); + state = PyGILState_Ensure(); exc_instance = PyObject_CallFunction(gerror_exc, "z", (*error)->message); @@ -1627,6 +1643,7 @@ pyg_error_check(GError **error) Py_DECREF(exc_instance); g_clear_error(error); + PyGILState_Release(state); pyg_unblock_threads(); return TRUE; @@ -1809,6 +1826,7 @@ initgobject(void) d = PyModule_GetDict(m); #ifdef ENABLE_PYGTK_THREADING + PyEval_InitThreads(); if (!g_threads_got_initialized) g_thread_init(NULL); #endif diff --git a/gobject/pygenum.c b/gobject/pygenum.c index 0f440ad4..69257786 100644 --- a/gobject/pygenum.c +++ b/gobject/pygenum.c @@ -149,6 +149,7 @@ pyg_enum_add (PyObject * module, const char * strip_prefix, GType gtype) { + PyGILState_STATE state; PyObject *instance_dict, *stub, *values; GEnumClass *eclass; int i; @@ -157,6 +158,8 @@ pyg_enum_add (PyObject * module, g_return_val_if_fail(typename != NULL, NULL); g_return_val_if_fail(g_type_is_a(gtype, G_TYPE_ENUM), NULL); + state = PyGILState_Ensure(); + instance_dict = PyDict_New(); stub = PyObject_CallFunction((PyObject *)&PyType_Type, "s(O)O", typename, (PyObject *)&PyGEnum_Type, @@ -164,6 +167,7 @@ pyg_enum_add (PyObject * module, Py_DECREF(instance_dict); if (!stub) { PyErr_SetString(PyExc_RuntimeError, "can't create const"); + PyGILState_Release(state); return NULL; } @@ -205,8 +209,9 @@ pyg_enum_add (PyObject * module, Py_DECREF(values); g_type_class_unref(eclass); - - return stub; + + PyGILState_Release(state); + return stub; } static PyObject * diff --git a/gobject/pygflags.c b/gobject/pygflags.c index d897d8a7..4a8211dd 100644 --- a/gobject/pygflags.c +++ b/gobject/pygflags.c @@ -182,6 +182,7 @@ pyg_flags_add (PyObject * module, const char * strip_prefix, GType gtype) { + PyGILState_STATE state; PyObject *instance_dict, *stub, *values; GFlagsClass *eclass; int i; @@ -190,6 +191,8 @@ pyg_flags_add (PyObject * module, g_return_val_if_fail(typename != NULL, NULL); g_return_val_if_fail(g_type_is_a(gtype, G_TYPE_FLAGS), NULL); + state = PyGILState_Ensure(); + instance_dict = PyDict_New(); stub = PyObject_CallFunction((PyObject *)&PyType_Type, "s(O)O", typename, (PyObject *)&PyGFlags_Type, @@ -197,7 +200,7 @@ pyg_flags_add (PyObject * module, Py_DECREF(instance_dict); if (!stub) { PyErr_SetString(PyExc_RuntimeError, "can't create const"); - return NULL; + PyGILState_Release(state); } PyDict_SetItemString(((PyTypeObject *)stub)->tp_dict, @@ -231,7 +234,7 @@ pyg_flags_add (PyObject * module, strip_prefix), item); Py_INCREF(item); - } + } PyDict_SetItemString(((PyTypeObject *)stub)->tp_dict, "__flags_values__", values); @@ -239,6 +242,8 @@ pyg_flags_add (PyObject * module, g_type_class_unref(eclass); + PyGILState_Release(state); + return stub; } diff --git a/gobject/pygobject.c b/gobject/pygobject.c index 8b33744b..d29d1d78 100644 --- a/gobject/pygobject.c +++ b/gobject/pygobject.c @@ -181,6 +181,7 @@ pygobject_register_wrapper(PyObject *self) PyTypeObject * pygobject_new_with_interfaces(GType gtype) { + PyGILState_STATE state; PyObject *o; PyTypeObject *type; PyObject *dict; @@ -246,10 +247,14 @@ pygobject_new_with_interfaces(GType gtype) type_name = g_strconcat(mod_name, ".", gtype_name, NULL); } + state = PyGILState_Ensure(); + type = (PyTypeObject*)PyObject_CallFunction((PyObject*)&PyType_Type, "sOO", type_name, bases, dict); g_free(type_name); + PyGILState_Release(state); + if (type == NULL) { PyErr_Print(); return NULL; diff --git a/gobject/pygobject.h b/gobject/pygobject.h index 9292cec2..ebddca09 100644 --- a/gobject/pygobject.h +++ b/gobject/pygobject.h @@ -7,8 +7,10 @@ #include <glib.h> #include <glib-object.h> -#if PY_VERSION_HEX < 0x02030000 - typedef destructor freefunc; +#if !(defined ENABLE_PYGTK_THREADING) +# define PyGILState_STATE int +# define PyGILState_Ensure() (0) +# define PyGILState_Release(x) #endif typedef struct { diff --git a/gobject/pygtype.c b/gobject/pygtype.c index edf01f0d..e6b97ff2 100644 --- a/gobject/pygtype.c +++ b/gobject/pygtype.c @@ -133,10 +133,8 @@ pyg_type_from_object(PyObject *obj) if (tp == &PyInt_Type) return G_TYPE_INT; -#if PY_VERSION_HEX >= 0x020300f0 else if (tp == &PyBool_Type) return G_TYPE_BOOLEAN; -#endif else if (tp == &PyLong_Type) return G_TYPE_LONG; else if (tp == &PyFloat_Type) @@ -736,7 +734,6 @@ pyg_closure_invalidate(gpointer data, GClosure *closure) pyg_unblock_threads(); } -/* XXXX - need to handle python thread context stuff */ static void pyg_closure_marshal(GClosure *closure, GValue *return_value, @@ -745,11 +742,14 @@ pyg_closure_marshal(GClosure *closure, gpointer invocation_hint, gpointer marshal_data) { + PyGILState_STATE state; PyGClosure *pc = (PyGClosure *)closure; PyObject *params, *ret; guint i; pyg_block_threads(); + state = PyGILState_Ensure(); + /* construct Python tuple for the parameter values */ params = PyTuple_New(n_param_values); for (i = 0; i < n_param_values; i++) { @@ -763,9 +763,7 @@ pyg_closure_marshal(GClosure *closure, /* error condition */ if (!item) { - Py_DECREF(params); - pyg_unblock_threads(); - return; + goto out; } PyTuple_SetItem(params, i, item); } @@ -779,14 +777,16 @@ pyg_closure_marshal(GClosure *closure, ret = PyObject_CallObject(pc->callback, params); if (ret == NULL) { PyErr_Print(); - Py_DECREF(params); - pyg_unblock_threads(); - return; + goto out; } if (return_value) pyg_value_from_pyobject(return_value, ret); - Py_DECREF(params); Py_DECREF(ret); + + out: + Py_DECREF(params); + + PyGILState_Release(state); pyg_unblock_threads(); } |