Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/ChangeLog,v
retrieving revision 1.429
diff -u -p -r1.429 ChangeLog
--- ChangeLog	2002/07/07 14:31:43	1.429
+++ ChangeLog	2002/07/08 11:41:15
@@ -1,3 +1,9 @@
+2002-07-06  Arjan Molenaar  <arjanmolenaar@hetnet.nl>
+
+	* pygtype.c, pygobject.c: Made signals collectable by the Python GC.
+	* pygtype.c (pyg_closure_marshal): Added missing Py_DECREF()'s
+	* pygobject.c (pygobject_connect): Added missing Py_DECREF()
+
 2002-07-07  James Henstridge  <james@daa.com.au>
 
 	* pygobject.c (pygobject_get_refcount): add __grefcount__ property.
Index: gobjectmodule.c
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/gobjectmodule.c,v
retrieving revision 1.102
diff -u -p -r1.102 gobjectmodule.c
--- gobjectmodule.c	2002/06/23 13:56:45	1.102
+++ gobjectmodule.c	2002/07/08 11:41:18
@@ -1293,8 +1293,8 @@ struct _PyGObject_Functions pygobject_ap
   pygobject_register_wrapper,
   pygobject_lookup_class,
   pygobject_new,
+  pygobject_closure_new,
 
-  pyg_closure_new,
   pyg_destroy_notify,
 
   pyg_type_from_object,
Index: pygobject-private.h
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/pygobject-private.h,v
retrieving revision 1.10
diff -u -p -r1.10 pygobject-private.h
--- pygobject-private.h	2002/06/23 13:56:46	1.10
+++ pygobject-private.h	2002/07/08 11:41:18
@@ -53,6 +53,9 @@ int       pyg_value_from_pyobject(GValue
 PyObject *pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed);
 
 GClosure *pyg_closure_new(PyObject *callback, PyObject *extra_args, PyObject *swap_data);
+int pyg_closure_visit (GClosure *closure, visitproc visit, void *arg);
+void pyg_closure_clear (GClosure *closure);
+
 GClosure *pyg_signal_class_closure_get(void);
 
 PyObject *pyg_object_descr_doc_get(void);
@@ -68,6 +71,10 @@ void          pygobject_register_class  
 void          pygobject_register_wrapper (PyObject *self);
 PyObject *    pygobject_new              (GObject *obj);
 PyTypeObject *pygobject_lookup_class     (GType gtype);
+GClosure *    pygobject_closure_new      (PyObject *self,
+					  PyObject *callback,
+					  PyObject *extra_args,
+					  PyObject *swap_data);
 
 
 /* from pygboxed.c */
Index: pygobject.c
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/pygobject.c,v
retrieving revision 1.5
diff -u -p -r1.5 pygobject.c
--- pygobject.c	2002/07/07 14:31:43	1.5
+++ pygobject.c	2002/07/08 11:41:19
@@ -11,6 +11,7 @@ static GQuark       pygobject_ownedref_k
 
 static void pygobject_dealloc(PyGObject *self);
 static int  pygobject_traverse(PyGObject *self, visitproc visit, void *arg);
+static int  pygobject_clear(PyGObject *self);
 
 /* -------------- class <-> wrapper manipulation --------------- */
 
@@ -38,6 +39,7 @@ pygobject_register_class(PyObject *dict,
 
     type->tp_dealloc  = (destructor)pygobject_dealloc;
     type->tp_traverse = (traverseproc)pygobject_traverse;
+    type->tp_clear = (inquiry)pygobject_clear;
     type->tp_flags |= Py_TPFLAGS_HAVE_GC;
     type->tp_weaklistoffset = offsetof(PyGObject, weakreflist);
     type->tp_dictoffset = offsetof(PyGObject, inst_dict);
@@ -127,6 +129,8 @@ pygobject_new(GObject *obj)
     self->hasref = FALSE;
     self->inst_dict = NULL;
     self->weakreflist = NULL;
+    self->closures = NULL;
+
     /* save wrapper pointer so we can access it later */
     g_object_set_qdata(obj, pygobject_wrapper_key, self);
 
@@ -152,6 +156,7 @@ pygobject_dealloc(PyGObject *self)
      * wrapper, but if a python wrapper can be */
     if (obj && obj->ref_count > 1) {
 	Py_INCREF(self); /* grab a reference on the wrapper */
+	//g_message (__FUNCTION__": refcount = %s %d/%d", G_OBJECT_TYPE_NAME(obj), ((PyObject*)self)->ob_refcnt, obj->ref_count);
 	self->hasref = TRUE;
 	g_object_set_qdata_full(obj, pygobject_ownedref_key,
 				self, pyg_destroy_notify);
@@ -182,6 +187,14 @@ pygobject_dealloc(PyGObject *self)
     }
     self->inst_dict = NULL;
 
+    if (self->closures) {
+	GSList *c;
+	for (c = self->closures; c != NULL; c = c->next)
+	    pyg_closure_clear(c->data);
+	g_slist_free (self->closures);
+    }
+    self->closures = NULL;
+
     /* the following causes problems with subclassed types */
     /*self->ob_type->tp_free((PyObject *)self); */
     PyObject_GC_Del(self);
@@ -217,11 +230,35 @@ pygobject_repr(PyGObject *self)
 static int
 pygobject_traverse(PyGObject *self, visitproc visit, void *arg)
 {
-    if (self->inst_dict)
-	return visit(self->inst_dict, arg);
+    int err = 0;
+    GSList *c;
+    if (self->inst_dict) {
+	err = visit(self->inst_dict, arg);
+	if (err)
+	    return err;
+    }
+    for (c = self->closures; c != NULL; c = c->next) {
+	err = pyg_closure_visit(c->data, visit, arg);
+	if (err)
+	    return err;
+    }
     return 0;
 }
 
+static int
+pygobject_clear(PyGObject *self)
+{
+    GSList *c;
+
+    for (c = self->closures; c != NULL; c = c->next)
+	pyg_closure_clear(c->data);
+    if (self->closures)
+	g_slist_free (self->closures);
+    self->closures = NULL;
+
+    return 0;
+}
+
 static void
 pygobject_free(PyObject *op)
 {
@@ -326,6 +363,32 @@ pygobject__gobject_init__(PyGObject *sel
     return Py_None;
 }
 
+static void
+pygobject_closure_destroy(gpointer data, GClosure *closure)
+{
+    PyGObject *self = data;
+    //g_message(__FUNCTION__": destroying closure finalizer %p", closure);
+    self->closures = g_slist_remove (self->closures, closure);
+}
+
+GClosure*
+pygobject_closure_new(PyObject *self, PyObject *callback,
+		      PyObject *extra_args, PyObject *swap_data)
+{
+    GClosure *closure;
+    PyGObject *gself = (PyGObject*) self;
+
+    //g_message (__FUNCTION__": begin %d %d", callback->ob_refcnt, extra_args->ob_refcnt);
+    closure = pyg_closure_new(callback, extra_args, swap_data);
+    if (closure) {
+	gself->closures = g_slist_prepend (gself->closures, closure);
+	g_closure_add_finalize_notifier(closure, self,
+					pygobject_closure_destroy);
+    }
+    //g_message (__FUNCTION__": end %d %d", callback->ob_refcnt, extra_args->ob_refcnt);
+    return closure;
+}
+
 static PyObject *
 pygobject_get_property(PyGObject *self, PyObject *args)
 {
@@ -477,7 +540,8 @@ pygobject_connect(PyGObject *self, PyObj
     if (extra_args == NULL)
 	return NULL;
     handlerid = g_signal_connect_closure_by_id(self->obj, sigid, detail,
-			pyg_closure_new(callback, extra_args, NULL), FALSE);
+			pygobject_closure_new((PyObject *)self, callback, extra_args, NULL), FALSE);
+    Py_DECREF (extra_args);
     return PyInt_FromLong(handlerid);
 }
 
@@ -515,7 +579,7 @@ pygobject_connect_after(PyGObject *self,
     if (extra_args == NULL)
 	return NULL;
     handlerid = g_signal_connect_closure_by_id(self->obj, sigid, detail,
-			pyg_closure_new(callback, extra_args, NULL), TRUE);
+			pygobject_closure_new((PyObject *)self, callback, extra_args, NULL), TRUE);
     return PyInt_FromLong(handlerid);
 }
 
@@ -553,7 +617,7 @@ pygobject_connect_object(PyGObject *self
     if (extra_args == NULL)
 	return NULL;
     handlerid = g_signal_connect_closure_by_id(self->obj, sigid, detail,
-			pyg_closure_new(callback, extra_args, object), FALSE);
+			pygobject_closure_new((PyObject *)self, callback, extra_args, object), FALSE);
     return PyInt_FromLong(handlerid);
 }
 
@@ -591,7 +655,7 @@ pygobject_connect_object_after(PyGObject
     if (extra_args == NULL)
 	return NULL;
     handlerid = g_signal_connect_closure_by_id(self->obj, sigid, detail,
-			pyg_closure_new(callback, extra_args, object), TRUE);
+			pygobject_closure_new((PyObject *)self, callback, extra_args, object), TRUE);
     return PyInt_FromLong(handlerid);
 }
 
@@ -872,6 +936,7 @@ PyTypeObject PyGObject_Type = {
     NULL, /* Documentation string */
     (traverseproc)pygobject_traverse,	/* tp_traverse */
     (inquiry)0,				/* tp_clear */
+    //(inquiry)pygobject_clear,		/* tp_clear */
     (richcmpfunc)0,			/* tp_richcompare */
     offsetof(PyGObject, weakreflist),	/* tp_weaklistoffset */
     (getiterfunc)0,			/* tp_iter */
Index: pygobject.h
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/pygobject.h,v
retrieving revision 1.26
diff -u -p -r1.26 pygobject.h
--- pygobject.h	2002/06/23 13:56:46	1.26
+++ pygobject.h	2002/07/08 11:41:19
@@ -13,6 +13,7 @@ typedef struct {
     gboolean hasref;     /* the GObject owns this reference */
     PyObject *inst_dict; /* the instance dictionary -- must be last */
     PyObject *weakreflist; /* list of weak references */
+    GSList *closures;
 } PyGObject;
 
 #define pygobject_get(v) (((PyGObject *)(v))->obj)
@@ -47,8 +48,8 @@ struct _PyGObject_Functions {
     PyTypeObject *(* lookup_class)(GType type);
     PyObject *(* newgobj)(GObject *obj);
 
-    GClosure *(* closure_new)(PyObject *callback, PyObject *extra_args,
-			      PyObject *swap_data);
+    GClosure *(* closure_new)(PyObject *self, PyObject *callback,
+			      PyObject *extra_args, PyObject *swap_data);
     GDestroyNotify destroy_notify;
 
     GType (* type_from_object)(PyObject *obj);
@@ -106,7 +107,7 @@ struct _PyGObject_Functions *_PyGObject_
 #define pygobject_register_wrapper (_PyGObject_API->register_wrapper)
 #define pygobject_lookup_class     (_PyGObject_API->lookup_class)
 #define pygobject_new              (_PyGObject_API->newgobj)
-#define pyg_closure_new            (_PyGObject_API->closure_new)
+#define pygobject_closure_new      (_PyGObject_API->closure_new)
 #define pyg_destroy_notify         (_PyGObject_API->destroy_notify)
 #define pyg_type_from_object       (_PyGObject_API->type_from_object)
 #define pyg_type_wrapper_new       (_PyGObject_API->type_wrapper_new)
Index: pygtype.c
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/pygtype.c,v
retrieving revision 1.13
diff -u -p -r1.13 pygtype.c
--- pygtype.c	2002/07/07 12:45:43	1.13
+++ pygtype.c	2002/07/08 11:41:20
@@ -624,10 +628,14 @@ pyg_closure_destroy(gpointer data, GClos
 {
     PyGClosure *pc = (PyGClosure *)closure;
 
+    //g_message (__FUNCTION__": %p", closure);
     pyg_block_threads();
-    Py_DECREF(pc->callback);
+    Py_XDECREF(pc->callback);
+    pc->callback = NULL;
     Py_XDECREF(pc->extra_args);
+    pc->extra_args = NULL;
     Py_XDECREF(pc->swap_data);
+    pc->swap_data = NULL;
     pyg_unblock_threads();
 }
 
@@ -644,6 +652,13 @@ pyg_closure_marshal(GClosure *closure,
     PyObject *params, *ret;
     guint i;
 
+    /* In case the signal is invoked, but it is already removed by the
+     * Python GC, we should not try to invoke it anyway... */
+    if (pc->callback == NULL)
+	return;
+
+    //g_message (__FUNCTION__);
+
     pyg_block_threads();
     /* construct Python tuple for the parameter values */
     params = PyTuple_New(n_param_values);
@@ -672,6 +687,7 @@ pyg_closure_marshal(GClosure *closure,
 	Py_DECREF(tuple);
     }
     ret = PyObject_CallObject(pc->callback, params);
+    Py_DECREF (params);
     if (ret == NULL) {
 	PyErr_Print();
 	PyErr_Clear();
@@ -693,6 +709,7 @@ pyg_closure_new(PyObject *callback, PyOb
 
     g_return_val_if_fail(callback != NULL, NULL);
     closure = g_closure_new_simple(sizeof(PyGClosure), NULL);
+    //g_message (__FUNCTION__": creating closure %p", closure);
     g_closure_add_finalize_notifier(closure, NULL, pyg_closure_destroy);
     g_closure_set_marshal(closure, pyg_closure_marshal);
     Py_INCREF(callback);
@@ -712,6 +729,47 @@ pyg_closure_new(PyObject *callback, PyOb
 	closure->derivative_flag = TRUE;
     }
     return closure;
+}
+
+int
+pyg_closure_visit(GClosure *closure, visitproc visit, void *arg)
+{
+    int err = 0;
+    PyGClosure *pc = (PyGClosure *)closure;
+
+    pyg_block_threads();
+    //g_message (__FUNCTION__": visiting closure %p", closure);
+
+    if (pc->callback)
+	err = visit (pc->callback, arg);
+
+    if (!err && pc->extra_args)
+	err = visit (pc->extra_args, arg);
+
+    if (!err && pc->swap_data)
+	err = visit (pc->swap_data, arg);
+
+    pyg_unblock_threads();
+
+    return err;
+}
+
+void
+pyg_closure_clear (GClosure *closure)
+{
+    PyGClosure *pc = (PyGClosure *)closure;
+
+    pyg_block_threads();
+    //g_message (__FUNCTION__": clearing closure %p", closure);
+    g_closure_remove_finalize_notifier(closure,
+				       NULL, pyg_closure_destroy);
+    Py_XDECREF(pc->callback);
+    pc->callback = NULL;
+    Py_XDECREF(pc->extra_args);
+    pc->extra_args = NULL;
+    Py_XDECREF(pc->swap_data);
+    pc->swap_data = NULL;
+    pyg_unblock_threads();
 }
 
 /* -------------- PySignalClassClosure ----------------- */
Index: gtk/gtk.override
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/gtk/gtk.override,v
retrieving revision 1.136
diff -u -p -r1.136 gtk.override
--- gtk/gtk.override	2002/07/07 13:19:29	1.136
+++ gtk/gtk.override	2002/07/08 11:41:27
@@ -4034,7 +4034,7 @@ _wrap_gtk_toolbar_append_item(PyGObject 
 			      "icon", "callback", "user_data", NULL };
     char *text, *tooltip_text, *tooltip_private_text;
     PyGObject *py_icon;
-    PyObject *callback, *param=NULL;
+    PyObject *callback, *param=NULL, *py_ret;
     GtkWidget *icon = NULL, *ret;
 
     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
@@ -4052,12 +4052,13 @@ _wrap_gtk_toolbar_append_item(PyGObject 
     }
     ret = gtk_toolbar_append_item(GTK_TOOLBAR(self->obj), text, tooltip_text,
 				  tooltip_private_text, icon, NULL, NULL);
+    py_ret = pygobject_new((GObject*) ret);
     if (ret && PyCallable_Check(callback)) {
 	g_signal_connect_closure(ret, "clicked",
-				 pyg_closure_new(callback, param, NULL),
+				 pygobject_closure_new(py_ret, callback, param, NULL),
 				 FALSE);
     }
-    return pygobject_new((GObject *)ret);
+    return py_ret;
 }
 %%
 override gtk_toolbar_prepend_item kwargs
@@ -4069,7 +4070,7 @@ _wrap_gtk_toolbar_prepend_item(PyGObject
 			      "icon", "callback", "user_data", NULL };
     char *text, *tooltip_text, *tooltip_private_text;
     PyGObject *py_icon;
-    PyObject *callback, *param;
+    PyObject *callback, *param, *py_ret;
     GtkWidget *icon = NULL, *ret;
 
     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
@@ -4087,12 +4088,13 @@ _wrap_gtk_toolbar_prepend_item(PyGObject
     }
     ret = gtk_toolbar_prepend_item(GTK_TOOLBAR(self->obj), text, tooltip_text,
 				  tooltip_private_text, icon, NULL, NULL);
+    py_ret = pygobject_new((GObject *)ret);
     if (ret && PyCallable_Check(callback)) {
 	g_signal_connect_closure(ret, "clicked",
-				 pyg_closure_new(callback, param, NULL),
+				 pygobject_closure_new(py_ret, callback, param, NULL),
 				 FALSE);
     }
-    return pygobject_new((GObject *)ret);
+    return py_ret;
 }
 %%
 override gtk_toolbar_insert_item kwargs
@@ -4105,7 +4107,7 @@ _wrap_gtk_toolbar_insert_item(PyGObject 
 			      NULL };
     char *text, *tooltip_text, *tooltip_private_text;
     PyGObject *py_icon;
-    PyObject *callback, *param;
+    PyObject *callback, *param, *py_ret;
     GtkWidget *icon = NULL, *ret;
     int position;
 
@@ -4125,12 +4127,13 @@ _wrap_gtk_toolbar_insert_item(PyGObject 
     ret = gtk_toolbar_insert_item(GTK_TOOLBAR(self->obj), text, tooltip_text,
 				  tooltip_private_text, icon, NULL, NULL,
 				  position);
+    py_ret = pygobject_new((GObject *)ret);
     if (ret && PyCallable_Check(callback)) {
 	g_signal_connect_closure(ret, "clicked",
-				 pyg_closure_new(callback, param, NULL),
+				 pygobject_closure_new(py_ret, callback, param, NULL),
 				 FALSE);
     }
-    return pygobject_new((GObject *)ret);
+    return py_ret;
 }
 %%
 override gtk_toolbar_insert_stock kwargs
@@ -4142,7 +4145,7 @@ _wrap_gtk_toolbar_insert_stock(PyGObject
 			      "callback", "user_data", "position",
 			      NULL };
     char *stock_id, *tooltip_text, *tooltip_private_text;
-    PyObject *callback, *param;
+    PyObject *callback, *param, *py_ret;
     GtkWidget *ret;
     int position;
 
@@ -4156,12 +4159,13 @@ _wrap_gtk_toolbar_insert_stock(PyGObject
     ret = gtk_toolbar_insert_stock(GTK_TOOLBAR(self->obj), stock_id, tooltip_text,
 				  tooltip_private_text, NULL, NULL,
 				  position);
+    py_ret = pygobject_new((GObject *)ret);
     if (ret && PyCallable_Check(callback)) {
 	g_signal_connect_closure(ret, "clicked",
-				 pyg_closure_new(callback, param, NULL),
+				 pygobject_closure_new(py_ret, callback, param, NULL),
 				 FALSE);
     }
-    return pygobject_new((GObject *)ret);
+    return py_ret;
 }
 %%
 override gtk_toolbar_append_element kwargs
@@ -4173,7 +4177,7 @@ _wrap_gtk_toolbar_append_element(PyGObje
 			      "tooltip_private_text", "icon", "callback",
 			      "user_data", NULL };
     char *text, *tooltip_text, *tooltip_private_text;
-    PyObject *py_type, *callback, *param;
+    PyObject *py_type, *callback, *param, *py_ret;
     PyGObject *py_widget, *py_icon;
     GtkWidget *widget = NULL, *icon = NULL, *ret;
     GtkToolbarChildType type;
@@ -4206,15 +4210,16 @@ _wrap_gtk_toolbar_append_element(PyGObje
     ret = gtk_toolbar_append_element(GTK_TOOLBAR(self->obj), type, widget,
 				     text, tooltip_text, tooltip_private_text,
 				     icon, NULL, NULL);
+    py_ret = pygobject_new ((GObject *)ret);
     if (ret && PyCallable_Check(callback) &&
 	(type == GTK_TOOLBAR_CHILD_BUTTON ||
 	 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
 	 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)) {
 	g_signal_connect_closure(ret, "clicked",
-				 pyg_closure_new(callback, param, NULL),
+				 pygobject_closure_new(py_ret, callback, param, NULL),
 				 FALSE);
     }
-    return pygobject_new((GObject *)ret);
+    return py_ret;
 }
 %%
 override gtk_toolbar_prepend_element kwargs
@@ -4226,7 +4231,7 @@ _wrap_gtk_toolbar_prepend_element(PyGObj
 			      "tooltip_private_text", "icon", "callback",
 			      "user_data", NULL };
     char *text, *tooltip_text, *tooltip_private_text;
-    PyObject *py_type, *callback, *param;
+    PyObject *py_type, *callback, *param, *py_ret;
     PyGObject *py_widget, *py_icon;
     GtkWidget *widget = NULL, *icon = NULL, *ret;
     GtkToolbarChildType type;
@@ -4259,15 +4264,16 @@ _wrap_gtk_toolbar_prepend_element(PyGObj
     ret = gtk_toolbar_prepend_element(GTK_TOOLBAR(self->obj), type, widget,
 				      text, tooltip_text, tooltip_private_text,
 				      icon, NULL, NULL);
+    py_ret = pygobject_new((GObject *)ret);
     if (ret && PyCallable_Check(callback) &&
 	(type == GTK_TOOLBAR_CHILD_BUTTON ||
 	 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
 	 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)) {
 	g_signal_connect_closure(ret, "clicked",
-				 pyg_closure_new(callback, param, NULL),
+				 pygobject_closure_new(py_ret, callback, param, NULL),
 				 FALSE);
     }
-    return pygobject_new((GObject *)ret);
+    return py_ret;
 }
 %%
 override gtk_toolbar_insert_element kwargs
@@ -4279,7 +4285,7 @@ _wrap_gtk_toolbar_insert_element(PyGObje
 			      "tooltip_private_text", "icon", "callback",
 			      "user_data", "position", NULL };
     char *text, *tooltip_text, *tooltip_private_text;
-    PyObject *py_type, *callback, *param;
+    PyObject *py_type, *callback, *param, *py_ret;
     PyGObject *py_widget, *py_icon;
     GtkWidget *widget = NULL, *icon = NULL, *ret;
     GtkToolbarChildType type;
@@ -4313,15 +4319,16 @@ _wrap_gtk_toolbar_insert_element(PyGObje
     ret = gtk_toolbar_insert_element(GTK_TOOLBAR(self->obj), type, widget,
 				     text, tooltip_text, tooltip_private_text,
 				     icon, NULL, NULL, position);
+    py_ret = pygobject_new((GObject *)ret);
     if (ret && PyCallable_Check(callback) &&
 	(type == GTK_TOOLBAR_CHILD_BUTTON ||
 	 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
 	 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)) {
 	g_signal_connect_closure(ret, "clicked",
-				 pyg_closure_new(callback, param, NULL),
+				 pygobject_closure_new(py_ret, callback, param, NULL),
 				 FALSE);
     }
-    return pygobject_new((GObject *)ret);
+    return py_ret;
 }
 %%
 override gtk_notebook_query_tab_label_packing kwargs
Index: gtk/libglade.override
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/gtk/libglade.override,v
retrieving revision 1.14
diff -u -p -r1.14 libglade.override
--- gtk/libglade.override	2002/04/16 19:46:34	1.14
+++ gtk/libglade.override	2002/07/08 11:41:28
@@ -34,15 +34,17 @@ connect_one(const gchar *handler_name, G
     GClosure *closure = NULL;
     PyObject *callback = PyTuple_GetItem((PyObject *)user_data, 0);
     PyObject *extra = PyTuple_GetItem((PyObject *)user_data, 1);
+    PyObject *self = pygobject_new(obj);
 
     if (connect_object) {
         PyObject *other;
 
         other = pygobject_new(connect_object);
-	closure = pyg_closure_new(callback, extra, other);
+	closure = pygobject_closure_new(self, callback, extra, other);
     } else {
-	closure = pyg_closure_new(callback, extra, NULL);
+	closure = pygobject_closure_new(self, callback, extra, NULL);
     }
+    Py_DECREF (self);
 
     g_signal_connect_closure(obj, signal_name, closure, after);
 }
@@ -103,19 +105,23 @@ connect_many(const gchar *handler_name, 
 	PyObject *callback = PyTuple_GetItem(tuple, 0);
 	PyObject *extra = PySequence_GetSlice(tuple, 1, PyTuple_Size(tuple));
 	PyObject *other = NULL;
+	PyObject *self = pygobject_new(obj);
 
 	if (connect_object)
 	    other = pygobject_new((GObject *)connect_object);
 
-	closure = pyg_closure_new(callback, extra, other);
+	closure = pygobject_closure_new(self, callback, extra, other);
+	Py_DECREF(self);
 	Py_DECREF(extra);
     } else if (PyCallable_Check(tuple)) {
 	PyObject *other = NULL;
+	PyObject *self = pygobject_new(obj);
 
 	if (connect_object)
 	    other = pygobject_new((GObject *)connect_object);
 
-	closure = pyg_closure_new(tuple, NULL, other);
+	closure = pygobject_closure_new(self, tuple, NULL, other);
+	Py_DECREF(self);
     } else {
 	g_warning("handler for `%s' not callable or a tuple", handler_name);
 	Py_DECREF(tuple);
