Re: gtk_tree_model_sort_increment_stamp doesn't increment stamp
- From: Darin Adler <darin bentspoon com>
- To: Jonathan Blandford <jrb redhat com>
- Cc: Gtk Developers <gtk-devel-list gnome org>
- Subject: Re: gtk_tree_model_sort_increment_stamp doesn't increment stamp
- Date: Mon, 11 Feb 2002 16:22:56 -0800
On 2/11/02 4:11 PM, "Jonathan Blandford" <jrb redhat com> wrote:
> Eek. That is almost certainly supposed to be:
>
> do { tree_model_sort->stamp++; } while (tree_model_sort->stamp == 0);
>
> We don't want stamp wrapping around to 0, but we do want to increase it
> most of the time. (-;
I had assumed that, and I changed it to that, and found all sorts of asserts
firing. I think gtk_tree_model_sort_increment_stamp is called at in many
places where it's not correct to invalidate all outstanding iterators.
I have a more-correct version of the patch to fix the insert_value function,
but things aren't sorting correctly for me, so I assume there's more to fix.
That's why I didn't post the patch before now. I'm running out of stamina
for GtkTreeModelSort hacking for today.
Also, there is enough untested here that I think I (or someone else) better
debug this in a GtkTreeModelSort test, rather than using the Nautilus tree
view as the test case.
Here's the latest version of that other patch. Apologies for some gratuitous
formatting fixups. OK to commit?
Index: gtk/gtktreemodelsort.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreemodelsort.c,v
retrieving revision 1.54
diff -p -u -r1.54 gtktreemodelsort.c
--- gtk/gtktreemodelsort.c 2002/02/09 21:56:30 1.54
+++ gtk/gtktreemodelsort.c 2002/02/12 00:15:45
@@ -99,6 +99,8 @@ enum {
#define GET_CHILD_ITER(tree_model_sort,child_iter,sort_iter)
gtk_tree_model_sort_convert_iter_to_child_iter(GTK_TREE_MODEL_SORT
(tree_model_sort), child_iter, sort_iter);
+#define NO_SORT_FUNC ((GtkTreeIterCompareFunc) 0x1)
+
/* general (object/interface init, etc) */
static void gtk_tree_model_sort_init (GtkTreeModelSort
*tree_model_sort);
static void gtk_tree_model_sort_class_init
(GtkTreeModelSortClass *tree_model_sort_class);
@@ -456,7 +458,9 @@ gtk_tree_model_sort_row_changed (GtkTree
level = iter.user_data;
elt = iter.user_data2;
- if (level->array->len < 2 || tree_model_sort->sort_column_id == -1)
+ if (level->array->len < 2 ||
+ (tree_model_sort->sort_column_id ==
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID &&
+ tree_model_sort->default_sort_func == NO_SORT_FUNC))
{
if (free_s_path)
gtk_tree_path_free (start_s_path);
@@ -788,8 +792,8 @@ gtk_tree_model_sort_rows_reordered (GtkT
g_array_index (level->array, SortElt, i).offset = tmp_array[i];
g_free (tmp_array);
- if (tree_model_sort->sort_column_id == -1 &&
- tree_model_sort->default_sort_func == (GtkTreeIterCompareFunc) 0x1)
+ if (tree_model_sort->sort_column_id ==
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID &&
+ tree_model_sort->default_sort_func == NO_SORT_FUNC)
{
gtk_tree_model_sort_sort_level (tree_model_sort, level,
@@ -1459,19 +1463,14 @@ gtk_tree_model_sort_sort_level (GtkTreeM
data.sort_data = tree_model_sort->default_sort_data;
}
- if (tree_model_sort->sort_column_id ==
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID &&
- tree_model_sort->default_sort_func == (GtkTreeIterCompareFunc) 0x1)
- {
- g_array_sort_with_data (sort_array,
- gtk_tree_model_sort_offset_compare_func,
- &data);
- }
+ if (data.sort_func == NO_SORT_FUNC)
+ g_array_sort_with_data (sort_array,
+ gtk_tree_model_sort_offset_compare_func,
+ &data);
else
- {
- g_array_sort_with_data (sort_array,
- gtk_tree_model_sort_compare_func,
- &data);
- }
+ g_array_sort_with_data (sort_array,
+ gtk_tree_model_sort_compare_func,
+ &data);
gtk_tree_path_free (data.parent_path);
@@ -1579,22 +1578,29 @@ gtk_tree_model_sort_level_find_insert (G
gpointer data;
GtkTreePath *path;
-
- {
- GtkTreeDataSortHeader *header;
- header = _gtk_tree_data_list_get_header (tree_model_sort->sort_list,
- tree_model_sort->sort_column_id);
-
- if (!header)
- return 0;
-
- g_return_val_if_fail (header->func != NULL, 0);
-
- func = header->func;
- data = header->data;
- }
+ if (tree_model_sort->sort_column_id !=
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID)
+ {
+ GtkTreeDataSortHeader *header;
+
+ header = _gtk_tree_data_list_get_header (tree_model_sort->sort_list,
+ tree_model_sort->sort_column_id);
+
+ g_return_val_if_fail (header != NULL, 0);
+
+ func = header->func;
+ data = header->data;
+ }
+ else
+ {
+ func = tree_model_sort->default_sort_func;
+ data = tree_model_sort->default_sort_data;
+
+ g_return_val_if_fail (func != NO_SORT_FUNC, 0);
+ }
+ g_return_val_if_fail (func != NULL, 0);
+
for (middle = 0; middle < level->array->len; middle++)
{
tmp_elt = &(g_array_index (level->array, SortElt, middle));
@@ -1641,9 +1647,13 @@ gtk_tree_model_sort_insert_value (GtkTre
elt.ref_count = 0;
elt.children = NULL;
- index = gtk_tree_model_sort_level_find_insert (tree_model_sort,
- level, s_iter,
- FALSE);
+ if (tree_model_sort->sort_column_id ==
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID &&
+ tree_model_sort->default_sort_func == NO_SORT_FUNC)
+ index = offset;
+ else
+ index = gtk_tree_model_sort_level_find_insert (tree_model_sort,
+ level, s_iter,
+ FALSE);
g_array_insert_vals (level->array, index, &elt, 1);
@@ -1764,7 +1774,7 @@ gtk_tree_model_sort_set_model (GtkTreeMo
tree_model_sort->sort_list = _gtk_tree_data_list_header_new
(n_columns, types);
g_free (types);
- tree_model_sort->default_sort_func = (GtkTreeIterCompareFunc)0x1;
+ tree_model_sort->default_sort_func = NO_SORT_FUNC;
tree_model_sort->stamp = g_random_int ();
}
}
@@ -2117,13 +2127,9 @@ gtk_tree_model_sort_free_level (GtkTreeM
}
if (sort_level->parent_elt)
- {
- sort_level->parent_elt->children = NULL;
- }
+ sort_level->parent_elt->children = NULL;
else
- {
- tree_model_sort->root = NULL;
- }
+ tree_model_sort->root = NULL;
g_array_free (sort_level->array, TRUE);
sort_level->array = NULL;
@@ -2155,10 +2161,7 @@ gtk_tree_model_sort_clear_cache_helper (
}
if (level->ref_count == 0 && level != tree_model_sort->root)
- {
- gtk_tree_model_sort_free_level (tree_model_sort, level);
- return;
- }
+ gtk_tree_model_sort_free_level (tree_model_sort, level);
}
/**
@@ -2176,7 +2179,7 @@ gtk_tree_model_sort_reset_default_sort_f
if (tree_model_sort->default_sort_destroy)
(* tree_model_sort->default_sort_destroy)
(tree_model_sort->default_sort_data);
- tree_model_sort->default_sort_func = (GtkTreeIterCompareFunc) 0x1;
+ tree_model_sort->default_sort_func = NO_SORT_FUNC;
tree_model_sort->default_sort_data = NULL;
tree_model_sort->default_sort_destroy = NULL;
tree_model_sort->sort_column_id =
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID;
===================================================================
-- Darin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]