Rusty Russell [Mon, 17 Jan 2011 05:50:15 +0000 (16:20 +1030)]
ccanlint: check examples actually mention thing they are demonstrating.
Brad suggested this after finding one such cut & paste in str:
rusty@vivaldi:~/devel/cvs/ccan/ccan/str$ ../../tools/ccanlint/ccanlint
Example: sections demonstrate appropriate function (examples_relevant): FAIL
/home/rusty/devel/cvs/ccan/ccan/str/str.h:64:Example for strcount doesn't mention it
Total score: 37/38
Rusty Russell [Mon, 17 Jan 2011 05:47:49 +0000 (16:17 +1030)]
ccanlint: score_file_error() takes printf-format
We simply build up the error string in score_file_error; a bit different
but simpler than current behaviour. We keep around struct file_error
because some tests need it.
Rusty Russell [Thu, 13 Jan 2011 08:55:01 +0000 (19:25 +1030)]
htable: fix type of cmpfn in htable_type
It in fact takes an object and a key to compare, not two keys.
The test case had the key as first element of the object, so it worked,
but ccanlint lost track of module dependencies due to this bug, and thus
would build submodules multiple times.
Rusty Russell [Mon, 10 Jan 2011 05:17:24 +0000 (15:47 +1030)]
rbtree: don't use temporary context to destroy rbtree
It leads to a memory leak if the allocation fails (as we reparent onto NULL).
Also, the extra allocation in the failure path increases test time for
failtest (under valgrind) by a factor of 2.
Rusty Russell [Mon, 10 Jan 2011 05:53:46 +0000 (16:23 +1030)]
rbtree: use failtest to check handling of allocation failures.
Unfortunately this means we have to reduce run-many from 1000 nodes to 100
(as forking under valgrind is really slow: test takes about 2 minutes with
100 nodes).
this is the minimal fix for the problem Rusty found. I previously
thought that the best fix would be to change tc->parent to be valid
for all pointers, but that is expensive for realloc with large numbers
of child pointers, which is much more commmon than I expected it to
be.
Joey Adams [Thu, 6 Jan 2011 15:50:04 +0000 (10:50 -0500)]
opt: Fix warnings with gcc-4.5 (same approach as commit 6535bde)
&*ptr is used in some other macros, but at a glance, they look like
cases where the pointer shouldn't be NULL . Didn't change those,
and if we get more warnings, we'll cross that bridge when we get to it.
For now, I suppose they are just free NULL checks.
Rusty Russell [Tue, 4 Jan 2011 10:41:47 +0000 (21:11 +1030)]
ccanlint: have valgrind fail with an error, always
The upcoming failtest module can only tell that a child failed when it
exits with a non-zero error. So we need this, although it means for ccanlint
it still needs to look at output to distinguish a memory leak from a real
error.
Rusty Russell [Thu, 16 Dec 2010 05:33:41 +0000 (16:03 +1030)]
typesafe_cb: Fix warnings with gcc-4.5:
Test compiled with warnings:
/home/rusty/devel/cvs/ccan/ccan/typesafe_cb/test/compile_ok-typesafe_cb-NULL.c:/home/rusty/devel/cvs/ccan/ccan/typesafe_cb/test/compile_ok-typesafe_cb-NULL.c: In function ‘main’:
/home/rusty/devel/cvs/ccan/ccan/typesafe_cb/test/compile_ok-typesafe_cb-NULL.c:18:2: warning: taking address of expression of type ‘void’
/home/rusty/devel/cvs/ccan/ccan/typesafe_cb/test/compile_ok-typesafe_cb-NULL.c:18:2: warning: taking address of expression of type ‘void’
/home/rusty/devel/cvs/ccan/ccan/typesafe_cb/test/compile_ok-typesafe_cb-NULL.c:18:2: warning: taking address of expression of type ‘void’
/home/rusty/devel/cvs/ccan/ccan/typesafe_cb/test/compile_ok-typesafe_cb-NULL.c:18:2: warning: taking address of expression of type ‘void’
/home/rusty/devel/cvs/ccan/ccan/typesafe_cb/test/compile_ok-typesafe_cb-NULL.c:18:2: warning: taking address of expression of type ‘void’
/home/rusty/devel/cvs/ccan/ccan/typesafe_cb/test/compile_ok-typesafe_cb-NULL.c:18:2: warning: taking address of expression of type ‘void’
/home/rusty/devel/cvs/ccan/ccan/typesafe_cb/test/compile_ok-typesafe_cb-NULL.c:18:2: warning: taking address of expression of type ‘void’
/home/rusty/devel/cvs/ccan/ccan/typesafe_cb/test/compile_ok-typesafe_cb-NULL.c:19:2: warning: taking address of expression of type ‘void’
Rusty Russell [Mon, 13 Dec 2010 08:15:25 +0000 (18:45 +1030)]
ccanlint: report valgrind "definite" leaks.
This is complicated by valgrind's limited options, and our desire not to run
valgrind twice (it's already the slowest part of the tests).
Ideally I'd like a different error code for each kind of error. I
could parse and pretty-print the XML output, but instead I just parse
the human-readable (which is fragile).
Ronnie Sahlberg [Wed, 8 Dec 2010 01:00:35 +0000 (12:00 +1100)]
rb_tree: fix trbt_delete
trbt_delete32() was broken and caused SEGV as soon as you tried to
delete an object from a tree.
Rework trbt_delete32() to instead just call talloc_free() instread of trying
to call delete_node() directly.
This makes the "from_destructor" argument to delete_node() redundant
so that parameter is removed too.
Signed-off-by: Ronnie Sahlberg <sahlberg@lenovo-laptop.(none)>
Rusty Russell [Wed, 8 Dec 2010 00:34:03 +0000 (11:04 +1030)]
ccanlint: fix compile on x86-64
cc -g -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -I. -MD -Werror -c -o tools/ccanlint/tests/examples_run.o tools/ccanlint/tests/examples_run.c
cc1: warnings being treated as errors
tools/ccanlint/tests/examples_run.c: In function ‘scan_forv’:
tools/ccanlint/tests/examples_run.c:37: warning: passing argument 2 of ‘__builtin_va_copy’ discards qualifiers from pointer target type
tools/ccanlint/tests/examples_run.c:43: warning: passing argument 4 of ‘scan_forv’ from incompatible pointer type
tools/ccanlint/tests/examples_run.c:52: warning: passing argument 4 of ‘scan_forv’ from incompatible pointer type
tools/ccanlint/tests/examples_run.c:60: warning: passing argument 4 of ‘scan_forv’ from incompatible pointer type
tools/ccanlint/tests/examples_run.c: In function ‘scan_for’:
tools/ccanlint/tests/examples_run.c:78: warning: passing argument 4 of ‘scan_forv’ from incompatible pointer type
make: *** [tools/ccanlint/tests/examples_run.o] Error 1
It really doesn't like constifying a va_arg, so remove the const declaration.
Right-shifting signed integers in undefined; indeed it seems that on
AIX with their compiler, doing a 30-bit shift on (INT_MAX-200) gives
0, not 1 as we might expect (THIS WAS WRONG, REAL FIX LATER).
The obvious fix is to make id and oid unsigned: l (level count) is also
logically unsigned.
(Note: Samba doesn't generally get to ids > 1 billion, but ctdb does)
Reported-by: Chris Cowan <cc@us.ibm.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Author: Rusty Russell <rusty@rustorp.com.au>
Date: Thu Jun 10 13:27:51 2010 -0700
Since idtree assigns sequentially, it rarely reaches high numbers.
But such numbers can be forced with idr_get_new_above(), and that
reveals two bugs:
1) Crash in sub_remove() caused by pa array being too short.
2) Shift by more than 32 in _idr_find(), which is undefined, causing
the "outside the current tree" optimization to misfire and return NULL.
Rusty Russell [Wed, 1 Dec 2010 13:13:37 +0000 (23:43 +1030)]
tdb2: hash chaining
If we get enough hash collisions, we can run out of hash bits; this almost
certainly is caused by a deliberate attempt to break the tdb (hash bombing).
Implement chained records for this case; they're slow but will keep the
rest of the database functioning.
Rusty Russell [Wed, 1 Dec 2010 13:11:26 +0000 (23:41 +1030)]
tdb2: use magic freetable value rather than different magic for coalescing
We have to unlock during coalescing, so we mark records specially to indicate
to tdb_check that they're not on any list, and to prevent other coalescers
from grabbing them.
Use a special free list number, rather than a new magic.
Rusty Russell [Wed, 1 Dec 2010 13:10:05 +0000 (23:40 +1030)]
tdb2: compare the extra 11 hash bits in the header.
We already have 10 hash bits encoded in the offset itself; we only get
here incorrectly about 1 time in 1000, so it's a pretty minor
optimization at best.
Nonetheless, we have the information, so let's check it before
accessing the key. This reduces the probability of a false keycmp by
another factor of 2000.