[gtk/mcatanzaro/unparent-warning: 4/5] Add warning when widget with no parent is unparented




commit db059847b246fbea1e6db0b38db9aaeec7ab4e36
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Thu Jan 7 09:45:43 2021 -0600

    Add warning when widget with no parent is unparented
    
    This is a little controversial -- Benjamin is not fond of adding new
    warnings in GTK 4 -- but it is not really an API break, and will help
    developers avoid adding unnecessary code to unparent widgets that are
    already unparented elsewhere. Also, it's still quite early in the life
    of GTK 4, before most apps have been ported. The earlier we add this
    warning, the better.

 gtk/gtkwidget.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 239f7735e8..8cfd5e56f4 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -2497,7 +2497,11 @@ gtk_widget_unparent (GtkWidget *widget)
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
   if (priv->parent == NULL)
-    return;
+    {
+      g_warning ("Attempted to unparent %s %p, but it already has no parent.",
+                 G_OBJECT_TYPE_NAME (widget), widget);
+      return;
+    }
 
   gtk_widget_push_verify_invariants (widget);
 


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