Eric Wong [Fri, 24 Oct 2014 22:02:32 +0000 (22:02 +0000)]
list: add list_for_each_rev_safe{,_off} macros
Deleting while iterating backwards will be needed in the
Ruby st_foreach_reverse_check implementation if we decide
to port Ruby's st.c to use ccan/list.
Signed-off-by: Eric Wong <normalperson@yhbt.net> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Eric Wong [Fri, 24 Oct 2014 22:02:31 +0000 (22:02 +0000)]
list: add list_for_each_rev_off macro
And re-implement list_for_each_rev in terms of list_for_each_rev_off
to avoid duplicating iteration logic.
Signed-off-by: Eric Wong <normalperson@yhbt.net> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Eric Wong [Fri, 24 Oct 2014 22:02:30 +0000 (22:02 +0000)]
list: new list_for_each{, _safe}_off_dir_ macros
These internal iteration macros will make implementing reverse
iteration simpler. For now, reimplement existing list_for_each_off
and list_for_each_safe_off macros on top of these macros to
prove they pass existing tests.
Signed-off-by: Eric Wong <normalperson@yhbt.net> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Eric Wong [Fri, 24 Oct 2014 22:02:29 +0000 (22:02 +0000)]
list: list_swap to exchange elements
This allows deleting and re-inserting an element in place
of the deleted element without branching.
Signed-off-by: Eric Wong <normalperson@yhbt.net> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Eric Wong [Fri, 24 Oct 2014 22:02:28 +0000 (22:02 +0000)]
list: list_add_after and list_add_before functions
These make it easy to add a new element before or after an
existing element in the middle of the list.
The existing list_add and list_add_tail functions are trivially
reimplemented on top of these new functions.
Signed-off-by: Eric Wong <normalperson@yhbt.net> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Stuart Longland [Fri, 22 Aug 2014 23:25:09 +0000 (09:25 +1000)]
stringbuilder: Functions for joining strings.
This is a small couple of functions for joining lists of strings
together. The lists can either be varadic arguments or arrays, and
delimiters are optional.
This patch incorporates some advice from David Gibson on the original
module.
Rusty Russell [Fri, 20 Mar 2015 01:06:52 +0000 (11:36 +1030)]
ntdb: fix up tests.
Mainly include path fixes.
Also Samba's unit tests were enhanced to detect the prefixes
helpapi and helprun to indicate an object was to be linked against
only api/run tests. We hack around that by #including the helper
code instead.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
David Disseldorp [Fri, 13 Mar 2015 16:45:16 +0000 (17:45 +0100)]
ntdb: next-generation trivial key-value database
ntdb is a partial rewrite of Samba's Trivial Database, providing > 4GB
database scalability and an improved API.
Obtained from the Samba repository at git://git.samba.org/samba.git, as
of bd13405e8570e9a5942165a8c52a2bc3fdc9d96e.
Rusty Russell [Wed, 29 Oct 2014 05:32:46 +0000 (16:02 +1030)]
timer: change timers_expire() to return a single timer.
The linked list method was problematic, especially if timers delete
other expired timers (eg. the next one in the expired list: the timer_del
will delete it from expired, but that's a bit unexpected).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
David Gibson [Sat, 11 Oct 2014 16:46:57 +0000 (18:46 +0200)]
bytestring: Add initializer macro
The BYTESTRING macro is constant, since it's designed to take a string
literal, but it doesn't count as constant since it involves an (inlined)
function call. That means it can't be used in a static storage duration
initializer.
Unfortunately, I can't see a portable way to make something which can be
used as an initializer, but which can also be used in other contexts where
BYTESTRING() can be used, so this patch introduces BYTESTRING_INIT() which
is similar to BYTESTRING() but produces an initializer.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Mon, 28 Jul 2014 09:33:33 +0000 (19:33 +1000)]
bytestring: Split bytestrings by a string delimiter
This introduces the functions bytestring_splitstr_first() and
bytestring_splitstr_next() which can be used to iterate through substrings
of a bytestring separated by a specified substring.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Mon, 28 Jul 2014 09:31:36 +0000 (19:31 +1000)]
bytestring: Split bytestrings by a set of character delimiters
This introduces the functions bytestring_splitchrs_first() and
bytestring_splitchrs_next() which can be used to iterate through substrings
of a bytestring separated by any of a given set of delimiter characters.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Mon, 28 Jul 2014 09:31:11 +0000 (19:31 +1000)]
bytestring: Split bytestrings by a character delimiter
This introduces the functions bytestring_splitchr_first() and
bytestring_splitchr_next() which can be used to iterate through substrings
of a bytestring separated by a single, specified delimiter character.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Wed, 22 Oct 2014 13:37:22 +0000 (15:37 +0200)]
bytestring: Implement bytestring_spn() and bytestring_cspn()
Add bytestring_spn() and bytestring_cspn() functions which, in analogy to
strspn() and strcspn() return the lengths of initial sub-bytestrings which
either contain only a given set of bytes, or anything except a given set
of bytes.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Wed, 22 Oct 2014 11:56:53 +0000 (13:56 +0200)]
mem: Implement memrchr()
The memrchr() function, which works like memchr(), but searches from the
back of the region to the front is implemented in the GNU C library, but
isn't standard.
This patch adds an implementation of the function to the mem module, when
it's not available in the system C library.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Wed, 22 Oct 2014 11:56:52 +0000 (13:56 +0200)]
mem: Correct testcases
Currently the 'mem' module testcases use test/run.c even though they don't
rely on access to the module internals. They're also missing an include
of mem.c, which has the effect that on systems with a C library memmem()
implementaiton, only that is tested, not the (re-)implementation in the
mem module itself. This corrects that by moving run.c to api.c/
Additionally, the memmem() testcases don't cover the case where the
"needle" appears multiple times in the "haystack". This patch also adds
such a test.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Wed, 22 Oct 2014 11:56:51 +0000 (13:56 +0200)]
mem: Rename memmem module to mem
Currently the 'memmem' module does nothing but provide an implementation of
the memmem() function if it is missing from the standard C library.
However there are other functions (e.g. memrchr()) also missing from some
C library implementations, so rename the module to mem to allow future
inclusion of other functions.
This also updates the rfc822 module - the only existing user of the
memmem module - to use the new name.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Chris McCormick [Sat, 25 Oct 2014 13:19:15 +0000 (21:19 +0800)]
New page layout, font, background image. Replaced table tags with headers and paragraph tags as appropriate. Redesigned logo. Added stylesheet to specify layout more easily. Meta tag for mobile device friendliness.
Chris McCormick [Wed, 22 Oct 2014 16:00:46 +0000 (00:00 +0800)]
Changed the look of the website. Added a new logo design (source SVG included). Fixed an issue with junkcode prefix not being set (broken links and images on current site). Removed /tmp/ccan in clean as it was preventing 'make webpages' running twice. Brought the HTML closer to standards compliance (doctype, encoding). Added meta tag for mobile device browsers to render nicely.
The literal "1" in "1 << (sizeof(long{, long})*8 - 1)" should be 1L or
1LL, so that the expression has the right type. Otherwise, the shift
is only by 31 bits on x86 (other platforms may behave differently). To
avoid language lawyers shouting UB at me, and since
__builtin_ctz{,l,ll} formally takes unsigned parameters, use UL and
ULL suffixes.
Also, fix a typo (missing parenthesis) in the code for CTZLL causing
the detection of __builtin_ctzll to always fail for the wrong reason.
Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
David Gibson [Thu, 2 Oct 2014 14:14:57 +0000 (00:14 +1000)]
bitmap: Switch bit indices to unsigned long
Currently all bit indices used in the bitmap module are represented as
'int'. These conceptually should be unsigned. In additional limiting
these to ints potentially prevents use of very large bitmaps. So, change
these all to unsigned long.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
David Gibson [Tue, 9 Sep 2014 14:22:52 +0000 (00:22 +1000)]
container_of: Add container_of_or_null()
It's quite common to have a pointer which could be either a pointer to a
structure member, or NULL. This needs special casing with container_of(),
or it will convert NULL into something strange.
This patch adds container_of_or_null(), which will return NULL if passed
(an appropriately typed) NULL, or the containining structure as
container_of() otherwise.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Rusty Russell [Sun, 3 Aug 2014 00:25:07 +0000 (09:55 +0930)]
ccan/io: rewrite.
I found it difficult to use myself, particularly io_duplex().
So this removes that, as well as timers and debug (for the moment).
API changes:
1) An io_plan is passed by pointer, rather than copied on the stack.
3) All io_plans are generated using the struct io_conn.
3) tal is the allocator.
4) A new connection must be set up with a callback, so this is now the
same as one generated from a listener.
5) io_read_partial and io_write_partial take an explicit length.
6) io_always() and io_wait() take an explit in/out arg.
7) io_break() does not return a plan.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
configurator: add BUILTIN_CTZ*, BUILTIN_FFS, and ICCARM_INTRINSICS
Realistically, the ICCARM_INTRINSICS probably won't ever be generated
by configurator, but will show up in manually created or alternately
generated config.h's.
Douglas Bagnall [Wed, 16 Jul 2014 10:19:11 +0000 (22:19 +1200)]
opt/helpers: fix out-of-range check in opt_set_floatval()
opt_set_floatval() uses opt_set_doubleval() to do initial conversion
and bounds checking before casting the result to float. Previously
the out of bounds check compared the original and float values for
equality and declared anything unequal to be out of bounds. While this
trick works well in the orderly integer world, it can backfire with
floating point. For example, 3.1 resolves to the double more precisely
known as 3.100000000000000088817841970012523233890533447265625, while
3.1f resolves to 3.099999904632568359375. These are not equal, though
3.1 is generally regarded as being in bounds for a float. There are
around 8 billion other doubles (i.e. 3.1 +/- a little bit) that map to
the same 3.1f value, of which only one is strictly equal to it.
Why wasn't this discovered by the tests? It turns out that neither
set_floatval nor set_doubleval were tested against non-integral
numbers. This is slightly improved here.
This patch uses the arguably more reasonable definition of bounds that
is found in opt_set_doubleval(): it excludes numbers that would get
rounded to zero or an infinity. One subtlety is that the double
version allows `--foo=INF` for an explicit infinity without overflow.
This is possibly useful, and there is some fiddling to allow this for
floats. Likewise an explicit zero is allowed, as you would expect.
It is perhaps worth noting that the `*f = d` cast/assignment at the
heart of it all can crash and core dump on overflow or underflow if
the floating point exception flags are in an unexpected state.
Signed-off-by: Douglas Bagnall <douglas@halo.gen.nz>
Douglas Bagnall [Fri, 20 Jun 2014 04:38:33 +0000 (16:38 +1200)]
opt: Don't segfault if a string's default is NULL
Instead show '(nil)', like other people do. This is distinguishable
from a similar looking string value, because the latter is shown with
double quotes while NULL's nil has no quotes.
Signed-off-by: Douglas Bagnall <douglas@halo.gen.nz> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>