totem r5742 - in trunk: . src/plugins
- From: hadess svn gnome org
- To: svn-commits-list gnome org
- Subject: totem r5742 - in trunk: . src/plugins
- Date: Tue, 7 Oct 2008 12:50:18 +0000 (UTC)
Author: hadess
Date: Tue Oct 7 12:50:17 2008
New Revision: 5742
URL: http://svn.gnome.org/viewvc/totem?rev=5742&view=rev
Log:
2008-10-07 Bastien Nocera <hadess hadess net>
* src/plugins/totem-python-module.c
(totem_python_module_init_python), (totem_python_module_load):
* src/plugins/totem-python-plugin.c (call_python_method),
(check_py_object_is_gtk_widget), (totem_python_object_init),
(totem_python_object_get_type): Patch from Tim-Philipp MÃller
<tim muller collabora co uk>, Prepare python for use from multiple
threads and add missing locking where applicable
(Closes: #554868)
Modified:
trunk/ChangeLog
trunk/src/plugins/totem-python-module.c
trunk/src/plugins/totem-python-plugin.c
Modified: trunk/src/plugins/totem-python-module.c
==============================================================================
--- trunk/src/plugins/totem-python-module.c (original)
+++ trunk/src/plugins/totem-python-module.c Tue Oct 7 12:50:17 2008
@@ -258,21 +258,31 @@
gettext_args = Py_BuildValue ("ss", GETTEXT_PACKAGE, GNOMELOCALEDIR);
PyObject_CallObject (install, gettext_args);
Py_DECREF (gettext_args);
+
+ /* ideally totem should clean up the python stuff again at some point,
+ * for which we'd need to save the result of SaveThread so we can then
+ * restore the state in a class_finalize or so, but since totem doesn't
+ * do any clean-up at this point, we'll just skip this as well */
+ PyEval_SaveThread();
}
static gboolean
totem_python_module_load (GTypeModule *gmodule)
{
TotemPythonModulePrivate *priv = TOTEM_PYTHON_MODULE_GET_PRIVATE (gmodule);
+ PyGILState_STATE state;
PyObject *main_module, *main_locals, *locals, *key, *value;
PyObject *module, *fromlist;
Py_ssize_t pos = 0;
+ gboolean res = FALSE;
+
+ state = pyg_gil_state_ensure();
main_module = PyImport_AddModule ("__main__");
if (main_module == NULL)
{
g_warning ("Could not get __main__.");
- return FALSE;
+ goto done;
}
/* If we have a special path, we register it */
@@ -296,7 +306,7 @@
Py_DECREF (fromlist);
if (!module) {
PyErr_Print ();
- return FALSE;
+ goto done;
}
locals = PyModule_GetDict (module);
@@ -308,13 +318,17 @@
if (PyObject_IsSubclass (value, (PyObject*) PyTotemPlugin_Type))
{
priv->type = totem_python_object_get_type (gmodule, value);
- return TRUE;
+ res = TRUE;
+ goto done;
}
}
g_debug ("Failed to find any totem.Plugin-derived classes in Python plugin");
- return FALSE;
+done:
+
+ pyg_gil_state_release (state);
+ return res;
}
static void
Modified: trunk/src/plugins/totem-python-plugin.c
==============================================================================
--- trunk/src/plugins/totem-python-plugin.c (original)
+++ trunk/src/plugins/totem-python-plugin.c Tue Oct 7 12:50:17 2008
@@ -39,8 +39,11 @@
TotemObject *totem,
gchar *method)
{
+ PyGILState_STATE state;
PyObject *py_ret = NULL;
+ state = pyg_gil_state_ensure();
+
g_return_val_if_fail (PyObject_HasAttrString (object->instance, method), NULL);
if (totem == NULL) {
@@ -57,6 +60,8 @@
if (!py_ret)
PyErr_Print ();
+ pyg_gil_state_release (state);
+
return py_ret;
}
@@ -64,6 +69,10 @@
check_py_object_is_gtk_widget (PyObject *py_obj)
{
static PyTypeObject *_PyGtkWidget_Type = NULL;
+ PyGILState_STATE state;
+ gboolean res = FALSE;
+
+ state = pyg_gil_state_ensure();
if (_PyGtkWidget_Type == NULL) {
PyObject *module;
@@ -76,12 +85,16 @@
if (_PyGtkWidget_Type == NULL) {
PyErr_SetString(PyExc_TypeError, "could not find python gtk widget type");
PyErr_Print();
-
- return FALSE;
+ res = FALSE;
+ goto done;
}
}
- return PyObject_TypeCheck (py_obj, _PyGtkWidget_Type) ? TRUE : FALSE;
+ res = PyObject_TypeCheck (py_obj, _PyGtkWidget_Type) ? TRUE : FALSE;
+
+done:
+ pyg_gil_state_release (state);
+ return res;
}
static void
@@ -180,6 +193,9 @@
totem_python_object_init (TotemPythonObject *object)
{
TotemPythonObjectClass *class;
+ PyGILState_STATE state;
+
+ state = pyg_gil_state_ensure();
g_debug ("Creating Python plugin instance");
@@ -188,6 +204,8 @@
object->instance = PyObject_CallObject (class->type, NULL);
if (object->instance == NULL)
PyErr_Print();
+
+ pyg_gil_state_release (state);
}
static void
@@ -240,6 +258,10 @@
(GInstanceInitFunc) totem_python_object_init
};
+ /* no need for pyg_gil_state_ensure() here since this function is only
+ * used from within totem_python_module_load() where this is already
+ * done */
+
Py_INCREF (type);
type_name = g_strdup_printf ("%s+TotemPythonPlugin",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]