treelistmodel: Delay notifies from TreeListRow
authorBenjamin Otte <otte@redhat.com>
Wed, 26 Apr 2023 21:40:56 +0000 (23:40 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 26 Apr 2023 21:40:56 +0000 (23:40 +0200)
Don't notify during destruction, notify afterwards.
This way we don't call into user code from a half-destructed node.

Note that this changes the order in which those notifies happen when
collapsing a large tree: From parent node before child nodes to child
nodes before parent node.

No actual use case for this, just thought it would be safer.

gtk/gtktreelistmodel.c

index 81b4319c150e52b0313845ff12aeebee7c29eb77..a4f0fa1d4b9ffe870e0bc9e7420945da946bc253 100644 (file)
@@ -415,10 +415,16 @@ gtk_tree_list_model_clear_node (gpointer data)
   TreeNode *node = data;
 
   if (node->row)
-    gtk_tree_list_row_destroy (node->row);
+    {
+      g_object_freeze_notify (G_OBJECT (node->row));
+      gtk_tree_list_row_destroy (node->row);
+    }
 
   gtk_tree_list_model_clear_node_children (node);
 
+  if (node->row)
+    g_object_thaw_notify (G_OBJECT (node->row));
+
   g_clear_object (&node->item);
 }
 
@@ -955,16 +961,12 @@ G_DEFINE_TYPE (GtkTreeListRow, gtk_tree_list_row, G_TYPE_OBJECT)
 static void
 gtk_tree_list_row_destroy (GtkTreeListRow *self)
 {
-  g_object_freeze_notify (G_OBJECT (self));
-
   self->node = NULL;
 
   /* FIXME: We could check some properties to avoid excess notifies */
   g_object_notify_by_pspec (G_OBJECT (self), row_properties[ROW_PROP_DEPTH]);
   g_object_notify_by_pspec (G_OBJECT (self), row_properties[ROW_PROP_EXPANDABLE]);
   g_object_notify_by_pspec (G_OBJECT (self), row_properties[ROW_PROP_EXPANDED]);
-
-  g_object_thaw_notify (G_OBJECT (self));
 }
 
 static void