[gtk+] gtktreemodelfilter: add a debug define and more assertions



commit 767b2e2604a3e7d7f147c9f21237614356f3cfe4
Author: Kristian Rietveld <kris gtk org>
Date:   Wed Sep 7 09:36:18 2011 +0200

    gtktreemodelfilter: add a debug define and more assertions
    
    Should be helpful when debugging this thing.  Perhaps this needs to
    be properly integrated in G_DEBUG/GTK_DEBUG, but currently I do not see
    the need to.

 gtk/gtktreemodelfilter.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtktreemodelfilter.c b/gtk/gtktreemodelfilter.c
index b1e0e0d..eac81a1 100644
--- a/gtk/gtktreemodelfilter.c
+++ b/gtk/gtktreemodelfilter.c
@@ -322,6 +322,11 @@ enum
 #  define GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS(filter) (FALSE)
 #endif
 
+/* Defining this constant enables more assertions, which will be
+ * helpful when debugging the code.
+ */
+#undef MODEL_FILTER_DEBUG
+
 #define FILTER_ELT(filter_elt) ((FilterElt *)filter_elt)
 #define FILTER_LEVEL(filter_level) ((FilterLevel *)filter_level)
 #define GET_ELT(siter) ((FilterElt*) (siter ? g_sequence_get (siter) : NULL))
@@ -1171,6 +1176,10 @@ gtk_tree_model_filter_clear_cache_helper_iter (gpointer data,
   GtkTreeModelFilter *filter = user_data;
   FilterElt *elt = data;
 
+#ifdef MODEL_FILTER_DEBUG
+  g_assert (elt->zero_ref_count >= 0);
+#endif
+
   if (elt->zero_ref_count > 0)
     gtk_tree_model_filter_clear_cache_helper (filter, elt->children);
 }
@@ -3312,8 +3321,18 @@ gtk_tree_model_filter_real_ref_node (GtkTreeModel *model,
 
           if (filter->priv->root != level)
             filter->priv->zero_ref_count--;
+
+#ifdef MODEL_FILTER_DEBUG
+          g_assert (filter->priv->zero_ref_count >= 0);
+#endif
         }
     }
+
+#ifdef MODEL_FILTER_DEBUG
+  g_assert (elt->ref_count >= elt->ext_ref_count);
+  g_assert (elt->ref_count >= 0);
+  g_assert (elt->ext_ref_count >= 0);
+#endif
 }
 
 static void
@@ -3348,6 +3367,11 @@ gtk_tree_model_filter_real_unref_node (GtkTreeModel *model,
   elt = iter->user_data2;
 
   g_return_if_fail (elt->ref_count > 0);
+#ifdef MODEL_FILTER_DEBUG
+  g_assert (elt->ref_count >= elt->ext_ref_count);
+  g_assert (elt->ref_count >= 0);
+  g_assert (elt->ext_ref_count >= 0);
+#endif
 
   elt->ref_count--;
   level->ref_count--;
@@ -3373,8 +3397,18 @@ gtk_tree_model_filter_real_unref_node (GtkTreeModel *model,
 
           if (filter->priv->root != level)
             filter->priv->zero_ref_count++;
+
+#ifdef MODEL_FILTER_DEBUG
+          g_assert (filter->priv->zero_ref_count >= 0);
+#endif
         }
     }
+
+#ifdef MODEL_FILTER_DEBUG
+  g_assert (elt->ref_count >= elt->ext_ref_count);
+  g_assert (elt->ref_count >= 0);
+  g_assert (elt->ext_ref_count >= 0);
+#endif
 }
 
 /* TreeDragSource interface implementation */



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