From: Emmanuele Bassi Date: Fri, 3 Mar 2023 21:10:39 +0000 (+0000) Subject: a11y: Use weak references for GtkATContext cached accessibles X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~6^2~4^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=74a00319ddeb32470d86d99a7e391ad10c333a4c;p=gtk4.git a11y: Use weak references for GtkATContext cached accessibles The accessible objects already own the GtkATContext, let's avoid a reference cycle. --- diff --git a/gtk/gtkatcontext.c b/gtk/gtkatcontext.c index e4e66e82aa..2ae924cc92 100644 --- a/gtk/gtkatcontext.c +++ b/gtk/gtkatcontext.c @@ -85,8 +85,19 @@ gtk_at_context_dispose (GObject *gobject) gtk_at_context_unrealize (self); - g_clear_object (&self->accessible_parent); - g_clear_object (&self->next_accessible_sibling); + if (self->accessible_parent != NULL) + { + g_object_remove_weak_pointer (G_OBJECT (self->accessible_parent), + (gpointer *) &self->accessible_parent); + self->accessible_parent = NULL; + } + + if (self->next_accessible_sibling != NULL) + { + g_object_remove_weak_pointer (G_OBJECT (self->next_accessible_sibling), + (gpointer *) &self->next_accessible_sibling); + self->next_accessible_sibling = NULL; + } G_OBJECT_CLASS (gtk_at_context_parent_class)->dispose (gobject); } @@ -479,7 +490,17 @@ gtk_at_context_set_accessible_parent (GtkATContext *self, { g_return_if_fail (GTK_IS_AT_CONTEXT (self)); - g_set_object (&self->accessible_parent, parent); + if (self->accessible_parent != parent) + { + if (self->accessible_parent != NULL) + g_object_remove_weak_pointer (G_OBJECT (self->accessible_parent), + (gpointer *) &self->accessible_parent); + + self->accessible_parent = parent; + if (self->accessible_parent != NULL) + g_object_add_weak_pointer (G_OBJECT (self->accessible_parent), + (gpointer *) &self->accessible_parent); + } } /*< private > @@ -511,7 +532,18 @@ gtk_at_context_set_next_accessible_sibling (GtkATContext *self, { g_return_if_fail (GTK_IS_AT_CONTEXT (self)); - g_set_object (&self->next_accessible_sibling, sibling); + if (self->next_accessible_sibling != sibling) + { + if (self->next_accessible_sibling != NULL) + g_object_remove_weak_pointer (G_OBJECT (self->next_accessible_sibling), + (gpointer *) &self->next_accessible_sibling); + + self->next_accessible_sibling = sibling; + + if (self->next_accessible_sibling != NULL) + g_object_add_weak_pointer (G_OBJECT (self->next_accessible_sibling), + (gpointer *) &self->next_accessible_sibling); + } } /*< private >