Merge branch '2672-dataset-tests-and-fixes' into 'main'

gdataset: Preserve destruction order

Closes #2672 and #2676

See merge request GNOME/glib!2776
This commit is contained in:
Philip Withnall
2022-07-07 11:52:19 +00:00
4 changed files with 152 additions and 16 deletions

View File

@@ -5049,16 +5049,22 @@ g_weak_ref_set (GWeakRef *weak_ref,
/* Remove the weak ref from the old object */
if (old_object != NULL)
{
gboolean in_weak_refs_notify;
weak_locations = g_datalist_id_get_data (&old_object->qdata, quark_weak_locations);
in_weak_refs_notify = g_datalist_id_get_data (&old_object->qdata, quark_weak_refs) == NULL;
/* for it to point to an object, the object must have had it added once */
g_assert (weak_locations != NULL);
g_assert (weak_locations != NULL || in_weak_refs_notify);
*weak_locations = g_slist_remove (*weak_locations, weak_ref);
if (!*weak_locations)
if (weak_locations != NULL)
{
weak_locations_free_unlocked (weak_locations);
g_datalist_id_remove_no_notify (&old_object->qdata, quark_weak_locations);
*weak_locations = g_slist_remove (*weak_locations, weak_ref);
if (!*weak_locations)
{
weak_locations_free_unlocked (weak_locations);
g_datalist_id_remove_no_notify (&old_object->qdata, quark_weak_locations);
}
}
}

View File

@@ -1089,6 +1089,52 @@ binding_concurrent_finalizing (void)
}
}
static void
binding_dispose_source (void)
{
/* Test that the source can be disposed */
BindingSource *source = g_object_new (binding_source_get_type (), NULL);
BindingTarget *target = g_object_new (binding_target_get_type (), NULL);
GBinding *binding;
g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/2676");
binding = g_object_bind_property (source, "foo",
target, "bar",
G_BINDING_DEFAULT);
g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding);
g_object_run_dispose (G_OBJECT (source));
g_assert_null (binding);
g_object_unref (target);
g_object_unref (source);
}
static void
binding_dispose_target (void)
{
/* Test that the target can be disposed */
BindingSource *source = g_object_new (binding_source_get_type (), NULL);
BindingTarget *target = g_object_new (binding_target_get_type (), NULL);
GBinding *binding;
g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/2676");
binding = g_object_bind_property (source, "foo",
target, "bar",
G_BINDING_DEFAULT);
g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding);
g_object_run_dispose (G_OBJECT (target));
g_assert_null (binding);
g_object_unref (target);
g_object_unref (source);
}
int
main (int argc, char *argv[])
{
@@ -1111,6 +1157,8 @@ main (int argc, char *argv[])
g_test_add_func ("/binding/interface", binding_interface);
g_test_add_func ("/binding/concurrent-unbind", binding_concurrent_unbind);
g_test_add_func ("/binding/concurrent-finalizing", binding_concurrent_finalizing);
g_test_add_func ("/binding/dispose-source", binding_dispose_source);
g_test_add_func ("/binding/dispose-target", binding_dispose_target);
return g_test_run ();
}