Sprinkle various g_assert() around the code where gcc cannot figure out
on its own that a variable is not NULL and too much refactoring would be
needed to make it do that.
Also fix usage of g_assert_nonnull(x) to use g_assert(x) because the
first is not marked as G_GNUC_NORETURN because of course GTester
supports not aborting on aborts.
The format of the printout will be suitable for addition as a new test to
testsuite/gtk/rbtree-crash.c
by just grepping the printouts from the relevant rbtree.
The refactoring of automatically updating tree->root when setting a
node's parent works very well - unless all nodes get removed and no
node's parent got updated.
The tree is not needed to walk around the nodes.
It is however still needed for anything that requires modifying the
tree.
There is no immediate benefit in changing this API, but there might be
situations in the future where we can avoid looking up the tree when we
just want to check some details about the node.
Store a link to the tree in the root node. This allows looking up the
tree in O(log N) from the node without any extra memory usage.
This is useful because code can just store a pointer to the node and
doesn't need to keep the tree pointer around. And that can (for large
trees) save quite a bit of memory.
Searching through the tree is too specific to use a general function.
All the existing code just copies and slightly adapts the same 20 lines
instead, so there's no reason to keep the complicated API.
The g_print documentation explicitly says not to do this, since
g_print is meant to be redirected by applications. Instead use
g_message for logging that can be triggered via GTK_DEBUG.
Also remove the starting underscore from function names where
appropriate, as those functions are static now and not exported anymore.
This is part of a bunch of fixes for gcc complaining about
-Wmissing-declarations.
_gtk_rbtree_reorder() was moving the node's data while reordering. As we
use the node pointer in the a11y code as a hash key, this didn't work.
So this rewrite changes that. As a bonus, it is less code and faster.
Woohoo!
- Make sure the rotated nodes aren't nil
- Use existing functions for complex computations
- Don't use NULL checks for variables guaranteed to not be NULL/nil
This has one major caveat: The new value is const, so read-only memory.
Any attempt to write to it will cause a crash. Note that we are not ever
supposed to write to it, but bugs happen...
The code used to set nil->parent, which could cause segfaults. Don't do
that. We also need to pass the parent explicitly to the fixup code,
because the node during fixup may be the nil node.
So instead of copying the children and height to the new node, we keep
the old node and copy all the old stuff to it.
This is necessary so the accessibility code can use the node as a key in
the hash table or store the node as a reference to the row instead of
GtkTreeRowReference. And because it already does that (oops), this fixes
a bunch of segfaults with a11y enabled.
gtk_rbtree_adjust() will adjust the summed values of a node and all its
parents in the tree. Currently only implemented by splitting out the
function from gtk_rbtree_free().
.. as a replacement for _gtk_rbtree_node_find_parity(). Instead of 1 or
0, the function now returns the index of node in the complete tree
(counting from the root). And this is of course identical to the row
number.
Instead of just storing the least significant bit of the row number,
store the full row number. This will soon be useful for accessibility.
But CSS could like it, too.
Preferrably should be made just into a local variable for libgtk like
_gdk_debug_flags for libgdk. But for now used by
gtk/tests/textbuffer.c and modules/printbackends/cups/gtkprintbackendcups.c.
2006-01-18 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkrbtree.c:
* gtk/gtktreemodel.c: Fix several g_new() calls which
were using extra indirections or pointless casts.
(#327423, Morten Welinder)