[glade/gbinding: 17/60] Fix GladeProperty / GladeBinding ownership issues (thanks Juan!)



commit fff95d570b1931cf930c3c9188a7b72bf37ef272
Author: Denis Washington <denisw src gnome org>
Date:   Fri Jun 10 13:58:08 2011 +0200

    Fix GladeProperty / GladeBinding ownership issues (thanks Juan!)
    
    Now it is clear: a bound GladeProperty owns the GladeBinding of which
    it is the target. A GladeBinding doesn't own any GladeProperty, neither
    the target nor the source. The former will destroy the GladeBinding
    when it is finalized, the latter is now only weakly referenced by
    the GladeBinding.

 gladeui/glade-binding.c  |   13 ++++++++++++-
 gladeui/glade-property.c |    1 +
 2 files changed, 13 insertions(+), 1 deletions(-)
---
diff --git a/gladeui/glade-binding.c b/gladeui/glade-binding.c
index 6416df3..1c2b691 100644
--- a/gladeui/glade-binding.c
+++ b/gladeui/glade-binding.c
@@ -236,9 +236,20 @@ void
 glade_binding_set_source (GladeBinding  *binding,
                           GladeProperty *source)
 {
+  GladeBindingPrivate *priv;
+  
   g_assert (GLADE_IS_BINDING (binding));
+
+  priv = GLADE_BINDING_GET_PRIVATE (binding);
+  
+  if (priv->source)
+    g_object_remove_weak_pointer (G_OBJECT (priv->source),
+                                  (gpointer *) &priv->source);
+
+  priv->source = source;
+  g_object_add_weak_pointer (G_OBJECT (priv->source),
+                             (gpointer *) &priv->source);
   
-  GLADE_BINDING_GET_PRIVATE (binding)->source = source;
   glade_binding_update (binding);
 }
 
diff --git a/gladeui/glade-property.c b/gladeui/glade-property.c
index ce892b1..5c80391 100644
--- a/gladeui/glade-property.c
+++ b/gladeui/glade-property.c
@@ -1579,6 +1579,7 @@ glade_property_set_binding (GladeProperty    *property,
   g_return_if_fail (glade_binding_get_target (binding) == property);
   
   property->priv->binding = binding;
+  g_object_ref (binding);
 }
 
 static gint glade_property_su_stack = 0;



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