From f0da89fa2032060351d1987d445b04d07e90c04a Mon Sep 17 00:00:00 2001 From: Kristian Rietveld Date: Mon, 9 May 2011 10:04:24 +0200 Subject: [PATCH] Print failed assertions for failed child iterator conversions --- gtk/gtktreemodelfilter.c | 17 +++++++++++++++-- gtk/gtktreemodelsort.c | 18 +++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/gtk/gtktreemodelfilter.c b/gtk/gtktreemodelfilter.c index 3f5e21f2e1..f86ab6c532 100644 --- a/gtk/gtktreemodelfilter.c +++ b/gtk/gtktreemodelfilter.c @@ -151,8 +151,17 @@ enum PROP_VIRTUAL_ROOT }; -#define GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS(filter) \ +/* Set this to 0 to disable caching of child iterators. This + * allows for more stringent testing. It is recommended to set this + * to one when refactoring this code and running the unit tests to + * catch more errors. + */ +#if 1 +# define GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS(filter) \ (((GtkTreeModelFilter *)filter)->priv->child_flags & GTK_TREE_MODEL_ITERS_PERSIST) +#else +# define GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS(filter) (FALSE) +#endif #define FILTER_ELT(filter_elt) ((FilterElt *)filter_elt) #define FILTER_LEVEL(filter_level) ((FilterLevel *)filter_level) @@ -3330,12 +3339,16 @@ gtk_tree_model_filter_convert_iter_to_child_iter (GtkTreeModelFilter *filter, else { GtkTreePath *path; + gboolean valid = FALSE; path = gtk_tree_model_filter_elt_get_path (filter_iter->user_data, filter_iter->user_data2, filter->priv->virtual_root); - gtk_tree_model_get_iter (filter->priv->child_model, child_iter, path); + valid = gtk_tree_model_get_iter (filter->priv->child_model, child_iter, + path); gtk_tree_path_free (path); + + g_return_if_fail (valid == TRUE); } } diff --git a/gtk/gtktreemodelsort.c b/gtk/gtktreemodelsort.c index c5186125c0..9a59a802d3 100644 --- a/gtk/gtktreemodelsort.c +++ b/gtk/gtktreemodelsort.c @@ -228,9 +228,18 @@ struct _GtkTreeModelSortPrivate gulong reordered_id; }; - -#define GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS(tree_model_sort) \ +/* Set this to 0 to disable caching of child iterators. This + * allows for more stringent testing. It is recommended to set this + * to one when refactoring this code and running the unit tests to + * catch more errors. + */ +#if 1 +# define GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS(tree_model_sort) \ (((GtkTreeModelSort *)tree_model_sort)->priv->child_flags>K_TREE_MODEL_ITERS_PERSIST) +#else +# define GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS(tree_model_sort) (FALSE) +#endif + #define SORT_ELT(sort_elt) ((SortElt *)sort_elt) #define SORT_LEVEL(sort_level) ((SortLevel *)sort_level) @@ -2422,11 +2431,14 @@ gtk_tree_model_sort_convert_iter_to_child_iter (GtkTreeModelSort *tree_model_sor else { GtkTreePath *path; + gboolean valid = FALSE; path = gtk_tree_model_sort_elt_get_path (sorted_iter->user_data, sorted_iter->user_data2); - gtk_tree_model_get_iter (priv->child_model, child_iter, path); + valid = gtk_tree_model_get_iter (priv->child_model, child_iter, path); gtk_tree_path_free (path); + + g_return_if_fail (valid == TRUE); } }