[gtk+] tests: Remove deleted rows from cache
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] tests: Remove deleted rows from cache
- Date: Mon, 19 Mar 2012 01:26:40 +0000 (UTC)
commit 6df7562570058da0449700466715a6dd33b8c98b
Author: Benjamin Otte <otte redhat com>
Date: Mon Mar 19 02:24:59 2012 +0100
tests: Remove deleted rows from cache
Otherwise the GNode pointer address that we use for indexing might get
reused for a new node and then we don't start out with a pristine
refcount.
gtk/tests/gtktreemodelrefcount.c | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/gtk/tests/gtktreemodelrefcount.c b/gtk/tests/gtktreemodelrefcount.c
index 76a38f1..7f29f99 100644
--- a/gtk/tests/gtktreemodelrefcount.c
+++ b/gtk/tests/gtktreemodelrefcount.c
@@ -59,6 +59,28 @@ G_DEFINE_TYPE_WITH_CODE (GtkTreeModelRefCount, gtk_tree_model_ref_count, GTK_TYP
gtk_tree_model_ref_count_tree_model_init))
static void
+row_removed (GtkTreeModelRefCount *ref_model,
+ GtkTreePath *path)
+{
+ GHashTableIter iter;
+ GtkTreeIter tree_iter;
+
+ if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ref_model), &tree_iter))
+ {
+ g_hash_table_remove_all (ref_model->priv->node_hash);
+ return;
+ }
+
+ g_hash_table_iter_init (&iter, ref_model->priv->node_hash);
+
+ while (g_hash_table_iter_next (&iter, &tree_iter.user_data, NULL))
+ {
+ if (!gtk_tree_store_iter_is_valid (GTK_TREE_STORE (ref_model), &tree_iter))
+ g_hash_table_iter_remove (&iter);
+ }
+}
+
+static void
gtk_tree_model_ref_count_init (GtkTreeModelRefCount *ref_model)
{
ref_model->priv = G_TYPE_INSTANCE_GET_PRIVATE (ref_model,
@@ -69,6 +91,8 @@ gtk_tree_model_ref_count_init (GtkTreeModelRefCount *ref_model)
g_direct_equal,
NULL,
(GDestroyNotify)node_info_free);
+
+ g_signal_connect (ref_model, "row-deleted", G_CALLBACK (row_removed), NULL);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]