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>
which is an occasionally seen idiom. It allows, e.g., people who like
quiet to use `alias foo='foo -q'`, while letting them get back to
normal and verbose modes with various amounts of '-v's.
Signed-off-by: Douglas Bagnall <douglas@halo.gen.nz> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Douglas Bagnall [Fri, 20 Jun 2014 02:33:53 +0000 (14:33 +1200)]
opt: always initialise values in set_llong_with_suffix()
The helper API functions based on set_llong_with_suffix() left the
value uninitialised in the case of an empty string argument. This is
quite unlikely to have caused problem in practice, as most values will
have already been set to a default and the non-NULL error message
should have triggered an early exit or some other emergency action.
Nevertheless, it caused a compiler warning on some minor version of
GCC 4.8 which I no longer seem to have, and the complaint seemed
reasonable at the time.
If an empty string (or any other non-numeric value) is passed to
strtoll(), the result is zero. As far as I know, the strtoll() call is
only short-circuited here to form a more specific error message, not
because there is a good reason for the empty string to be a special
non-initialising case. So let's set it to zero.
Signed-off-by: Douglas Bagnall <douglas@halo.gen.nz> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cody P Schafer [Sat, 21 Jun 2014 00:46:01 +0000 (20:46 -0400)]
compiler: avoid barfing when config.h & the current -std= mode mismatch
Add a bunch of __ for all the attribute members.
Lets us keep working even if configurator is called with different
CFLAGS than the build of a file which includes compiler.h
Idealy, we (people using ccan) wouldn't let this happen, however I don't
see any reason /not/ to avoid build breakage in the above case.
Long term, it might make sense to plug some logic into configurator's
config.h (or a cc wrapper, so something else) to warn when the current
flags don't look the same as the ones used to generate config.h
CC: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Cody P Schafer <dev@codyps.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
David Gibson [Sun, 15 Jun 2014 14:09:09 +0000 (00:09 +1000)]
ccan: Correct some poor conventions in _info includes
There are a couple of small problems with the includes used in most of
ccan's _info files.
* _info routinely uses printf(), and so should include <stdio.h>, but
only some of them do. We get away with it, because they do include
<string.h>, which apparently includes <stdio.h> indirectly, but we should
be explicit about it.
* Most _info files were including config.h after the system headers.
That _seems_ sensible, but actually causes problems. Because config.h
defines _GNU_SOURCE it can change the behaviour of the system headers.
More specifically it can make them behave differently to how the individual
module headers (which have included config.h) expects them to behave.
This patch adjusts all the existing _info files and, more importantly,
the template constructed by ccanlint.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
David Gibson [Sat, 14 Jun 2014 16:11:25 +0000 (02:11 +1000)]
memmem: Trivial module to provide memmem() function
glibc includes a memmem() function which, by analogy with strstr()
searches for a byte sequence within a larger byte sequence. The function
isn't standard, however, so other C libraries may not include it.
This adds a trivial module providing the memmem() function, if the C
library doesn't already do so.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
David Gibson [Wed, 4 Jun 2014 14:41:51 +0000 (00:41 +1000)]
jacobson_karels: Add missing inline keyword
Forgot the 'inline' in 'static inline' in the functions defined in the
header, which means that lots of warnings will be generated, if you include
the header but don't use the functions.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>