Commit Graph

83 Commits

Author SHA1 Message Date
Benjamin Otte
e356d59a92 build: Add -Wnull-dereference
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.
2020-03-05 08:14:37 +01:00
Benjamin Otte
dc86c744bf rbtree: Simplify macros
* NODE_FROM_POINTER() can not be NULL

* shuffle NODE_TO_POINTER() code for readability so that the NULL check
  is on the outside and not the cast
2020-03-05 07:59:05 +01:00
Benjamin Otte
9fedcec82e rbtree: Simplify code
This makes it easier to understand for gcc (and hopefully humans, too)
that by rotating we essentially just swap `node` and `p`.
2020-03-05 07:59:05 +01:00
Benjamin Otte
af56f06b7b rbtree: Fix a crash in insertion fixup
This got broken in commit a33ff4c6ab.

Testcase included.
2019-01-20 06:09:40 +01:00
Benjamin Otte
5e00cdbd74 rbtree: Add a trivial way to add rbtree tests to the testsuite.
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.
2019-01-20 06:09:40 +01:00
Benjamin Otte
e104337704 rbtree: Fix removing last element
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.
2019-01-14 18:42:18 +01:00
Benjamin Otte
8a7706f2b5 rbtree: Make node getters not require tree argument
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.
2019-01-14 02:14:11 +01:00
Benjamin Otte
6a3c2a230a rbtree: Add gtk_rb_tree_node_get_tree()
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.
2019-01-14 02:14:11 +01:00
Benjamin Otte
a33ff4c6ab rbtree: Access node->parent only via accessors
This also adds a set_parent() function that automatically takes care of
updating tree->root for root nodes.
2019-01-14 02:14:11 +01:00
Benjamin Otte
7ff949ea30 rbtree: Remove gtk_rb_tree_find()
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.
2019-01-14 02:14:11 +01:00
Matthias Clasen
25bca27bfe Rename GtkCssRBTree to GtkRBTree
This is a generally usable red-black tree api,
and it is not used in css at all.
2019-01-14 02:14:11 +01:00
Matthias Clasen
e269f43afc Rename GtkRBTree to GtkTreeRBTree
This frees up the generic name for a more
generic rbtree implementation.
2019-01-14 02:14:11 +01:00
Benjamin Otte
cf030e9ffc rbtree: Privatize header
According to meson it's the only private header that doesn't conform to
the *private.h naming.

Fix that.
2018-02-03 16:24:13 +01:00
Matthias Clasen
2ee7fb1818 Don't use g_print for debug output
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.
2016-02-28 21:40:23 -05:00
Matthias Clasen
bbd94b5a9f gtk: Strip newlines from g_warning and g_error
g_logv adds one for us already.
2016-02-28 12:23:12 -05:00
Matthias Clasen
3526b08e01 Clean up debug features
Introduce a GTK_DEBUG_CHECK() macro and use it to check for
GTK_DEBUG flags everywhere. Also guard all such places by
2015-09-09 06:32:46 -04:00
Benjamin Otte
12683da8f7 gtk: Make functions static that don't need to be non-static
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.
2012-10-02 19:32:51 +02:00
Javier Jardón
9d0febc9a6 Change FSF Address 2012-02-27 17:06:11 +00:00
Benjamin Otte
710a8435cc rbtree: Add _gtk_rbtree_contains()
It's useful in a bunch of places, so split it out
2011-12-10 08:00:25 +01:00
Benjamin Otte
6d0499a500 rbtree: Rewrite to not lose node order
_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!
2011-11-22 23:29:04 +01:00
Benjamin Otte
d8b6414567 rbtree: Remove needless tests
if the checks are run on the nil node, they will get the second test the
  way we expect it anyway, so it's unnecessary.
2011-11-22 03:42:31 +01:00
Benjamin Otte
ae99a9e04a rbtree: Simplify rotation functions
- 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
2011-11-22 03:32:56 +01:00
Benjamin Otte
37786804e1 rbtree: Remove the nil member 2011-11-22 03:32:56 +01:00
Benjamin Otte
a4630d0e7b rbtree: Introduce _gtk_rbtree_is_nil()
Makes for more readable code than "== tree->nil" and allows removing the
nil member later.
2011-11-22 03:32:56 +01:00
Benjamin Otte
c3056951db rbtree: Introduce _gtk_rbtree_first()
... and use it.
2011-11-22 03:32:56 +01:00
Benjamin Otte
73a834336f rbtree: Replace nil node allocation with a preallocated 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...
2011-11-22 03:32:56 +01:00
Benjamin Otte
647c441e26 rbtree: Don't write to nil node
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.
2011-11-21 22:33:46 +01:00
Benjamin Otte
f4fe921a17 rbtree: Add a local variable
This will be needed in the next patch, and I wanted to split that patch
up.
2011-11-21 22:33:46 +01:00
Benjamin Otte
02671f9ec9 rbtree: Move to an approach where we don't move contents
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.
2011-11-21 22:33:45 +01:00
Benjamin Otte
1dd9dd45c1 rbtree: Use gtk_rbnode_adjust() even more
Use it for the modified node in gtk_rbnode_remove(). Cleans up the code
quite a lot.
2011-11-21 22:33:45 +01:00
Benjamin Otte
769186dbff rbtree: Use gtk_rbnode_adjust()
Make gtk_rbnode_remove() use it when unlinking the node.
2011-11-21 22:33:45 +01:00
Benjamin Otte
ba7a0a0188 rbtree: Use gtk_rbnode_adjust() more.
Make _gtk_rbtree_node_set_height() use it.
2011-11-21 22:33:45 +01:00
Benjamin Otte
7b2d414222 rbtree: Use gtk_rbnode_adjust() more
Make _gtk_rbtree_insert_before() use it.
2011-11-21 22:33:45 +01:00
Benjamin Otte
01a44e2a16 rbtree: Use gtk_rbnode_adjust()
Make _gtk_rbtree_insert_after() use it.
2011-11-21 22:33:45 +01:00
Benjamin Otte
22a4c15b4f rbtree: Split out a common function
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().
2011-11-21 22:33:45 +01:00
Benjamin Otte
54f3fbfe26 rbtree: Don't set variable twice 2011-11-21 22:33:45 +01:00
Benjamin Otte
6168a64713 rbtree: Add assertions to clarify usage 2011-11-21 22:33:45 +01:00
Benjamin Otte
69a516018f rbtree: Mark all debug sections as debug 2011-11-21 22:33:45 +01:00
Benjamin Otte
af2ebe638c rbtree: Make debug functions private
They're not used elsewhere
2011-11-21 22:33:45 +01:00
Benjamin Otte
a890a61253 treeview: Add _gtk_rbtree_node_get_index()
.. 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.
2011-11-16 04:39:24 +01:00
Benjamin Otte
635e53433d treeview: Add _gtk_rbtree_find_index()
Uses the parity to do an O(log N) search for the nth element in the
tree in display order of the treeview.
2011-11-16 04:31:06 +01:00
Benjamin Otte
59097ecef4 treeview: Rename "parity" to "total_count"
Now that we use it to actually count the rows instead of just even/odd,
it's better to reflect that in the variable name.
2011-11-16 04:31:06 +01:00
Benjamin Otte
320df163a2 treeview: Make the parity actually store 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.
2011-11-16 04:31:06 +01:00
Benjamin Otte
c8e2cd27e9 treeview: Remove special cases when computing parity
The parity of the nil npode is always 0, so no need to check for the nil
node first.
2011-11-16 04:31:06 +01:00
Tor Lillqvist
801875b805 Replace gtk_debug_flags with getter and setter functions
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.
2010-09-08 21:31:34 +03:00
Javier Jardón
0a07e9733b gtk/: fully remove gtkalias hacks
https://bugzilla.gnome.org/show_bug.cgi?id=623845
2010-07-10 02:51:26 +02:00
Javier Jardón
5bcf3ba72a Fix compilation warning: move function to proper location
Move _count_nodes() auxiliar function inside the
G_ENABLE_DEBUG define, where other auxiliar functions are.
2010-04-12 22:10:38 +02:00
Johan Dahlin
d97cdbdf53 Include "config.h" instead of <config.h> Command used: find -name
2008-06-21  Johan Dahlin  <jdahlin@async.com.br>

    * *.[ch]: Include "config.h" instead of <config.h>
    Command used:
    find -name \*.[ch]|xargs perl -p -i -e 's/^#include <config.h>/#include "config.h"/g'
    Rubberstamped by Mitch and Tim


svn path=/trunk/; revision=20669
2008-06-22 14:28:52 +00:00
Matthias Clasen
07e7719441 Apply a cleanup patch by Kjartan Maraas (#341812)
2006-10-08  Matthias Clasen  <mclasen@redhat.com>

	* Apply a cleanup patch by Kjartan Maraas  (#341812)
2006-10-08 05:07:55 +00:00
Matthias Clasen
1e05106801 Fix several g_new() calls which were using extra indirections or pointless
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)
2006-01-18 05:23:24 +00:00