Rusty Russell [Wed, 6 Apr 2011 22:54:41 +0000 (08:24 +0930)]
typesafe_cb: simplify, preserve namespace.
Get rid of many variants, which were just confusing for most people.
Keep typesafe_cb(), typesafe_cb_preargs() and typesafe_cb_postarts(),
and rework cast_if_type() into typesafe_cb_cast() so we stay in our
namespace.
I should have done this as soon as I discovered the limitation that
the types have to be defined if I want const-taking callbacks.
Andreas Schlick [Sat, 2 Apr 2011 01:30:36 +0000 (12:00 +1030)]
asort: Remove the trampoline version.
Most Linux systems use glibc and therefore have qsort_r() and for the others an
implementation is provided, therefore there is no need to have a third case in
asort.
Rusty Russell [Mon, 28 Mar 2011 03:58:22 +0000 (14:28 +1030)]
failtest: continue (without failing) if we run off end of --failpath=
This is important because we tell people to use --failpath to reproduce a
failure, but the fail path we list only goes up to the last failure injection
if the child dies, for example.
Thanks to David Gibson for prodding me to fix this...
Rusty Russell [Mon, 28 Mar 2011 03:48:49 +0000 (14:18 +1030)]
tdb2: make head of free list point to last entry.
This allows for access to the end of the list, in case we need it
later (eg. moving free list entries to the end of the list after
failed coalescing?).
Here's the effect (average of 10) on x8664 with gcc 4.1.2, with an earlier
tree and 1000000:
Before:
Adding 830.1ns
Finding 428.3ns
Missing 250.3ns
Traversing 387.4ns
Deleting 588.8ns
Re-adding 737.2ns
Appending 1141.4ns
Churning 1792ns
Rusty Russell [Fri, 25 Mar 2011 05:39:05 +0000 (16:09 +1030)]
tdb2: fix traversal bug in free list lock_and_alloc()
We keep looking even if the current best is exactly right. This is
really bad, because our smaller free lists hold exactly one size: with
this bug we iterate to the end of the list before hitting the end and
deciding we can use it after all.
Rusty Russell [Thu, 24 Mar 2011 03:40:22 +0000 (14:10 +1030)]
tdb2: fix use after free on error message
We use "r" after we call tdb_access_release() when we find corruption
in the free list. "r" may be a pointer into malloced memory, freed
by tdb_access_release().
Rusty Russell [Thu, 24 Mar 2011 01:12:21 +0000 (11:42 +1030)]
tdb2: fix two transaction bugs.
One but were we didn't update the map_size if we expanded the
transaction but didn't create a new recovery area (most easily
reproduced by setting the TDB_NOSYNC flag).
Another out-by-one bug in transaction_direct where we would give
read-access to the underlying file despite the last block having been
modified.
Rusty Russell [Thu, 24 Mar 2011 01:24:43 +0000 (11:54 +1030)]
tdb2: check PID if we are holding a lock.
tdb1 has tdb_reopen/tdb_reopen_all, which you are supposed to call
after a fork(). But we can detect PID changes whenever we grab a lock,
which is to say, before we do anything.
We currently assume that pread and pwrite work, so the only problem
with fork() is if we are holding locks and expect them to still be
there in the child. This is unusual, but most likely caused by a
fork() inside a transaction. In such cases, allow the child to unlock
without complaint; they can then use the TDB as expected.
Performance before and after shows no measurable speed difference:
Total of 5 runs of tools/speed 100000:
Before:
Adding: 18899ns
Finding: 7040ns
Missing: 5802ns
Traversing: 6466ns
Deleting: 12607ns
Re-adding: 14185ns
Appending: 20770ns
Churning: 93845ns
Rusty Russell [Fri, 25 Mar 2011 03:21:20 +0000 (13:51 +1030)]
ccanlint: fix listing of dependencies
gcc gave a warning:
tools/ccanlint/ccanlint.c:230:19: error: ācā may be used uninitialized in this function
Which indicated that test dependency printing was broken: we need to
loop through the tests! Also, we haven't parsed options yet, so
verbose is never true: move it to later and make it depend on -vvv.
David Gibson [Fri, 18 Mar 2011 08:29:16 +0000 (19:29 +1100)]
Add configurator test for memmem()
memmem(), which searches for one bytestring in a longer
bytestring is one of those functions that should be standard, but
isn't. This patch adds a ccan configurator test for the function
so that modules can use or replace it as necessary.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Rusty Russell [Tue, 22 Mar 2011 04:22:13 +0000 (14:52 +1030)]
ccanlint: exit with non-zero exit status if a test fails.
This means we change some minor tests to "never fail", eg. whitespace
or documentation tests. Note that pass/fail is independent of the
score for a test.
Rusty Russell [Tue, 22 Mar 2011 01:21:00 +0000 (11:51 +1030)]
ccan: add -Wpointer-arith and -Wwrite-strings by default
Wpointer-arith is useful for spotting GCC-isms which do arithmetic on
void pointers. Wwrite-strings treats string constants as const char *,
which is sane (but bad for legacy code).
Rusty Russell [Tue, 22 Mar 2011 01:18:43 +0000 (11:48 +1030)]
opt: allow const arguments.
This need shows up most clearly with opt_usage_and_exit and gcc's
-Wwrite-strings, where string literals become "const char *". Our
callbacks should take const void *: since we overload the arg field
already (to hold table size) it make sense to turn it into a proper
union.
Rusty Russell [Mon, 21 Mar 2011 11:42:17 +0000 (22:12 +1030)]
tdb2: tdb_mkdata
It's common to want to create a struct tdb_data which contains a const
pointer, so add a helper to do so, and use it to clean up other -Wcast-qual
warnings.
Rusty Russell [Mon, 21 Mar 2011 11:47:42 +0000 (22:17 +1030)]
cast: fix compilation with GCC's -Wcast-qual
Samba uses -Wcast-qual to warn about casting away const. The kind of
coders who care about const correctness are likely to turn that option
on, so we should make sure it's compatible with cast_const().
Rusty Russell [Mon, 21 Mar 2011 03:14:22 +0000 (13:44 +1030)]
foreach: fix case where iterators are not on the stack.
The foreach garbage collection assumed that iterators were all on the
stack, but they could be on the heap or a global (or static) variable.
We can prevent the heap case by tricky use of macros to complain on
any iterator which isn't a single token, but we can't prevent
globals/statics.
So, if an iterator already seems to be "off" the stack, mark it as
such and simply never free it.
Rusty Russell [Mon, 21 Mar 2011 02:43:51 +0000 (13:13 +1030)]
foreach: allow a single argument to foreach_int() and foreach_ptr().
David Gibson noted that foreach requires more than one argument.
There's no particularly good reason for this, other than lack of
imagination on my part.
Rusty Russell [Thu, 17 Mar 2011 11:42:20 +0000 (22:12 +1030)]
tdb2: tdb_name and tdb_fd functions.
As per TDB1, with one enhancement: a non-NULL name argument passed to
tdb_open() with the TDB_INTERNAL flag is preserved so you can identify
internal TDBs too.
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: implement tdb_exists and tdb_parse_record
These are the same as the TDB1 functions; but note that there is no reliable
way to tell if tdb_exists() fails due to an error. This simplifies the API,
but means you have to use tdb_fetch() if you really care.
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: move file operations into separate structure
This moves the fd and locking information into a new 'struct tdb_file',
opening the way for it to be shared by multiple tdb_open calls on the
same file.
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: make sure records with extra padding have a 0 byte.
As detailed in doc/design.lyx section 2.16 "Record Headers Are Not
Expandible", we make sure that if there is padding at the end of a record,
the first byte of padding is a zero.
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: feature support.
As detailed in doc/design.lyx section 2.15 "Extending The Header Is
Difficult"; we add features_used and features_offered fields to the
header, so we can identify if we add new features, and then if someone
opens it who doesn't understand that feature.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
ccanlint: fix gdb line in tests_pass helper.
Recent changes shifted line numbers in tap.c, so the break is now in
the wrong place. We should probably have an explicit function we can
breakpoint instead.