[pygtk] Protect window objects from GC in gtk.window_get_toplevels()



commit e955848c108b37fea4825c3ca539e931b87e6bca
Author: Gustavo Carneiro <gjc inescporto pt>
Date:   Thu Jun 18 00:26:25 2009 +0300

    Protect window objects from GC in gtk.window_get_toplevels()
    
    Fixes bug #574259.

 gtk/gtkwindow.override |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkwindow.override b/gtk/gtkwindow.override
index 58264eb..c694229 100644
--- a/gtk/gtkwindow.override
+++ b/gtk/gtkwindow.override
@@ -34,13 +34,20 @@ _wrap_gtk_window_list_toplevels(PyGObject *self)
 
     list = gtk_window_list_toplevels();
 
+    /* See bug #574259.  We temporarily reference each window.  After
+     * the list is created, windows will be referenced from PyGTK
+     * wrappers, so we remove the temporary refs. */
+    g_list_foreach(list, (GFunc) g_object_ref, NULL);
+    
     if ((py_list = PyList_New(0)) == NULL) {
+        g_list_foreach(list, (GFunc) g_object_unref, NULL);
         g_list_free(list);
         return NULL;
     }
     for (tmp = list; tmp != NULL; tmp = tmp->next) {
         gtk_obj = pygobject_new(G_OBJECT(tmp->data));
         if (gtk_obj == NULL) {
+            g_list_foreach(list, (GFunc) g_object_unref, NULL);
             g_list_free(list);
             Py_DECREF(py_list);
             return NULL;
@@ -48,6 +55,8 @@ _wrap_gtk_window_list_toplevels(PyGObject *self)
         PyList_Append(py_list, gtk_obj);
         Py_DECREF(gtk_obj);
     }
+
+    g_list_foreach(list, (GFunc) g_object_unref, NULL);
     g_list_free(list);
     return py_list;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]