]> git.ozlabs.org Git - ccan/log
ccan
9 years agotools/ccanlint: slight neatening of license logic.
Rusty Russell [Mon, 30 Mar 2015 06:27:38 +0000 (16:57 +1030)]
tools/ccanlint: slight neatening of license logic.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccanlint - avoid e.g. GPL vs LGPL mismatch in license checking
Peter Barker [Wed, 25 Feb 2015 03:34:14 +0000 (14:34 +1100)]
ccanlint - avoid e.g. GPL vs LGPL mismatch in license checking

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agolist: add list_for_each_rev_safe{,_off} macros
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.

ref: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/65408

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>
9 years agolist: add list_for_each_rev_off macro
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>
9 years agolist: new list_for_each{, _safe}_off_dir_ macros
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>
9 years agolist: list_swap to exchange elements
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>
9 years agolist: list_add_after and list_add_before functions
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>
9 years agostringbuilder: fix ccan/str test dependency.
Rusty Russell [Mon, 30 Mar 2015 05:23:45 +0000 (15:53 +1030)]
stringbuilder: fix ccan/str test dependency.

It's a test dependency, not a core one, so it belongs under "testdepends".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoendian: Fix cpu_to_be64 on big-endian
Jeremy Kerr [Mon, 18 Aug 2014 10:45:39 +0000 (18:45 +0800)]
endian: Fix cpu_to_be64 on big-endian

Commit 9e2c88b5 added an extra return (with an unconditional byteswap)
in cpu_to_be64. This breaks on big-endian, where we shouldn't be
byteswapping.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agostringbuilder: Functions for joining strings.
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.

9 years agoMakefile: add ntdb.
Rusty Russell [Mon, 30 Mar 2015 06:46:08 +0000 (17:16 +1030)]
Makefile: add ntdb.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agontdb: fix up tests.
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>
9 years agontdb: assume HAVE_CCAN in header.
Rusty Russell [Fri, 20 Mar 2015 01:06:28 +0000 (11:36 +1030)]
ntdb: assume HAVE_CCAN in header.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agontdb: fix up _info.
Rusty Russell [Wed, 18 Mar 2015 03:39:33 +0000 (14:09 +1030)]
ntdb: fix up _info.

It was missing dependency information, and a description of ntdb.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agontdb: move python bindings to subdir.
Rusty Russell [Wed, 18 Mar 2015 03:38:50 +0000 (14:08 +1030)]
ntdb: move python bindings to subdir.

The other option would be to require Python.h, which seems overkill.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agontdb: remove config.h
Rusty Russell [Wed, 18 Mar 2015 03:37:48 +0000 (14:07 +1030)]
ntdb: remove config.h

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoMerge branch 'ntdb' of https://github.com/ddiss/ccan into ddiss-ntdb
Rusty Russell [Tue, 17 Mar 2015 01:55:21 +0000 (12:25 +1030)]
Merge branch 'ntdb' of https://github.com/ddiss/ccan into ddiss-ntdb

9 years agoinvbloom: singleton callback for when destroying a singleton, too.
Rusty Russell [Mon, 16 Mar 2015 21:46:28 +0000 (08:16 +1030)]
invbloom: singleton callback for when destroying a singleton, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agontdb: add _info file
David Disseldorp [Mon, 16 Mar 2015 14:15:31 +0000 (15:15 +0100)]
ntdb: add _info file

The Authors entries were added based on source file copyright
statements. Full details can be found via the upstream Samba Git
repository.

Signed-off-by: David Disseldorp <ddiss@suse.de>
9 years agontdb: link to common LGPL-3 license
David Disseldorp [Mon, 16 Mar 2015 13:08:57 +0000 (14:08 +0100)]
ntdb: link to common LGPL-3 license

Signed-off-by: David Disseldorp <ddiss@suse.de>
9 years agontdb: build core components via static Makefile
David Disseldorp [Mon, 16 Mar 2015 11:58:33 +0000 (12:58 +0100)]
ntdb: build core components via static Makefile

As part of Samba, ntdb was built using the Waf build system. As part of
ccan, convert this to a simple Makefile, and add a static config.h.

The Makefile only builds core ntdb components for now - libntdb and
tools.

Signed-off-by: David Disseldorp <ddiss@suse.de>
9 years agontdb: next-generation trivial key-value database
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.

See Samba's Git changelog for authorship details.

Signed-off-by: David Disseldorp <ddiss@suse.de>
9 years agoinvbloom: reduce hash count to 3.
Rusty Russell [Sun, 15 Mar 2015 05:37:26 +0000 (16:07 +1030)]
invbloom: reduce hash count to 3.

Kalle shows the superiority of 3 (as does the paper for > 50 buckets).

https://github.com/kallerosenbaum/bitcoin-iblt/wiki/Diff-count-VS-failure-probability

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoinvbloom: add callback for when an element becomes a singleton.
Rusty Russell [Sun, 15 Mar 2015 05:36:59 +0000 (16:06 +1030)]
invbloom: add callback for when an element becomes a singleton.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoinvbloom: remove unused structure field.
Rusty Russell [Sun, 15 Mar 2015 02:53:36 +0000 (13:23 +1030)]
invbloom: remove unused structure field.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agocdump: ignore __attribute__ (gcc extension).
Rusty Russell [Fri, 14 Nov 2014 02:45:18 +0000 (13:15 +1030)]
cdump: ignore __attribute__ (gcc extension).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agocdump: handle multi-line preprocessor directives.
Rusty Russell [Fri, 14 Nov 2014 02:28:58 +0000 (12:58 +1030)]
cdump: handle multi-line preprocessor directives.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agocdump: add CDUMP() support.
Rusty Russell [Fri, 14 Nov 2014 00:21:29 +0000 (10:51 +1030)]
cdump: add CDUMP() support.

This lets you annotate your headers with notes for cdump.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agocdump: handle array sizes and comments better.
Rusty Russell [Fri, 14 Nov 2014 00:20:01 +0000 (10:50 +1030)]
cdump: handle array sizes and comments better.

We can now parse array sizes properly: comments and extra [] pairs
will no longer confuse us.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoio: fix example in io_plan.h which didn't compile.
Rusty Russell [Tue, 11 Nov 2014 05:40:21 +0000 (16:10 +1030)]
io: fix example in io_plan.h which didn't compile.

This was found because ccanlint now looks for examples here too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agocdump: add useful tool to generate enum name string table.
Rusty Russell [Tue, 11 Nov 2014 05:25:54 +0000 (15:55 +1030)]
cdump: add useful tool to generate enum name string table.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agocdump: handle , at end of enums.
Rusty Russell [Tue, 11 Nov 2014 05:25:54 +0000 (15:55 +1030)]
cdump: handle , at end of enums.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agocdump: new module.
Rusty Russell [Tue, 11 Nov 2014 05:25:48 +0000 (15:55 +1030)]
cdump: new module.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agopushpull: new module.
Rusty Russell [Tue, 11 Nov 2014 05:23:27 +0000 (15:53 +1030)]
pushpull: new module.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccanlint: offer to insert license comments where they're missing.
Rusty Russell [Mon, 10 Nov 2014 04:30:26 +0000 (15:00 +1030)]
ccanlint: offer to insert license comments where they're missing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccanlint: check all headers for examples.
Rusty Russell [Mon, 10 Nov 2014 04:30:06 +0000 (15:00 +1030)]
ccanlint: check all headers for examples.

pushpull module doesn't have examples in pushpull.h.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoinvbloom: new module for IBLTs.
Rusty Russell [Fri, 7 Nov 2014 04:38:03 +0000 (15:08 +1030)]
invbloom: new module for IBLTs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoMakefile-ccan: bytestring now has source.
Rusty Russell [Thu, 30 Oct 2014 22:53:26 +0000 (09:23 +1030)]
Makefile-ccan: bytestring now has source.

Reported-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoio: update for new timer API.
Rusty Russell [Wed, 29 Oct 2014 05:59:56 +0000 (16:29 +1030)]
io: update for new timer API.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agotimer: make timer_del() idempotent, add timer_init().
Rusty Russell [Wed, 29 Oct 2014 05:40:21 +0000 (16:10 +1030)]
timer: make timer_del() idempotent, add timer_init().

This catches duplicate timer_add() calls, as well as meaning we don't
need to track if the timer is active before calling timer_del().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agotimer: change timers_expire() to return a single timer.
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>
9 years agobytestring: Add initializer macro
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>
9 years agobytestring: Use CONST_FUNCTION
David Gibson [Sat, 11 Oct 2014 16:47:28 +0000 (18:47 +0200)]
bytestring: Use CONST_FUNCTION

The bytestring() constructor function satisfies the constraints of
CONST_FUNCTION, so mark it as such.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
9 years agobytestring: Split bytestrings by a string delimiter
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>
9 years agobytestring: Split bytestrings by a set of character delimiters
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>
9 years agobytestring: Split bytestrings by a character delimiter
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>
9 years agobytestring: Implement bytestring_spn() and bytestring_cspn()
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>
9 years agobytestring: Implement bytestring_bytestring()
David Gibson [Sat, 26 Jul 2014 12:51:22 +0000 (22:51 +1000)]
bytestring: Implement bytestring_bytestring()

Add a bytestring_bytestring() function which, in analogy with strstr() and
memmem() finds one bytestring within another.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
9 years agobytestring: Add bytestring_index and bytestring_rindex() functions
David Gibson [Wed, 22 Oct 2014 13:35:26 +0000 (15:35 +0200)]
bytestring: Add bytestring_index and bytestring_rindex() functions

Add bytestring equivalents of the index() and rindex() standard functions
which search for characters/bytes within a bytestring.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
9 years agobytestring: bytestring_starts() and bytestring_ends() functions
David Gibson [Sun, 19 Oct 2014 10:26:29 +0000 (12:26 +0200)]
bytestring: bytestring_starts() and bytestring_ends() functions

This implements bytestring_starts() and bytestring_ends() which
will test if a given bytestring starts or ends with another given
bytestring.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
9 years agobytestring: Add bytestring_slice function
David Gibson [Sun, 19 Oct 2014 10:22:49 +0000 (12:22 +0200)]
bytestring: Add bytestring_slice function

Add a bytestring_slice() function to take a sub(byte)string of a
bytestring.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
9 years agobytestring: Add bytestring_byte() function
David Gibson [Sun, 19 Oct 2014 10:20:14 +0000 (12:20 +0200)]
bytestring: Add bytestring_byte() function

Add a bytestring_byte() function to get a single byte / character
from a bytestring.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
9 years agomem: Implement memrchr()
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>
9 years agomem: Correct testcases
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>
9 years agomem: Rename memmem module to mem
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>
9 years agoSyntax highlighting for module example code using prettify. Note: prettify is introdu...
Chris McCormick [Sat, 25 Oct 2014 10:55:58 +0000 (18:55 +0800)]
Syntax highlighting for module example code using prettify. Note: prettify is introduced with an svn checkout into the web directoy.

9 years agoRemoved more tables where they aren't required. Improved table layout.
Chris McCormick [Sat, 25 Oct 2014 09:43:30 +0000 (17:43 +0800)]
Removed more tables where they aren't required. Improved table layout.

9 years agoNew page layout, font, background image. Replaced table tags with headers and paragra...
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.

9 years agoStandards compliance - XML html doctype, charset meta tag.
Chris McCormick [Sat, 25 Oct 2014 13:12:27 +0000 (21:12 +0800)]
Standards compliance - XML html doctype, charset meta tag.

9 years agoWhen building webpages, skip clean-tree check if WEBDEV flag is set.
Chris McCormick [Sat, 25 Oct 2014 11:12:49 +0000 (19:12 +0800)]
When building webpages, skip clean-tree check if WEBDEV flag is set.

9 years agoFix for broken links/images on website 'junkcode' pages.
Chris McCormick [Sat, 25 Oct 2014 11:02:29 +0000 (19:02 +0800)]
Fix for broken links/images on website 'junkcode' pages.

9 years agoChanged the look of the website. Added a new logo design (source SVG included). Fixed...
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.

9 years agoconfigurator: Fix CTZ detection
Rasmus Villemoes [Tue, 7 Oct 2014 20:19:41 +0000 (22:19 +0200)]
configurator: Fix CTZ detection

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>
9 years agoAdd eratosthenes to Makefile-ccan list.
Rusty Russell [Mon, 13 Oct 2014 02:46:29 +0000 (13:16 +1030)]
Add eratosthenes to Makefile-ccan list.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoeratosthenes: Implementation of the Sieve of Eratosthenes
David Gibson [Thu, 2 Oct 2014 14:15:01 +0000 (00:15 +1000)]
eratosthenes: Implementation of the Sieve of Eratosthenes

This adds a new "eratosthenes" module which implements the standard
Sieve of Eratosthenes algorithm for locating small prime numbers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agobitmap: Implement bitmap_ffs()
David Gibson [Thu, 2 Oct 2014 14:15:00 +0000 (00:15 +1000)]
bitmap: Implement bitmap_ffs()

This adds a bitmap_ffs() function to find the first (by the usual bitmap
bit ordering) 1 bit in a bitmap between two given bits.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agobitmap: Extend allocation functions
David Gibson [Thu, 2 Oct 2014 14:14:59 +0000 (00:14 +1000)]
bitmap: Extend allocation functions

The bitmap module already has a simple allocation helper, which returns
an uninitialized, dynamically allocated bitmap of a given size.

This extends this with bitmap_alloc[01]() which allocate bitmaps and
initialize them to all zero or all one.

It also adds bitmap_realloc[01]() which reallocate an existing bitmap,
preserving existing bits, and setting any new bits to all zero or all one.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agobitmap: Add functions to set/clear ranges of bits
David Gibson [Thu, 2 Oct 2014 14:14:58 +0000 (00:14 +1000)]
bitmap: Add functions to set/clear ranges of bits

Add bitmap_zero_range() and bitmap_fill_range() functions which will set
a contiguous range of bits in the bitmap to 0 or 1.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agobitmap: Switch bit indices to unsigned long
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>
9 years agolstack: Linked list stack implementation
David Gibson [Tue, 9 Sep 2014 14:22:54 +0000 (00:22 +1000)]
lstack: Linked list stack implementation

This new module provides a simple stack implementation as a singly
linked list.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agolqueue: Linked list queue implementation
David Gibson [Tue, 9 Sep 2014 14:22:53 +0000 (00:22 +1000)]
lqueue: Linked list queue implementation

This new module provides a simple queue implementation as a singly
linked (circular) list.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agocontainer_of: Add container_of_or_null()
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>
9 years agoio: use normal linked lists.
Rusty Russell [Wed, 27 Aug 2014 06:57:37 +0000 (16:27 +0930)]
io: use normal linked lists.

There seems to be a bug with the overloaded single-linked list.
Rewrite.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agolist_del_init/list_node_init: for multiple list_del() calls.
Rusty Russell [Wed, 27 Aug 2014 06:27:24 +0000 (15:57 +0930)]
list_del_init/list_node_init: for multiple list_del() calls.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agotal/str: use tal/grab_file not grab_file in example.
Rusty Russell [Mon, 18 Aug 2014 17:07:19 +0000 (02:37 +0930)]
tal/str: use tal/grab_file not grab_file in example.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agocharset: make example use tal/grab_file instead of grab_file.
Rusty Russell [Mon, 18 Aug 2014 17:03:03 +0000 (02:33 +0930)]
charset: make example use tal/grab_file instead of grab_file.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccan_tokenizer: remove warnings with gcc
Rusty Russell [Mon, 18 Aug 2014 16:55:04 +0000 (02:25 +0930)]
ccan_tokenizer: remove warnings with gcc

/home/rusty/devel/cvs/ccan/ccan/ccan_tokenizer/test/run.c:898:66: warning: initialization discards ‘const’ qualifier from pointer target type [enabled by default]
 #define T(txt, ...) {txt, sizeof(txt)-1, array_count_pair(struct token, __VA_ARGS__)}
...

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccan_tokenizer: switch example from grab_file to ccan/grab_file.
Rusty Russell [Mon, 18 Aug 2014 16:43:46 +0000 (02:13 +0930)]
ccan_tokenizer: switch example from grab_file to ccan/grab_file.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoendian: Wrap arguments in braces to silence warnings
Joel Stanley [Thu, 14 Aug 2014 03:37:53 +0000 (13:37 +1000)]
endian: Wrap arguments in braces to silence warnings

When using the endian swapping marcos with multiple arguments that are
or'd together:

  CPU_TO_BE64(THIS_THING | THAT_THING)

gcc will emit this warning:

  warning: suggest parentheses around arithmetic in operand
  of ‘|’ [-Wparentheses]

Wrap the arugments in braces to avoid this.

Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agodarray: Add darray_remove()
Andy Grover [Tue, 12 Aug 2014 17:49:13 +0000 (10:49 -0700)]
darray: Add darray_remove()

It is useful to be able to remove elements from other than the end, even
if it is slow.

Signed-off-by: Andy Grover <agrover@redhat.com>
9 years agoio: always make fds O_NONBLOCK.
Rusty Russell [Fri, 8 Aug 2014 05:10:47 +0000 (14:40 +0930)]
io: always make fds O_NONBLOCK.

Debugging an issue where pettycoin would become unresponsive, I discovered
this:

poll([{fd=5, events=POLLIN}, {fd=19, events=POLLIN}, {fd=6, events=POLLIN}, {fd=15, events=POLLIN}, {fd=8, events=POLLIN}, {fd=-11}, {fd=7, events=POLL
OUT}], 7, -1) = 1 ([{fd=7, revents=POLLOUT}]) <0.000014>
write(7, "\224]\4\0\4\0\0\0\200\203\16\234\v\262\276\321h\357\217Y\0\204\21\31\253\304#U\0206}\20"..., 286100) = 159280 <98.894019>

Despite poll saying the (TCP socket) fd was ready, the write took 98 seconds!
The results were far more reasonable with O_NONBLOCK:

write(9, "%\247l0\337^\216\24\323\2705\203Y\340h\2767/bM\373?dM\254\22g\310\v\0\0\0"..., 206460) = 40544 <0.000052>

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoio: don't do wakeup immediately.
Rusty Russell [Fri, 8 Aug 2014 03:25:12 +0000 (12:55 +0930)]
io: don't do wakeup immediately.

ccan/io users don't expect to deal with callbacks inside each other; we should
just mark woken connections as if they were io_always.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccan/io: use shutdown() before close.
Rusty Russell [Tue, 5 Aug 2014 11:07:44 +0000 (20:37 +0930)]
ccan/io: use shutdown() before close.

During a debugging session, I wondered why poll() wasn't exiting
when I killed a (local) peer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccan/io: add io_out_wait() and io_out_always().
Rusty Russell [Mon, 4 Aug 2014 08:17:21 +0000 (17:47 +0930)]
ccan/io: add io_out_wait() and io_out_always().

This specificity is required, for example, when doing:

return io_duplex(conn, io_read(...), io_always(...));

The workaround suggested doesn't work, because io_duplex_prepare()
asserts() if the plans aren't UNSET to start.  And pettycoin needs this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccan/io: io_halfclose.
Rusty Russell [Mon, 4 Aug 2014 08:16:21 +0000 (17:46 +0930)]
ccan/io: io_halfclose.

Helper for a common case.  Replace all but 1 in tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccan/io: keep more io_plan details internal.
Rusty Russell [Mon, 4 Aug 2014 08:15:21 +0000 (17:45 +0930)]
ccan/io: keep more io_plan details internal.

To write a normal helper you only need access to the args, so only
expose that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccan/io: implement debug.
Rusty Russell [Mon, 4 Aug 2014 08:14:21 +0000 (17:44 +0930)]
ccan/io: implement debug.

Now a simple flag, with an external toggle (no compile time DEBUG
define required).  But it's completely synchronous.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccan/io: implement timeouts.
Rusty Russell [Mon, 4 Aug 2014 08:13:21 +0000 (17:43 +0930)]
ccan/io: implement timeouts.

We do this by the simplest method: return from io_loop() and let the caller
sort them out.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccan/io: duplex support.
Rusty Russell [Mon, 4 Aug 2014 08:12:21 +0000 (17:42 +0930)]
ccan/io: duplex support.

This is actually pretty simple now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccan/io: eliminate dir argument from io_wait and io_always.
Rusty Russell [Mon, 4 Aug 2014 08:11:21 +0000 (17:41 +0930)]
ccan/io: eliminate dir argument from io_wait and io_always.

We can use either empty slot for this, so figure it out internally.

This could cause problems if you want to use it with io_duplex, so
document that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoccan/io: rewrite.
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>
9 years agoccan/io: fix io_connect.
Rusty Russell [Sun, 3 Aug 2014 00:25:01 +0000 (09:55 +0930)]
ccan/io: fix io_connect.

getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len) gives err == ECONNREFUSED
when connection is refused.  Handle this (and other error cases).

And we need F_SETFL not F_SETFD to restore blocking on the socket!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agotools/ccanlint: add global .valgrind_suppressions file.
Rusty Russell [Fri, 1 Aug 2014 07:06:39 +0000 (16:36 +0930)]
tools/ccanlint: add global .valgrind_suppressions file.

Seems like my local Ubuntu install is giving bogus warnings.  Allow
local valgrind overrides.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoconfigurator: add BUILTIN_CTZ*, BUILTIN_FFS, and ICCARM_INTRINSICS
Cody P Schafer [Mon, 28 Jul 2014 02:28:53 +0000 (22:28 -0400)]
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.

Signed-off-by: Cody P Schafer <dev@codyps.com>
9 years agoopt/helpers: fix out-of-range check in opt_set_floatval()
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>
9 years agonet: use freeaddrinfo() in _info example.
Rusty Russell [Wed, 23 Jul 2014 23:50:21 +0000 (09:20 +0930)]
net: use freeaddrinfo() in _info example.

In fact, almost everyone will want to do this, so include the required
headers in net.h.  This makes usage simpler.

Reported-by: Jeremy Visser <jeremy@visser.name>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agoio: fix io_connect().
Rusty Russell [Thu, 17 Jul 2014 03:39:55 +0000 (13:09 +0930)]
io: fix io_connect().

How embarrassing: we weren't actually doing a non-blocking connect because
I was using F_SETFD instead of F_SETFL...

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agostructeq: new module.
Rusty Russell [Wed, 25 Jun 2014 02:28:57 +0000 (11:58 +0930)]
structeq: new module.

World's most trivial module, but I want it for pettycoin.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agotal/str: fix error when strreg regex looks for literal slashes.
Rusty Russell [Mon, 23 Jun 2014 06:36:19 +0000 (16:06 +0930)]
tal/str: fix error when strreg regex looks for literal slashes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years agotime: update for new configurator.
Rusty Russell [Sun, 22 Jun 2014 23:49:08 +0000 (09:19 +0930)]
time: update for new configurator.

HAVE_CLOCK_GETTIME_IN_LIBRT now implies HAVE_CLOCK_GETTIME.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>