[glib: 8/9] Deprecate g_binding_get_source() and get_target() in favour of dup_source() and dup_target()




commit 52261f0abe8bb5ed9b0c1e9636ce58f490298f98
Author: Sebastian Dröge <sebastian centricular com>
Date:   Thu Nov 26 19:26:25 2020 +0200

    Deprecate g_binding_get_source() and get_target() in favour of dup_source() and dup_target()
    
    The old functions are not thread-safe by design.

 gobject/gbinding.c      |  6 ++++++
 gobject/gbinding.h      |  4 ++--
 gobject/tests/binding.c | 22 ++++++++++++++++++----
 3 files changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/gobject/gbinding.c b/gobject/gbinding.c
index 9a4190a97..562f339da 100644
--- a/gobject/gbinding.c
+++ b/gobject/gbinding.c
@@ -1019,6 +1019,9 @@ g_binding_get_flags (GBinding *binding)
  * Returns: (transfer none) (nullable): the source #GObject, or %NULL if the
  *     source does not exist any more.
  *
+ * Deprecated: 2.68: Use g_binding_dup_source() for a safer version of this
+ * function.
+ *
  * Since: 2.26
  */
 GObject *
@@ -1077,6 +1080,9 @@ g_binding_dup_source (GBinding *binding)
  * Returns: (transfer none) (nullable): the target #GObject, or %NULL if the
  *     target does not exist any more.
  *
+ * Deprecated: 2.68: Use g_binding_dup_target() for a safer version of this
+ * function.
+ *
  * Since: 2.26
  */
 GObject *
diff --git a/gobject/gbinding.h b/gobject/gbinding.h
index f269ad5a8..84dad7f86 100644
--- a/gobject/gbinding.h
+++ b/gobject/gbinding.h
@@ -108,11 +108,11 @@ GType                 g_binding_get_type            (void) G_GNUC_CONST;
 
 GLIB_AVAILABLE_IN_ALL
 GBindingFlags         g_binding_get_flags           (GBinding *binding);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_68_FOR(g_binding_dup_source)
 GObject *             g_binding_get_source          (GBinding *binding);
 GLIB_AVAILABLE_IN_2_68
 GObject *             g_binding_dup_source          (GBinding *binding);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_68_FOR(g_binding_dup_target)
 GObject *             g_binding_get_target          (GBinding *binding);
 GLIB_AVAILABLE_IN_2_68
 GObject *             g_binding_dup_target          (GBinding *binding);
diff --git a/gobject/tests/binding.c b/gobject/tests/binding.c
index d79d09ec5..61002f4fb 100644
--- a/gobject/tests/binding.c
+++ b/gobject/tests/binding.c
@@ -353,6 +353,7 @@ binding_default (void)
 {
   BindingSource *source = g_object_new (binding_source_get_type (), NULL);
   BindingTarget *target = g_object_new (binding_target_get_type (), NULL);
+  GObject *tmp;
   GBinding *binding;
 
   binding = g_object_bind_property (source, "foo",
@@ -360,8 +361,14 @@ binding_default (void)
                                     G_BINDING_DEFAULT);
 
   g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding);
-  g_assert_true ((BindingSource *) g_binding_get_source (binding) == source);
-  g_assert_true ((BindingTarget *) g_binding_get_target (binding) == target);
+  tmp = g_binding_dup_source (binding);
+  g_assert_nonnull (tmp);
+  g_assert_true ((BindingSource *) tmp == source);
+  g_object_unref (tmp);
+  tmp = g_binding_dup_target (binding);
+  g_assert_nonnull (tmp);
+  g_assert_true ((BindingTarget *) tmp == target);
+  g_object_unref (tmp);
   g_assert_cmpstr (g_binding_get_source_property (binding), ==, "foo");
   g_assert_cmpstr (g_binding_get_target_property (binding), ==, "bar");
   g_assert_cmpint (g_binding_get_flags (binding), ==, G_BINDING_DEFAULT);
@@ -388,6 +395,7 @@ binding_canonicalisation (void)
   BindingSource *source = g_object_new (binding_source_get_type (), NULL);
   BindingTarget *target = g_object_new (binding_target_get_type (), NULL);
   GBinding *binding;
+  GObject *tmp;
 
   g_test_summary ("Test that bindings set up with non-canonical property names work");
 
@@ -396,8 +404,14 @@ binding_canonicalisation (void)
                                     G_BINDING_DEFAULT);
 
   g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding);
-  g_assert_true ((BindingSource *) g_binding_get_source (binding) == source);
-  g_assert_true ((BindingTarget *) g_binding_get_target (binding) == target);
+  tmp = g_binding_dup_source (binding);
+  g_assert_nonnull (tmp);
+  g_assert_true ((BindingSource *) tmp == source);
+  g_object_unref (tmp);
+  tmp = g_binding_dup_target (binding);
+  g_assert_nonnull (tmp);
+  g_assert_true ((BindingTarget *) tmp == target);
+  g_object_unref (tmp);
   g_assert_cmpstr (g_binding_get_source_property (binding), ==, "double-value");
   g_assert_cmpstr (g_binding_get_target_property (binding), ==, "double-value");
   g_assert_cmpint (g_binding_get_flags (binding), ==, G_BINDING_DEFAULT);


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