From 82877f9ee919f8a19060a219bfe5f94d8fa17f94 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 20 Jul 2004 17:10:24 +0000 Subject: [PATCH] Add some refcount debugging. 2004-07-20 Matthias Clasen * tests/testactions.c (main): * tests/testmerge.c (main): Add some refcount debugging. * gtk/gtkuimanager.c (update_node, free_node): Ref an sink all proxies, so that we can properly clean up floating proxies which the app didn't adopt. (#147926, Tommi Komulainen) --- ChangeLog | 9 +++++++++ ChangeLog.pre-2-10 | 9 +++++++++ ChangeLog.pre-2-6 | 9 +++++++++ ChangeLog.pre-2-8 | 9 +++++++++ gtk/gtkuimanager.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- tests/testactions.c | 26 ++++++++++++++++++++++++-- tests/testmerge.c | 36 ++++++++++++++++++++++++++++++++++-- 7 files changed, 136 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index bfd6b74925..beea8adc22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-07-20 Matthias Clasen + + * tests/testactions.c (main): + * tests/testmerge.c (main): Add some refcount debugging. + + * gtk/gtkuimanager.c (update_node, free_node): Ref an sink + all proxies, so that we can properly clean up floating proxies + which the app didn't adopt. (#147926, Tommi Komulainen) + 2004-07-20 Matthias Clasen Allow custom initialization of cell editables. (#147221) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index bfd6b74925..beea8adc22 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +2004-07-20 Matthias Clasen + + * tests/testactions.c (main): + * tests/testmerge.c (main): Add some refcount debugging. + + * gtk/gtkuimanager.c (update_node, free_node): Ref an sink + all proxies, so that we can properly clean up floating proxies + which the app didn't adopt. (#147926, Tommi Komulainen) + 2004-07-20 Matthias Clasen Allow custom initialization of cell editables. (#147221) diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index bfd6b74925..beea8adc22 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,12 @@ +2004-07-20 Matthias Clasen + + * tests/testactions.c (main): + * tests/testmerge.c (main): Add some refcount debugging. + + * gtk/gtkuimanager.c (update_node, free_node): Ref an sink + all proxies, so that we can properly clean up floating proxies + which the app didn't adopt. (#147926, Tommi Komulainen) + 2004-07-20 Matthias Clasen Allow custom initialization of cell editables. (#147221) diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index bfd6b74925..beea8adc22 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,12 @@ +2004-07-20 Matthias Clasen + + * tests/testactions.c (main): + * tests/testmerge.c (main): Add some refcount debugging. + + * gtk/gtkuimanager.c (update_node, free_node): Ref an sink + all proxies, so that we can properly clean up floating proxies + which the app didn't adopt. (#147926, Tommi Komulainen) + 2004-07-20 Matthias Clasen Allow custom initialization of cell editables. (#147221) diff --git a/gtk/gtkuimanager.c b/gtk/gtkuimanager.c index 220a2c2bd7..db582444db 100644 --- a/gtk/gtkuimanager.c +++ b/gtk/gtkuimanager.c @@ -954,6 +954,10 @@ free_node (GNode *node) if (info->action) g_object_unref (info->action); + if (info->proxy) + g_object_unref (info->proxy); + if (info->extra) + g_object_unref (info->extra); g_free (info->name); g_chunk_free (info, merge_node_chunk); @@ -2124,6 +2128,8 @@ update_node (GtkUIManager *self, if (info->proxy == NULL) { info->proxy = gtk_menu_bar_new (); + g_object_ref (info->proxy); + gtk_object_sink (info->proxy); gtk_widget_set_name (info->proxy, info->name); gtk_widget_show (info->proxy); g_signal_emit (self, ui_manager_signals[ADD_WIDGET], 0, info->proxy); @@ -2131,7 +2137,11 @@ update_node (GtkUIManager *self, break; case NODE_TYPE_POPUP: if (info->proxy == NULL) - info->proxy = gtk_menu_new (); + { + info->proxy = gtk_menu_new (); + g_object_ref (info->proxy); + gtk_object_sink (info->proxy); + } gtk_widget_set_name (info->proxy, info->name); break; case NODE_TYPE_MENU: @@ -2152,6 +2162,7 @@ update_node (GtkUIManager *self, gtk_action_disconnect_proxy (info->action, info->proxy); gtk_container_remove (GTK_CONTAINER (info->proxy->parent), info->proxy); + g_object_unref (info->proxy); info->proxy = NULL; } /* create proxy if needed ... */ @@ -2166,6 +2177,8 @@ update_node (GtkUIManager *self, GtkWidget *filler; info->proxy = gtk_action_create_menu_item (action); + g_object_ref (info->proxy); + gtk_object_sink (info->proxy); menu = gtk_menu_new (); gtk_widget_set_name (info->proxy, info->name); gtk_widget_set_name (menu, info->name); @@ -2210,6 +2223,8 @@ update_node (GtkUIManager *self, if (info->proxy == NULL) { info->proxy = gtk_toolbar_new (); + g_object_ref (info->proxy); + gtk_object_sink (info->proxy); gtk_widget_set_name (info->proxy, info->name); gtk_widget_show (info->proxy); g_signal_emit (self, ui_manager_signals[ADD_WIDGET], 0, info->proxy); @@ -2224,12 +2239,14 @@ update_node (GtkUIManager *self, { gtk_container_remove (GTK_CONTAINER (info->proxy->parent), info->proxy); + g_object_unref (info->proxy); info->proxy = NULL; } if (info->extra) { gtk_container_remove (GTK_CONTAINER (info->extra->parent), info->extra); + g_object_unref (info->extra); info->extra = NULL; } } @@ -2241,6 +2258,8 @@ update_node (GtkUIManager *self, if (find_menu_position (node, &menushell, &pos)) { info->proxy = gtk_separator_menu_item_new (); + g_object_ref (info->proxy); + gtk_object_sink (info->proxy); g_object_set_data (G_OBJECT (info->proxy), "gtk-separator-mode", GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN)); @@ -2249,6 +2268,8 @@ update_node (GtkUIManager *self, NODE_INFO (node)->proxy, pos); info->extra = gtk_separator_menu_item_new (); + g_object_ref (info->extra); + gtk_object_sink (info->extra); g_object_set_data (G_OBJECT (info->extra), "gtk-separator-mode", GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN)); @@ -2267,12 +2288,14 @@ update_node (GtkUIManager *self, { gtk_container_remove (GTK_CONTAINER (info->proxy->parent), info->proxy); + g_object_unref (info->proxy); info->proxy = NULL; } if (info->extra) { gtk_container_remove (GTK_CONTAINER (info->extra->parent), info->extra); + g_object_unref (info->extra); info->extra = NULL; } } @@ -2288,6 +2311,8 @@ update_node (GtkUIManager *self, item = gtk_separator_tool_item_new (); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos); info->proxy = GTK_WIDGET (item); + g_object_ref (info->proxy); + gtk_object_sink (info->proxy); g_object_set_data (G_OBJECT (info->proxy), "gtk-separator-mode", GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN)); @@ -2296,6 +2321,8 @@ update_node (GtkUIManager *self, item = gtk_separator_tool_item_new (); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos+1); info->extra = GTK_WIDGET (item); + g_object_ref (info->extra); + gtk_object_sink (info->extra); g_object_set_data (G_OBJECT (info->extra), "gtk-separator-mode", GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN)); @@ -2314,6 +2341,7 @@ update_node (GtkUIManager *self, gtk_action_disconnect_proxy (info->action, info->proxy); gtk_container_remove (GTK_CONTAINER (info->proxy->parent), info->proxy); + g_object_unref (info->proxy); info->proxy = NULL; } /* create proxy if needed ... */ @@ -2325,6 +2353,8 @@ update_node (GtkUIManager *self, if (find_menu_position (node, &menushell, &pos)) { info->proxy = gtk_action_create_menu_item (action); + g_object_ref (info->proxy); + gtk_object_sink (info->proxy); gtk_widget_set_name (info->proxy, info->name); gtk_menu_shell_insert (GTK_MENU_SHELL (menushell), @@ -2353,8 +2383,8 @@ update_node (GtkUIManager *self, break; case NODE_TYPE_TOOLITEM: /* remove the proxy if it is of the wrong type ... */ - if (info->proxy && G_OBJECT_TYPE (info->proxy) != - GTK_ACTION_GET_CLASS (action)->toolbar_item_type) + if (info->proxy && + G_OBJECT_TYPE (info->proxy) != GTK_ACTION_GET_CLASS (action)->toolbar_item_type) { g_signal_handlers_disconnect_by_func (info->proxy, G_CALLBACK (update_smart_separators), @@ -2362,6 +2392,7 @@ update_node (GtkUIManager *self, gtk_action_disconnect_proxy (info->action, info->proxy); gtk_container_remove (GTK_CONTAINER (info->proxy->parent), info->proxy); + g_object_unref (info->proxy); info->proxy = NULL; } /* create proxy if needed ... */ @@ -2373,6 +2404,8 @@ update_node (GtkUIManager *self, if (find_toolbar_position (node, &toolbar, &pos)) { info->proxy = gtk_action_create_tool_item (action); + g_object_ref (info->proxy); + gtk_object_sink (info->proxy); gtk_widget_set_name (info->proxy, info->name); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), @@ -2408,6 +2441,7 @@ update_node (GtkUIManager *self, { gtk_container_remove (GTK_CONTAINER (info->proxy->parent), info->proxy); + g_object_unref (info->proxy); info->proxy = NULL; } @@ -2416,6 +2450,8 @@ update_node (GtkUIManager *self, GtkToolItem *item = gtk_separator_tool_item_new (); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos); info->proxy = GTK_WIDGET (item); + g_object_ref (info->proxy); + gtk_object_sink (info->proxy); gtk_widget_set_no_show_all (info->proxy, TRUE); g_object_set_data (G_OBJECT (info->proxy), "gtk-separator-mode", @@ -2432,12 +2468,15 @@ update_node (GtkUIManager *self, { gtk_container_remove (GTK_CONTAINER (info->proxy->parent), info->proxy); + g_object_unref (info->proxy); info->proxy = NULL; } if (find_menu_position (node, &menushell, &pos)) { info->proxy = gtk_separator_menu_item_new (); + g_object_ref (info->proxy); + gtk_object_sink (info->proxy); gtk_widget_set_no_show_all (info->proxy, TRUE); g_object_set_data (G_OBJECT (info->proxy), "gtk-separator-mode", diff --git a/tests/testactions.c b/tests/testactions.c index be8c78a282..3c9a507892 100644 --- a/tests/testactions.c +++ b/tests/testactions.c @@ -203,7 +203,12 @@ static const gchar *ui_info = " \n" " \n" " \n" -" \n"; +" \n" +" \n" +" \n" +" \n" +" \n" +" \n"; static void add_widget (GtkUIManager *merge, @@ -308,16 +313,18 @@ create_window (GtkActionGroup *action_group) GtkWidget *hbox, *spinbutton, *button; GError *error = NULL; + merge = gtk_ui_manager_new (); + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), -1, -1); gtk_window_set_title (GTK_WINDOW (window), "Action Test"); + g_signal_connect_swapped (window, "destroy", G_CALLBACK (g_object_unref), merge); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); box = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (window), box); gtk_widget_show (box); - merge = gtk_ui_manager_new (); gtk_ui_manager_insert_action_group (merge, action_group, 0); g_signal_connect (merge, "add_widget", G_CALLBACK (add_widget), box); @@ -382,6 +389,21 @@ main (int argc, char **argv) gtk_main (); +#ifdef DEBUG_UI_MANAGER + { + GList *action; + + for (action = gtk_action_group_list_actions (action_group); + action; + action = action->next) + { + GtkAction *a = action->data; + g_print ("action %s ref count %d\n", + gtk_action_get_name (a), G_OBJECT (a)->ref_count); + } + } +#endif + g_object_unref (action_group); gtk_accel_map_save ("accels"); diff --git a/tests/testmerge.c b/tests/testmerge.c index 05bbf3133b..dff451a648 100644 --- a/tests/testmerge.c +++ b/tests/testmerge.c @@ -88,7 +88,6 @@ delayed_toggle_dynamic (GtkUIManager *merge) "label", "Dynamic action 2", "stock_id", GTK_STOCK_EXECUTE, NULL); - g_object_set (dyn, "name", "dyn2", NULL); gtk_action_group_add_action (dynamic, dyn); } @@ -690,8 +689,41 @@ main (int argc, char **argv) gtk_widget_show_all (window); gtk_main (); - g_object_unref (action_group); +#ifdef DEBUG_UI_MANAGER + { + GList *action; + + g_print ("\n> before unreffing the ui manager <\n"); + for (action = gtk_action_group_list_actions (action_group); + action; + action = action->next) + { + GtkAction *a = action->data; + g_print (" action %s ref count %d\n", + gtk_action_get_name (a), G_OBJECT (a)->ref_count); + } + } +#endif + g_object_unref (merge); +#ifdef DEBUG_UI_MANAGER + { + GList *action; + + g_print ("\n> after unreffing the ui manager <\n"); + for (action = gtk_action_group_list_actions (action_group); + action; + action = action->next) + { + GtkAction *a = action->data; + g_print (" action %s ref count %d\n", + gtk_action_get_name (a), G_OBJECT (a)->ref_count); + } + } +#endif + + g_object_unref (action_group); + return 0; }