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.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
str: provide checks for ctype.h char functions, and strstr and strchr functions.
In the former case, we were bitten by the fact that you don't pass a char
to isalpha() et al: you pass an int. This means on most platforms you want
to do:
if (isalpha((unsigned char)c)) ...
Insane? Yes, but I assure you I'm not making this up.
Similarly, I've always wanted strstr, strchr and strrchr to return
const char * when given a const char * argument to search, to avoid
constness leak.
In both cases, the actual versions from the headers may be macros, so
we need to be very careful overriding them. The result is that they
become out-of-line functions which is unacceptable for general
performance.
So we only activate these when CCAN_STR_DEBUG is defined.
Rusty Russell [Wed, 2 Mar 2011 00:15:51 +0000 (10:45 +1030)]
configurator: more robust test for HAVE_NESTED_FUNCTIONS
Thanks to Andreas Schlick, we have a nicer test for when gcc warns about
trampolines (gcc 4.6's -Wtrampolines). This works at any optimization level,
and means when that warning is enabled we recognize that we shouldn't allow
nested functions.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework hash.c functions to return enum TDB_ERROR.
This time we have to use our tri-value "tdb_bool_err" type to indicate
true, false, or error, which now allows us to correctly handle errors
in key matching (rather than treating it as a non-match).
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework some io.c functions to encode errors in their pointer returns.
This causes a subtle enhancement in tdb_direct(): it previously
returned NULL on both "can't use direct access" or "some error
occurred", as the caller always uses read/write functions as a
fallback anyway. Now we distinguish the error case.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework io functions to return enum TDB_ERROR.
We have a series of I/O functions which change depending on whether we're
inside a transaction or not. This makes them return enum TDB_ERROR instead
of int.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: restore file filling code.
This snuck in fe55330a which added the stats attribute. Without it,
TDB works but is vulnerable to segmenation faults or write errors when
disk is exhausted.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: Internal error helpers.
I use the "high pointers hold error numbers" trick, and also make
tdb_logerr return the error code, which enables the common case of
"return tdb_logerr(...)".