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.
This commit is contained in:
Sebastian Dröge 2020-11-26 19:26:25 +02:00
parent 7367c5d367
commit 52261f0abe
3 changed files with 26 additions and 6 deletions

View File

@ -1019,6 +1019,9 @@ g_binding_get_flags (GBinding *binding)
* Returns: (transfer none) (nullable): the source #GObject, or %NULL if the * Returns: (transfer none) (nullable): the source #GObject, or %NULL if the
* source does not exist any more. * source does not exist any more.
* *
* Deprecated: 2.68: Use g_binding_dup_source() for a safer version of this
* function.
*
* Since: 2.26 * Since: 2.26
*/ */
GObject * GObject *
@ -1077,6 +1080,9 @@ g_binding_dup_source (GBinding *binding)
* Returns: (transfer none) (nullable): the target #GObject, or %NULL if the * Returns: (transfer none) (nullable): the target #GObject, or %NULL if the
* target does not exist any more. * target does not exist any more.
* *
* Deprecated: 2.68: Use g_binding_dup_target() for a safer version of this
* function.
*
* Since: 2.26 * Since: 2.26
*/ */
GObject * GObject *

View File

@ -108,11 +108,11 @@ GType g_binding_get_type (void) G_GNUC_CONST;
GLIB_AVAILABLE_IN_ALL GLIB_AVAILABLE_IN_ALL
GBindingFlags g_binding_get_flags (GBinding *binding); 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); GObject * g_binding_get_source (GBinding *binding);
GLIB_AVAILABLE_IN_2_68 GLIB_AVAILABLE_IN_2_68
GObject * g_binding_dup_source (GBinding *binding); 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); GObject * g_binding_get_target (GBinding *binding);
GLIB_AVAILABLE_IN_2_68 GLIB_AVAILABLE_IN_2_68
GObject * g_binding_dup_target (GBinding *binding); GObject * g_binding_dup_target (GBinding *binding);

View File

@ -353,6 +353,7 @@ binding_default (void)
{ {
BindingSource *source = g_object_new (binding_source_get_type (), NULL); BindingSource *source = g_object_new (binding_source_get_type (), NULL);
BindingTarget *target = g_object_new (binding_target_get_type (), NULL); BindingTarget *target = g_object_new (binding_target_get_type (), NULL);
GObject *tmp;
GBinding *binding; GBinding *binding;
binding = g_object_bind_property (source, "foo", binding = g_object_bind_property (source, "foo",
@ -360,8 +361,14 @@ binding_default (void)
G_BINDING_DEFAULT); G_BINDING_DEFAULT);
g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding); g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding);
g_assert_true ((BindingSource *) g_binding_get_source (binding) == source); tmp = g_binding_dup_source (binding);
g_assert_true ((BindingTarget *) g_binding_get_target (binding) == target); 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_source_property (binding), ==, "foo");
g_assert_cmpstr (g_binding_get_target_property (binding), ==, "bar"); g_assert_cmpstr (g_binding_get_target_property (binding), ==, "bar");
g_assert_cmpint (g_binding_get_flags (binding), ==, G_BINDING_DEFAULT); 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); BindingSource *source = g_object_new (binding_source_get_type (), NULL);
BindingTarget *target = g_object_new (binding_target_get_type (), NULL); BindingTarget *target = g_object_new (binding_target_get_type (), NULL);
GBinding *binding; GBinding *binding;
GObject *tmp;
g_test_summary ("Test that bindings set up with non-canonical property names work"); 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_BINDING_DEFAULT);
g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding); g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding);
g_assert_true ((BindingSource *) g_binding_get_source (binding) == source); tmp = g_binding_dup_source (binding);
g_assert_true ((BindingTarget *) g_binding_get_target (binding) == target); 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_source_property (binding), ==, "double-value");
g_assert_cmpstr (g_binding_get_target_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); g_assert_cmpint (g_binding_get_flags (binding), ==, G_BINDING_DEFAULT);