[glib/glib-2-30] Fix binding properties of the same object
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-30] Fix binding properties of the same object
- Date: Sun, 11 Mar 2012 22:23:49 +0000 (UTC)
commit be130752b43866649beae051b47e66c0ca6b81e6
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Mar 4 20:49:04 2012 -0500
Fix binding properties of the same object
This problem was pointed out in bug 639873.
The patch here is based on Matt Barnes patch,
I've added a testcase as well.
gobject/gbinding.c | 8 +++++---
gobject/tests/binding.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 3 deletions(-)
---
diff --git a/gobject/gbinding.c b/gobject/gbinding.c
index 39de99f..906aadd 100644
--- a/gobject/gbinding.c
+++ b/gobject/gbinding.c
@@ -575,9 +575,11 @@ g_binding_constructed (GObject *gobject)
G_CALLBACK (on_target_notify),
binding);
- g_object_weak_ref (binding->target, weak_unbind, binding);
- add_binding_qdata (binding->target, binding);
-
+ if (binding->target != binding->source)
+ {
+ g_object_weak_ref (binding->target, weak_unbind, binding);
+ add_binding_qdata (binding->target, binding);
+ }
}
static void
diff --git a/gobject/tests/binding.c b/gobject/tests/binding.c
index 4d0465c..b36fda1 100644
--- a/gobject/tests/binding.c
+++ b/gobject/tests/binding.c
@@ -7,6 +7,7 @@ typedef struct _BindingSource
GObject parent_instance;
gint foo;
+ gint bar;
gdouble value;
gboolean toggle;
} BindingSource;
@@ -21,6 +22,7 @@ enum
PROP_SOURCE_0,
PROP_SOURCE_FOO,
+ PROP_SOURCE_BAR,
PROP_SOURCE_VALUE,
PROP_SOURCE_TOGGLE
};
@@ -41,6 +43,10 @@ binding_source_set_property (GObject *gobject,
source->foo = g_value_get_int (value);
break;
+ case PROP_SOURCE_BAR:
+ source->bar = g_value_get_int (value);
+ break;
+
case PROP_SOURCE_VALUE:
source->value = g_value_get_double (value);
break;
@@ -68,6 +74,10 @@ binding_source_get_property (GObject *gobject,
g_value_set_int (value, source->foo);
break;
+ case PROP_SOURCE_BAR:
+ g_value_set_int (value, source->bar);
+ break;
+
case PROP_SOURCE_VALUE:
g_value_set_double (value, source->value);
break;
@@ -94,6 +104,11 @@ binding_source_class_init (BindingSourceClass *klass)
-1, 100,
0,
G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_SOURCE_BAR,
+ g_param_spec_int ("bar", "Bar", "Bar",
+ -1, 100,
+ 0,
+ G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_SOURCE_VALUE,
g_param_spec_double ("value", "Value", "Value",
-100.0, 200.0,
@@ -530,6 +545,26 @@ binding_invert_boolean (void)
g_object_unref (target);
}
+static void
+binding_same_object (void)
+{
+ BindingSource *source = g_object_new (binding_source_get_type (),
+ "foo", 100,
+ "bar", 50,
+ NULL);
+ GBinding *binding G_GNUC_UNUSED;
+
+ binding = g_object_bind_property (source, "foo",
+ source, "bar",
+ G_BINDING_BIDIRECTIONAL);
+
+ g_object_set (source, "foo", 10, NULL);
+ g_assert_cmpint (source->foo, ==, 10);
+ g_assert_cmpint (source->bar, ==, 10);
+
+ g_object_unref (source);
+}
+
int
main (int argc, char *argv[])
{
@@ -546,6 +581,7 @@ main (int argc, char *argv[])
g_test_add_func ("/binding/chain", binding_chain);
g_test_add_func ("/binding/sync-create", binding_sync_create);
g_test_add_func ("/binding/invert-boolean", binding_invert_boolean);
+ g_test_add_func ("/binding/same-object", binding_same_object);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]