[pygobject] Fix refcount bug by not creating python wrapper during gobject init stage
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix refcount bug by not creating python wrapper during gobject init stage
- Date: Thu, 15 Sep 2011 19:02:11 +0000 (UTC)
commit f6fa5dd8f39af1b8a52d7600d257400b0983e8c5
Author: John (J5) Palmieri <johnp redhat com>
Date: Wed Sep 14 20:26:15 2011 -0400
Fix refcount bug by not creating python wrapper during gobject init stage
* This only applys to python subclasses of GObject which are instantiated
using GObject.new
* Because we were creating the wrapper when the gobject is initialized
and then again calling pygobject_new_full the wrapper would get
ref'ed twice.
* we could not simply Py_DECREF the wrapper due to the fact that
non-subclassed objects (e.g. GObject.Object) instantiated via
new do not run the same initialization code and would not have the
extra ref
* solution was to simply not create the wrapper during initialization
because if it doesn't exist when pygobject_new_full is called
it gets created and registered there
* move the call to __init__ into pyg_object_new
https://bugzilla.gnome.org/show_bug.cgi?id=657403
gi/_gobject/gobjectmodule.c | 32 +++++++++++++++-----------------
1 files changed, 15 insertions(+), 17 deletions(-)
---
diff --git a/gi/_gobject/gobjectmodule.c b/gi/_gobject/gobjectmodule.c
index 3ef7842..7f86949 100644
--- a/gi/_gobject/gobjectmodule.c
+++ b/gi/_gobject/gobjectmodule.c
@@ -1048,7 +1048,7 @@ pygobject__g_instance_init(GTypeInstance *instance,
gpointer g_class)
{
GObject *object = (GObject *) instance;
- PyObject *wrapper, *args, *kwargs;
+ PyObject *wrapper;
wrapper = g_object_get_qdata(object, pygobject_wrapper_key);
if (wrapper == NULL) {
@@ -1059,22 +1059,6 @@ pygobject__g_instance_init(GTypeInstance *instance,
}
}
pygobject_init_wrapper_set(NULL);
- if (wrapper == NULL) {
- /* this looks like a python object created through
- * g_object_new -> we have no python wrapper, so create it
- * now */
- PyGILState_STATE state;
- state = pyglib_gil_state_ensure();
- wrapper = pygobject_new_full(object, FALSE, g_class);
- args = PyTuple_New(0);
- kwargs = PyDict_New();
- if (Py_TYPE(wrapper)->tp_init(wrapper, args, kwargs))
- PyErr_Print();
-
- Py_DECREF(args);
- Py_DECREF(kwargs);
- pyglib_gil_state_release(state);
- }
}
@@ -1746,8 +1730,22 @@ pyg_object_new (PyGObject *self, PyObject *args, PyObject *kwargs)
g_type_class_unref(class);
if (obj) {
+ PyObject *empty_args;
+ PyObject *empty_kwargs;
+ PyGILState_STATE state;
+
pygobject_sink (obj);
self = (PyGObject *) pygobject_new_full((GObject *)obj, FALSE, NULL);
+ empty_args = PyTuple_New(0);
+ empty_kwargs = PyDict_New();
+
+ state = pyglib_gil_state_ensure();
+ if (Py_TYPE(self)->tp_init((PyObject *)self, empty_args, empty_kwargs))
+ PyErr_Print();
+ pyglib_gil_state_release(state);
+
+ Py_DECREF(empty_args);
+ Py_DECREF(empty_kwargs);
g_object_unref(obj);
} else
self = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]