]> Pileus Git - ~andy/gtk/commitdiff
Do reference counting on the user_data that is shared between multiple
authorMatthias Clasen <maclas@gmx.de>
Wed, 28 Jan 2004 23:49:10 +0000 (23:49 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Wed, 28 Jan 2004 23:49:10 +0000 (23:49 +0000)
Thu Jan 29 00:48:47 2004  Matthias Clasen  <maclas@gmx.de>

* gtk/gtkactiongroup.c (gtk_action_group_add_toggle_actions_full):
* gtk/gtkactiongroup.c (gtk_action_group_add_actions_full): Do reference
counting on the user_data that is shared between multiple signal handlers,
to avoid calling the destroy notify multiple times.  (#132447, Adam Hooper)

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkactiongroup.c

index bf90bbfead8d888f3f853acbcd16e0be071292a5..4c5453b47edf70a1a48985c48492b31e195e1149 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Jan 29 00:48:47 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkactiongroup.c (gtk_action_group_add_toggle_actions_full): 
+       * gtk/gtkactiongroup.c (gtk_action_group_add_actions_full): Do reference
+       counting on the user_data that is shared between multiple signal handlers,
+       to avoid calling the destroy notify multiple times.  (#132447, Adam Hooper)
+
 2004-01-28  Hans Breuer  <hans@breuer.org>
 
        * gtk/stock-icons/stock_network_(16|24).png : new GTK_STOCK_NETWORK ...
index bf90bbfead8d888f3f853acbcd16e0be071292a5..4c5453b47edf70a1a48985c48492b31e195e1149 100644 (file)
@@ -1,3 +1,10 @@
+Thu Jan 29 00:48:47 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkactiongroup.c (gtk_action_group_add_toggle_actions_full): 
+       * gtk/gtkactiongroup.c (gtk_action_group_add_actions_full): Do reference
+       counting on the user_data that is shared between multiple signal handlers,
+       to avoid calling the destroy notify multiple times.  (#132447, Adam Hooper)
+
 2004-01-28  Hans Breuer  <hans@breuer.org>
 
        * gtk/stock-icons/stock_network_(16|24).png : new GTK_STOCK_NETWORK ...
index bf90bbfead8d888f3f853acbcd16e0be071292a5..4c5453b47edf70a1a48985c48492b31e195e1149 100644 (file)
@@ -1,3 +1,10 @@
+Thu Jan 29 00:48:47 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkactiongroup.c (gtk_action_group_add_toggle_actions_full): 
+       * gtk/gtkactiongroup.c (gtk_action_group_add_actions_full): Do reference
+       counting on the user_data that is shared between multiple signal handlers,
+       to avoid calling the destroy notify multiple times.  (#132447, Adam Hooper)
+
 2004-01-28  Hans Breuer  <hans@breuer.org>
 
        * gtk/stock-icons/stock_network_(16|24).png : new GTK_STOCK_NETWORK ...
index bf90bbfead8d888f3f853acbcd16e0be071292a5..4c5453b47edf70a1a48985c48492b31e195e1149 100644 (file)
@@ -1,3 +1,10 @@
+Thu Jan 29 00:48:47 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkactiongroup.c (gtk_action_group_add_toggle_actions_full): 
+       * gtk/gtkactiongroup.c (gtk_action_group_add_actions_full): Do reference
+       counting on the user_data that is shared between multiple signal handlers,
+       to avoid calling the destroy notify multiple times.  (#132447, Adam Hooper)
+
 2004-01-28  Hans Breuer  <hans@breuer.org>
 
        * gtk/stock-icons/stock_network_(16|24).png : new GTK_STOCK_NETWORK ...
index bf90bbfead8d888f3f853acbcd16e0be071292a5..4c5453b47edf70a1a48985c48492b31e195e1149 100644 (file)
@@ -1,3 +1,10 @@
+Thu Jan 29 00:48:47 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkactiongroup.c (gtk_action_group_add_toggle_actions_full): 
+       * gtk/gtkactiongroup.c (gtk_action_group_add_actions_full): Do reference
+       counting on the user_data that is shared between multiple signal handlers,
+       to avoid calling the destroy notify multiple times.  (#132447, Adam Hooper)
+
 2004-01-28  Hans Breuer  <hans@breuer.org>
 
        * gtk/stock-icons/stock_network_(16|24).png : new GTK_STOCK_NETWORK ...
index 72ff6e4dfa7af6795d5aedf63985d6135d703c0c..fb172cef3d7c167f7a333711ff07796ec47a266a 100644 (file)
@@ -679,6 +679,29 @@ gtk_action_group_add_actions (GtkActionGroup *action_group,
                                     user_data, NULL);
 }
 
+typedef struct _SharedData  SharedData;
+
+struct _SharedData {
+  guint          ref_count;
+  gpointer       data;
+  GDestroyNotify destroy;
+};
+
+static void
+shared_data_unref (gpointer data)
+{
+  SharedData *shared_data = (SharedData *)data;
+
+  shared_data->ref_count--;
+  if (shared_data->ref_count == 0)
+    {
+      if (shared_data->destroy) 
+       (*shared_data->destroy) (shared_data->data);
+      
+      g_free (shared_data);
+    }
+}
+
 
 /**
  * gtk_action_group_add_actions_full:
@@ -707,12 +730,18 @@ gtk_action_group_add_actions_full (GtkActionGroup *action_group,
   guint i;
   GtkTranslateFunc translate_func;
   gpointer translate_data;
+  SharedData *shared_data;
 
   g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
 
   translate_func = action_group->private_data->translate_func;
   translate_data = action_group->private_data->translate_data;
 
+  shared_data = g_new0 (SharedData, 1);
+  shared_data->ref_count = 1;
+  shared_data->data = user_data;
+  shared_data->destroy = destroy;
+
   for (i = 0; i < n_entries; i++)
     {
       GtkAction *action;
@@ -736,15 +765,24 @@ gtk_action_group_add_actions_full (GtkActionGroup *action_group,
                               entries[i].stock_id);
 
       if (entries[i].callback)
-       g_signal_connect_data (action, "activate",
-                              entries[i].callback, 
-                              user_data, (GClosureNotify)destroy, 0);
+       {
+         GClosure *closure;
+
+         closure = g_cclosure_new (entries[i].callback, user_data, NULL);
+         g_closure_add_finalize_notifier (closure, shared_data, 
+                                          (GClosureNotify)shared_data_unref);
+         shared_data->ref_count++;
 
+         g_signal_connect_closure (action, "activate", closure, FALSE);
+       }
+         
       gtk_action_group_add_action_with_accel (action_group, 
                                              action,
                                              entries[i].accelerator);
       g_object_unref (action);
     }
+
+  shared_data_unref (shared_data);
 }
 
 /**
@@ -801,12 +839,18 @@ gtk_action_group_add_toggle_actions_full (GtkActionGroup       *action_group,
   guint i;
   GtkTranslateFunc translate_func;
   gpointer translate_data;
+  SharedData *shared_data;
 
   g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
 
   translate_func = action_group->private_data->translate_func;
   translate_data = action_group->private_data->translate_data;
 
+  shared_data = g_new0 (SharedData, 1);
+  shared_data->ref_count = 1;
+  shared_data->data = user_data;
+  shared_data->destroy = destroy;
+
   for (i = 0; i < n_entries; i++)
     {
       GtkToggleAction *action;
@@ -832,15 +876,24 @@ gtk_action_group_add_toggle_actions_full (GtkActionGroup       *action_group,
       gtk_toggle_action_set_active (action, entries[i].is_active);
 
       if (entries[i].callback)
-       g_signal_connect_data (action, "activate",
-                              entries[i].callback, 
-                              user_data, (GClosureNotify)destroy, 0);
+       {
+         GClosure *closure;
+
+         closure = g_cclosure_new (entries[i].callback, user_data, NULL);
+         g_closure_add_finalize_notifier (closure, shared_data, 
+                                          (GClosureNotify)shared_data_unref);
+         shared_data->ref_count++;
 
+         g_signal_connect_closure (action, "activate", closure, FALSE);
+       }
+         
       gtk_action_group_add_action_with_accel (action_group, 
                                              GTK_ACTION (action),
                                              entries[i].accelerator);
       g_object_unref (action);
     }
+
+    shared_data_unref (shared_data);
 }
 
 /**