[gtk/suggestion-entry: 3/7] builder: Warn about dropped objects
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/suggestion-entry: 3/7] builder: Warn about dropped objects
- Date: Sat, 27 Jun 2020 20:32:08 +0000 (UTC)
commit c167388442ef45f404e1ade9d9f391de3bf1166f
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jun 27 09:36:45 2020 -0400
builder: Warn about dropped objects
Use GTK_DEBUG=builder-objects to make GtkBuilder warn
if a named object from a ui files doesn't get claimed
by gtk_builder_get_object(). This is useful for finding
dead wood in .ui files.
gtk/gtkbuilder.c | 18 ++++++++++++++++++
gtk/gtkdebug.h | 1 +
gtk/gtkmain.c | 1 +
3 files changed, 20 insertions(+)
---
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index ed9fbe37bd..65bd1a2d6f 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -225,6 +225,8 @@
#include "gtkicontheme.h"
#include "gtkiconthemeprivate.h"
#include "gdkpixbufutilsprivate.h"
+#include "gtkdebug.h"
+
static void gtk_builder_finalize (GObject *object);
static void gtk_builder_set_property (GObject *object,
@@ -359,6 +361,22 @@ gtk_builder_finalize (GObject *object)
g_free (priv->filename);
g_free (priv->resource_prefix);
+#ifdef G_ENABLE_DEBUG
+ if (GTK_DEBUG_CHECK (BUILDER_OBJECTS))
+ {
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init (&iter, priv->objects);
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ {
+ if (G_OBJECT (value)->ref_count == 1)
+ g_message ("builder: %s with id %s unused",
+ G_OBJECT_TYPE_NAME (value), (const char *)key);
+ }
+ }
+#endif
+
g_hash_table_destroy (priv->objects);
g_slist_free_full (priv->signals, (GDestroyNotify)_free_signal_info);
diff --git a/gtk/gtkdebug.h b/gtk/gtkdebug.h
index a615921b19..f752b406db 100644
--- a/gtk/gtkdebug.h
+++ b/gtk/gtkdebug.h
@@ -53,6 +53,7 @@ typedef enum {
GTK_DEBUG_LAYOUT = 1 << 15,
GTK_DEBUG_SNAPSHOT = 1 << 16,
GTK_DEBUG_CONSTRAINTS = 1 << 17,
+ GTK_DEBUG_BUILDER_OBJECTS = 1 << 18,
} GtkDebugFlag;
#ifdef G_ENABLE_DEBUG
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 57cacc2273..aa314d05a2 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -168,6 +168,7 @@ static const GDebugKey gtk_debug_keys[] = {
{ "icontheme", GTK_DEBUG_ICONTHEME },
{ "printing", GTK_DEBUG_PRINTING} ,
{ "builder", GTK_DEBUG_BUILDER },
+ { "builder-objects", GTK_DEBUG_BUILDER_OBJECTS },
{ "size-request", GTK_DEBUG_SIZE_REQUEST },
{ "no-css-cache", GTK_DEBUG_NO_CSS_CACHE },
{ "shortcuts", GTK_DEBUG_SHORTCUTS },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]