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>
David Gibson [Mon, 2 Jun 2014 12:37:28 +0000 (22:37 +1000)]
minmax: New module, safe min and max macros
Add a 'minmax' module with typesafe macros to compute minimum, maximum and
clamping. Inspired by the versions used in the Linux kernel, but using
a different implementation based on __builtin_types_compatible_p() and the
build_assert module.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Rusty Russell [Tue, 27 May 2014 03:47:29 +0000 (13:17 +0930)]
net: don't return still-connecting fd.
If one connect failed, we'd return the other one without
waiting for the connect to complete. This resulted in
read() returning 0, which was really weird.
The downside: the poll doesn't seem to time out when the
connect times out (Linux 3.13 x86-64).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Emilio G. Cota [Mon, 10 Mar 2014 15:04:50 +0000 (11:04 -0400)]
bitmap: use unsigned int for iterating over bitmap words
Bitmap words (e.g. resulting from BITMAP_{N,HEAD}WORDS) are of
unsigned type.
Use "unsigned int" to iterate over bitmap words to avoid comparisons
between signed and unsigned expressions. GCC otherwise warns about
these when -Wsign-compare is enabled.
Rusty Russell [Sun, 2 Mar 2014 06:05:10 +0000 (16:35 +1030)]
io: call finish function after fd is actually closed.
This turns out to be the right sequence for pettycoin, which
wants to reap the child in the finish routine. From that sample
size of 1, this is clearly the Right Thing!
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Rusty Russell [Fri, 28 Feb 2014 01:42:11 +0000 (12:12 +1030)]
Enhance CCAN_LIST_DEBUG to report original caller
Simpler reimplementation of SS's patch; just plumb file and line through
inline functions in header. We add a new check, which actually tests
these, and fix _info which missed ccan/check_type as a dependency.
Based-on-the-true-story-by: Stewart Smith <stewart@linux.vnet.ibm.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Rusty Russell [Mon, 24 Feb 2014 02:55:19 +0000 (13:25 +1030)]
opt: relicense to GPLv2+ (from GPLv3+)
Acked by contributors:
Luke-Jr <luke@dashjr.org>:
I don't have any objections
Douglas Bagnall <douglas@halo.gen.nz>:
Fine by me.
Joel Stanley <joel@jms.id.au>:
Fine with me.
Brad Hards <bradh@frogmouth.net>:
Ack.
No response from Joey (trivial warning patch) or Andreas Schlick (one
trivial patch, but he also wrote opt_free() (which was a 2 line function).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>