summaryrefslogtreecommitdiffstats
path: root/gobject/pygobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'gobject/pygobject.c')
-rw-r--r--gobject/pygobject.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/gobject/pygobject.c b/gobject/pygobject.c
index 84f6ef7..1a16e37 100644
--- a/gobject/pygobject.c
+++ b/gobject/pygobject.c
@@ -558,6 +558,8 @@ pygobject_new_with_interfaces(GType gtype)
PyObject *modules, *module;
gchar *type_name, *mod_name, *gtype_name;
+ state = pyg_gil_state_ensure();
+
interfaces = g_type_interfaces (gtype, &n_interfaces);
bases = PyTuple_New(n_interfaces+1);
@@ -566,6 +568,7 @@ pygobject_new_with_interfaces(GType gtype)
py_parent_type = pygobject_lookup_class(parent_type);
/* We will always put the parent at the first position in bases */
+ Py_INCREF(py_parent_type); /* PyTuple_SetItem steals a reference */
PyTuple_SetItem(bases, 0, (PyObject*)py_parent_type);
/* And traverse interfaces */
@@ -573,6 +576,7 @@ pygobject_new_with_interfaces(GType gtype)
for (i = 0; i < n_interfaces; i++) {
interface_type = interfaces[i];
py_interface_type = pygobject_lookup_class(interface_type);
+ Py_INCREF(py_interface_type); /* PyTuple_SetItem steals a reference */
PyTuple_SetItem(bases, i+1, (PyObject*)py_interface_type);
}
@@ -611,16 +615,14 @@ pygobject_new_with_interfaces(GType gtype)
type_name = g_strconcat(mod_name, ".", gtype_name, NULL);
}
- state = pyg_gil_state_ensure();
- type = (PyTypeObject*)PyObject_CallFunction((PyObject*)&PyType_Type, "sOO",
+ type = (PyTypeObject*)PyObject_CallFunction((PyObject*)&PyType_Type, "sNN",
type_name, bases, dict);
g_free(type_name);
- pyg_gil_state_release(state);
-
if (type == NULL) {
PyErr_Print();
+ pyg_gil_state_release(state);
return NULL;
}
@@ -637,6 +639,7 @@ pygobject_new_with_interfaces(GType gtype)
if (PyType_Ready(type) < 0) {
g_warning ("couldn't make the type `%s' ready", type->tp_name);
+ pyg_gil_state_release(state);
return NULL;
}
@@ -651,6 +654,8 @@ pygobject_new_with_interfaces(GType gtype)
Py_INCREF(type);
g_type_set_qdata(gtype, pygobject_class_key, type);
+ pyg_gil_state_release(state);
+
return type;
}