ccan
3 years agointmap: clean up iterators.
Rusty Russell [Fri, 13 Jan 2017 02:55:14 +0000 (13:25 +1030)]
intmap: clean up iterators.

By returning the value, we have a nice sentinal and we save a second lookup
if they want it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agointmap: new module.
Rusty Russell [Wed, 11 Jan 2017 03:25:54 +0000 (13:55 +1030)]
intmap: new module.

Critbit tree to map ints/uints to pointers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoio: make io_close_taken_fd() unset nonblocking on the fd.
Rusty Russell [Mon, 9 Jan 2017 23:16:26 +0000 (09:46 +1030)]
io: make io_close_taken_fd() unset nonblocking on the fd.

This is what users want, and expect: as demonstrated by the test failure
when not under valgrind!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoio: handle errors on listening file descriptors.
Rusty Russell [Mon, 9 Jan 2017 02:46:32 +0000 (13:16 +1030)]
io: handle errors on listening file descriptors.

While investigating the previous patch, a bug caused poll to return
POLLHUP on the listening socket, which caused us to spin.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoio: io_close_taken_fd to steal fd from conn.
Rusty Russell [Mon, 9 Jan 2017 02:08:06 +0000 (12:38 +1030)]
io: io_close_taken_fd to steal fd from conn.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoio: don't try to close() connection twice, remove shutdown logic.
Rusty Russell [Mon, 9 Jan 2017 02:03:44 +0000 (12:33 +1030)]
io: don't try to close() connection twice, remove shutdown logic.

We were closing before calling del_fd, which also closed.

The shutdown() logic applies when a child and parent are using the
*same* socket fd to communicate to each other.  That's really unusual
(who would you connect to?), and should probably be done by the user.

Generally, you'd use socketpair() for this child-parent case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoio: update documentation for io_close.
Rusty Russell [Mon, 9 Jan 2017 00:15:31 +0000 (10:45 +1030)]
io: update documentation for io_close.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agostr: make sure STR_MAX_CHARS gives a constant expression.
Rusty Russell [Sat, 7 Jan 2017 04:19:53 +0000 (14:49 +1030)]
str: make sure STR_MAX_CHARS gives a constant expression.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agotal/autoptr: new module.
Rusty Russell [Thu, 29 Dec 2016 04:34:30 +0000 (15:04 +1030)]
tal/autoptr: new module.

Helps with the common case of wanting to NULL out a pointer when the object
freed.  We could also track it if resized, but that's TODO.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agotal: support destructors with an extra argument.
Rusty Russell [Thu, 29 Dec 2016 04:33:19 +0000 (15:03 +1030)]
tal: support destructors with an extra argument.

There are several times I've wanted an extra arg to the destructor, and had
to embed it in the thing destroyed.  It's more efficient to put it into
tal itself (since it allocates space anyway), but we make it conditional
on a flag to avoid bloating every destructor.

The infrastructure makes it easier to add an extra arg to the general
notifiers later if we want.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoio: allow freeing of io_conn at any time.
Rusty Russell [Thu, 29 Dec 2016 04:31:32 +0000 (15:01 +1030)]
io: allow freeing of io_conn at any time.

io_close() currently marks the io_conn for freeing, but doesn't
actually do it.  This is a problem for tal() users, because we can't
just call it in the parent's constructor.

Make io_close() just tal_free() + return &io_conn_freed (a magic
io_plan pointer).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoio: remove io_debug support.
Rusty Russell [Thu, 29 Dec 2016 04:29:29 +0000 (14:59 +1030)]
io: remove io_debug support.

It seemed like a good idea, but it complicates things and I never used
it (since I never really trusted that the alternate paths would be
equivalent).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agotal: save and restore errno across all notifiers.
Rusty Russell [Thu, 29 Dec 2016 04:28:42 +0000 (14:58 +1030)]
tal: save and restore errno across all notifiers.

So the errno when you call tal_free() is handed to all the notifiers,
independent of what the others do.

This makes sense, but also helps for the upcoming ccan/io change.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoccanlint: Move ccanlint test options from _info comments to code
David Gibson [Sat, 24 Dec 2016 12:58:19 +0000 (23:58 +1100)]
ccanlint: Move ccanlint test options from _info comments to code

Currently, _info files can specify options, or note expected failures, for
ccanlint checks in the _info file with specially structured comments. That
differs from most other things ccanlint gets from _info, where it instead
executes the info file with certain parameters.

This changes ccanlint and existing _info files to use the normal method for
the ccanlint test options as well.  This also has the advantage that an
info file can alter its test options based on things from config.h - in
some cases whether a test can work or not might depend on various things.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoMakefile: Make module checks depend on info file
David Gibson [Sat, 24 Dec 2016 12:46:29 +0000 (23:46 +1100)]
Makefile: Make module checks depend on info file

Changing the _info file can change how ccanlint assesses the module.
Therefore, if the _info file changes, we should re-run ccanlint module
tests with make check.  We didn't previously have a dependency for that,
though, so this adds it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoio/fdpass: new module for async fd passing.
Rusty Russell [Fri, 23 Dec 2016 00:40:57 +0000 (11:10 +1030)]
io/fdpass: new module for async fd passing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agobase64: correct linkage of base64_maps_rfc4648
Peter Barker [Thu, 18 Feb 2016 05:38:54 +0000 (16:38 +1100)]
base64: correct linkage of base64_maps_rfc4648

Two copies of this map meant only the tests would ever work.

3 years agogenerator: Rewrite to use coroutine module
David Gibson [Mon, 12 Dec 2016 09:58:35 +0000 (20:58 +1100)]
generator: Rewrite to use coroutine module

Use the new coroutine module to abstract away our dependence on
ucontext.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agocoroutine: New module
David Gibson [Wed, 6 Jul 2016 11:31:03 +0000 (21:31 +1000)]
coroutine: New module

This is essentially a wrapper around ucontext.h, but the idea is that
alternative back end implementations could be used in future.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agofdpass: new module.
Rusty Russell [Wed, 7 Dec 2016 04:55:10 +0000 (15:25 +1030)]
fdpass: new module.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoshachain: allow overriding of number of bits, add cmdline tool.
Rusty Russell [Mon, 5 Dec 2016 05:48:20 +0000 (16:18 +1030)]
shachain: allow overriding of number of bits, add cmdline tool.

lightning uses 48 bits, so this provides a quick utility for our test
vectors, and provides a nice example.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agohkdf_sha256: okm is a void *.
Rusty Russell [Mon, 5 Dec 2016 05:25:08 +0000 (15:55 +1030)]
hkdf_sha256: okm is a void *.

Making arbitrary bytes a uchar* is always a bit nasty for the caller.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoMakefile: Remove testdepends from make check dependencies
David Gibson [Thu, 1 Dec 2016 11:43:20 +0000 (22:43 +1100)]
Makefile: Remove testdepends from make check dependencies

The new Makefile system, via the helper script in tools/gen_deps.sh, when
generating the targets to test a module, inserts dependencies meaning it
must first check modules this one depends on, whether via 'depends' or
'testdepends' in _info.

Although it seems logical, including 'testdepends' is actually incorrect.
If ccan/a testepends on ccan/b then ccan/b must be *built* in order to test
ccan/a, but it doesn't need to be tested.  testepends are explicitly
permitted to contain loops - it's quite common for two complementary
modules to be used to test each other.  This is one of the reasons
testdepends exists separate from depends.

So, remove testdepends from the generated check dependencies, removing the
circular dependency that Make complains about.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agocrypto/hkdf_sha256: new module.
Rusty Russell [Wed, 30 Nov 2016 03:54:37 +0000 (14:24 +1030)]
crypto/hkdf_sha256: new module.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agocrypto/hmac_sha256: add partial progress functions.
Rusty Russell [Wed, 30 Nov 2016 03:54:23 +0000 (14:24 +1030)]
crypto/hmac_sha256: add partial progress functions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agocrypto/hmac_sha256: new module.
Rusty Russell [Wed, 30 Nov 2016 03:54:08 +0000 (14:24 +1030)]
crypto/hmac_sha256: new module.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoedit_distance: Rename ED_STACK_ELEMS ED_STACK_DIST_VALS
Kevin Locke [Sun, 27 Nov 2016 00:44:01 +0000 (17:44 -0700)]
edit_distance: Rename ED_STACK_ELEMS ED_STACK_DIST_VALS

The previous name was misleading, since it does not define the number of
elements (ed_elem) on the stack, but rather the number of distance
values (ed_dist).  Rename to make this more clear and add more
documentation about what it does and how best to define it.

Note:  This is an API change for custom-compiled versions, but since the
module has only been included for a couple days I don't think it's worth
a back-compat #ifdef at this point.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
3 years ago.travis.yml: Enable C99 mode for older gcc versions
David Gibson [Wed, 23 Nov 2016 12:12:59 +0000 (23:12 +1100)]
.travis.yml: Enable C99 mode for older gcc versions

Currently Travis builds fail on the edit_distance module, because that
module uses C99 extensions, which aren't enabled by default on the
Ubuntu Precise compiler version.  Force it to allow these, by adding the
-std=gnu99 option to the compiler.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoedit_distance: calculate edit distance between strings
Kevin Locke [Sat, 19 Nov 2016 04:19:25 +0000 (21:19 -0700)]
edit_distance: calculate edit distance between strings

This commit creates the edit_distance module for calculating various
edit distance measures.  The edit distance quantifies the similarity
between two strings based on the number of modifications necessary to
turn one string into the other.  There are several edit distance
measures which differ in the operations which are permitted and the
cost (aka weight) of the operations.  This module provides functions
for calculating the Longest Common Subsequence (LCS), Levenshtein, and
Damerau-Levenshtein (restricted and unrestricted) distances.  Weighted
versions of these functions can be created by defining cost functions
as preprocessor macros when compiling this module.  Distances over
other array types (e.g. wide strings, integers, structs) can be
accomplished by defining the element type and equality test macros.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoMakefile: Remove unused test targets
David Gibson [Tue, 22 Nov 2016 22:50:48 +0000 (09:50 +1100)]
Makefile: Remove unused test targets

The Makefile provides for "fast" and "full" variants of make check.
However, nothing seems to use or implement the "full" variant at all.
Further, the %.check and %.fastcheck targets are not actually used, with
other targets instead using the actual .ok tag file as the target.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoweb: fix for PHP7.
Rusty Russell [Tue, 22 Nov 2016 00:47:09 +0000 (11:17 +1030)]
web: fix for PHP7.

split() was deprecated, is now removed. explode() is the new hotness.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoMakefile-web: make it usable with "make -f Makefile-web".
Rusty Russell [Tue, 22 Nov 2016 00:20:46 +0000 (10:50 +1030)]
Makefile-web: make it usable with "make -f Makefile-web".

Particularly since it's used by a gitolite hook on ozlabs.org to update
the webpages.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agocppmagic: Tweak testcase to work on older clang versions
David Gibson [Mon, 21 Nov 2016 14:05:37 +0000 (01:05 +1100)]
cppmagic: Tweak testcase to work on older clang versions

clang version 3.4, for whatever reason, expands a few of the testcases
in cppmagic with slightly different whitespace from what we expect.  Since
this was changed in later clang versions, it was probably a compiler bug,
but it turns out an extra space in the testcase can make it pass on clang
3.4 as well.  This means we finally have clang builds working in Travis.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agotime: Change TIME_HAVE_MONOTONIC to be 0/1 rather than defined/undefined
David Gibson [Mon, 21 Nov 2016 13:52:53 +0000 (00:52 +1100)]
time: Change TIME_HAVE_MONOTONIC to be 0/1 rather than defined/undefined

Generally, ccan config variables are always defined as either 0 or 1 and
are tested with #if.  That's instead of being being either defined or
undefined and tested with #ifdef.

TIME_HAVE_MONOTONIC breaks that convention.  This can cause warnings in
ccan/timer which uses it assuming the 0/1 convention.  Change it to remove
that warning.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoccanlint: Remove unused variable
David Gibson [Mon, 21 Nov 2016 13:47:37 +0000 (00:47 +1100)]
ccanlint: Remove unused variable

Remove a warning caused by the unused 'explain' variable in
headers_idempotent.c.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoMakefile: Remove generator modules from the exclude list
David Gibson [Mon, 21 Nov 2016 12:45:50 +0000 (23:45 +1100)]
Makefile: Remove generator modules from the exclude list

There's no real reason to exclude 'generator' from the build or check
targets.  Add it back in.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years ago.travis.yml: Remove external libraries
David Gibson [Mon, 21 Nov 2016 12:35:22 +0000 (23:35 +1100)]
.travis.yml: Remove external libraries

The new makefile excludes all modules with external library dependencies
from the usual make check, meaning the libraries are not needed for the
Travis build.

Although it would be nice to include these modules, there are a bunch of
problems with sorting out a correct environment for them.  For now, just
leave them out.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoMerge Makefile rewrite into master
David Gibson [Mon, 21 Nov 2016 12:24:36 +0000 (23:24 +1100)]
Merge Makefile rewrite into master

# Conflicts:
# .travis.yml
# Makefile
# Makefile-ccan

3 years agowwviaudio: Mark examples as not compiling
David Gibson [Thu, 17 Nov 2016 12:24:31 +0000 (23:24 +1100)]
wwviaudio: Mark examples as not compiling

The example code in wwviaudio doesn't compile as is.  Mark it as an
expected failure for ccanlint.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agowwviaudio: Use correct C99 format specifiers for uint64_t
David Gibson [Thu, 17 Nov 2016 12:23:34 +0000 (23:23 +1100)]
wwviaudio: Use correct C99 format specifiers for uint64_t

This fixes a warning.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoClearer output from make check in Travis
David Gibson [Wed, 2 Nov 2016 22:35:31 +0000 (09:35 +1100)]
Clearer output from make check in Travis

This removes the parallel make (-j) option when running make check under
Travis CI.  This will slow down the build somewhat, but makes it easier to
match errors to the modules which caused them.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoccanlint: Alter meaning of --summary option
David Gibson [Wed, 2 Nov 2016 22:34:23 +0000 (09:34 +1100)]
ccanlint: Alter meaning of --summary option

--summary (used by make check) causes ccanlint to only ever print a
one-line summary of the results.  When one of the tests fails, this isn't
very useful, because it doesn't say why it failed, or even which test
failed.  This is particularly frustrating for failures in Travis CI builds
where it's not always straightforward to reproduce a similar enough build
environment to check the failure manually for a particular module.

--summary does have one purpose which is vital for make check, though: it
suppresses any attempt to interactively correct / improve the module
printing only results.

This changes --summary to only have the second effect, not the first.  This
won't change the output in the case of passing modules, but will give more
useful information in the case of failing modules.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agopipecmd: fix -Wextra complaint about empty body.
Rusty Russell [Sun, 6 Nov 2016 06:44:53 +0000 (17:14 +1030)]
pipecmd: fix -Wextra complaint about empty body.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoccanlint: remove empty statement warnings.
Rusty Russell [Sun, 6 Nov 2016 06:43:53 +0000 (17:13 +1030)]
ccanlint: remove empty statement warnings.

Since doesnt_matter() expands to nothing, GCC -Wextra suggests { }.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoccanlint: check unused result.
Rusty Russell [Sun, 6 Nov 2016 06:42:53 +0000 (17:12 +1030)]
ccanlint: check unused result.

GCC with -O gives an error here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoccanlint: mark unused parameters.
Rusty Russell [Sun, 6 Nov 2016 06:41:53 +0000 (17:11 +1030)]
ccanlint: mark unused parameters.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agohtable: another unused parameter in tests.
Rusty Russell [Sun, 6 Nov 2016 06:40:53 +0000 (17:10 +1030)]
htable: another unused parameter in tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoccanlint: fix usage of unused main parameters in other cases where we add main()
Rusty Russell [Sun, 6 Nov 2016 06:33:19 +0000 (17:03 +1030)]
ccanlint: fix usage of unused main parameters in other cases where we add main()

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agocontainer_of: Make example compile cleanly with -Wunused
Rusty Russell [Sun, 6 Nov 2016 04:38:17 +0000 (15:08 +1030)]
container_of: Make example compile cleanly with -Wunused

Make register_timer "use" my_timer_callback and its own args.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoasort, cdump, htable, list, noerr, strmap, tal/link: fix sign warnings in examples.
Rusty Russell [Sun, 6 Nov 2016 04:37:51 +0000 (15:07 +1030)]
asort, cdump, htable, list, noerr, strmap, tal/link: fix sign warnings in examples.

Many are because argc is 'int' not 'unsigned', others just laziness.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agotools/ccanlint: add args to main.
Rusty Russell [Sun, 6 Nov 2016 04:35:17 +0000 (15:05 +1030)]
tools/ccanlint: add args to main.

This allows examples to refer to them, but we cast them to void at the
end to avoid -Wunused warnings.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoMark unused arguments in many modules.
Rusty Russell [Sun, 6 Nov 2016 04:34:17 +0000 (15:04 +1030)]
Mark unused arguments in many modules.

Either with UNNEEDED (if the module already used ccan/compiler) or
with (void) casting.

The only other change is in ccan/list/test/run-CCAN_LIST_DEBUG.c, because
the linenumbers change and thus it needs updating.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agocast, str, take, tal/grabfile, tal/str, typesafe_cb: use argc
Rusty Russell [Fri, 4 Nov 2016 20:56:47 +0000 (07:26 +1030)]
cast, str, take, tal/grabfile, tal/str, typesafe_cb: use argc

This avoids the warning about it being unused with -Wunused.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoRemove unused main() args in many modules.
Rusty Russell [Fri, 4 Nov 2016 20:55:47 +0000 (07:25 +1030)]
Remove unused main() args in many modules.

This makes us closer to compiling cleanly with -Wunused (as used by -Wextra).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agotal: remove ccan/talloc from example.
Rusty Russell [Fri, 4 Nov 2016 20:54:47 +0000 (07:24 +1030)]
tal: remove ccan/talloc from example.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agotools/ccanlint: compile cleanly with -Wextra.
Rusty Russell [Fri, 4 Nov 2016 20:53:47 +0000 (07:23 +1030)]
tools/ccanlint: compile cleanly with -Wextra.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agocpuid: increment over size of cpu array, not just first one.
Rusty Russell [Fri, 4 Nov 2016 10:44:21 +0000 (21:14 +1030)]
cpuid: increment over size of cpu array, not just first one.

Found by PCS Suite.

Reported-by: Jon Griffiths
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Ahmed Samy <f.fallen45@gmail.com>
3 years agoaga,agar: Negative weight cycle testcase
David Gibson [Thu, 3 Nov 2016 10:49:55 +0000 (21:49 +1100)]
aga,agar: Negative weight cycle testcase

Adds a new test graph which includes a negative weight cycle.  This means
that shortest paths are not well defined, and both Dijkstra's algorithm and
the Bellman-Ford algorithm (which can handle some negative edge weights)
will fail.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoaga,agar: The Bellman-Ford algorithm
David Gibson [Sat, 11 Jun 2016 08:30:08 +0000 (18:30 +1000)]
aga,agar: The Bellman-Ford algorithm

This adds the Bellman-Ford single-source shortest path algorithm to
the aga and agar modules.  The Bellman-Ford algorithm is (usually)
slower than Dijkstra's algorithm, but unlike Dijkstra's is able to
cope with negative edge costs, unless they form a negative cost cycle.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoaga,agar: Rename aga_dijkstra_all_paths()
David Gibson [Sat, 11 Jun 2016 03:10:58 +0000 (13:10 +1000)]
aga,agar: Rename aga_dijkstra_all_paths()

aga_dijkstra_all_paths() runs Dijkstra's algorithm to completion (as
opposed to aga_dijkstra_path(), which operates lazily).  In effect this
computes the shortest path to all (reachable) nodes from the start node.

So, in this context the name makes sense.  But for an analogous function
for future algorithms (e.g. Bellman-Ford), the name doesn't make sense.

So, in the interests of consistency with those future extensions, change
the name of this to aga_dijkstra_complete().

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agotools: set, don't increment bool.
Rusty Russell [Fri, 4 Nov 2016 10:36:55 +0000 (21:06 +1030)]
tools: set, don't increment bool.

Not really a bug, but stylistically questionable and makes PCS Suite
complain.

Reported-by: Jon Griffiths
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years ago.travis.yml: Correct additional packages list
David Gibson [Wed, 2 Nov 2016 06:00:00 +0000 (17:00 +1100)]
.travis.yml: Correct additional packages list

The list of additional packages in our .travis.yml (mostly libraries needed
for specific modules) was incorrectly formatted.  So travis was attempting
to install the "libjudy-dev libvorbis-dev libportaudio-dev libtalloc-dev"
packagde (spaces included) which obviously didn't work.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoio: update to use time_mono() for timers.
Rusty Russell [Mon, 31 Oct 2016 00:54:28 +0000 (11:24 +1030)]
io: update to use time_mono() for timers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agotimer: change to use time_mono (api break!)
Rusty Russell [Mon, 31 Oct 2016 00:45:33 +0000 (11:15 +1030)]
timer: change to use time_mono (api break!)

Remove timer_add() in favor of explicit timer_addrel and timer_addmono.

Someone hit a real-life case where time went backwards, and we asserted.
The correct fix is to use time_mono() where available, but as all known
users actually want a relative timeout, have a helper for that case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agotime: make timemono a first-class citizen.
Rusty Russell [Mon, 31 Oct 2016 00:32:32 +0000 (11:02 +1030)]
time: make timemono a first-class citizen.

Include assert checks, implement timemono_eq().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agotime: test/run-monotonic backwards timemono_between fix.
Rusty Russell [Mon, 31 Oct 2016 00:30:57 +0000 (11:00 +1030)]
time: test/run-monotonic backwards timemono_between fix.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agotime: timemono_add.
Rusty Russell [Sun, 30 Oct 2016 05:47:55 +0000 (16:17 +1030)]
time: timemono_add.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agojmap: fix tools/speed
Rusty Russell [Fri, 28 Oct 2016 23:50:34 +0000 (10:20 +1030)]
jmap: fix tools/speed

Minor fixes on top of patch from rocco@tecsiel.it:

Hi Rusty,
latest git version of the file ccan/jmap/tools/speed.c does not
compile.

Please find attacched my own version with the following differences:

  1. deleted inclusion of <ccan/jmap/jmap_type.h> which is no longer in ccan/

  2. added inclusion of <ccan/time/time.h>

  3. added definition of struct jmap_obj in terms of JMAP_MEMBERS();

  4. deleted use of macro JMAP_DEFINE_UINTIDX_TYPE() which is no longer needed

  5. changed function normalize() to be aligned with ccan/htable/tools/speed.c

  6. repleaced gettimeofday() in favour of time_now()

  7. added memory cleanup at the end of the program in terms of
       jmap_free(jmap);
       free(objs);
     to be valgrind safe

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agopipecmd: fix warn-unused-result warnings (-O2)
Rusty Russell [Tue, 25 Oct 2016 04:46:07 +0000 (15:16 +1030)]
pipecmd: fix warn-unused-result warnings (-O2)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoptr_valid: fix warn-unused-result warning (-O2)
Rusty Russell [Tue, 25 Oct 2016 04:46:07 +0000 (15:16 +1030)]
ptr_valid: fix warn-unused-result warning (-O2)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoio: fix maybe-uninitialized warning in test (-O2)
Rusty Russell [Tue, 25 Oct 2016 04:46:07 +0000 (15:16 +1030)]
io: fix maybe-uninitialized warning in test (-O2)

/home/rusty/devel/cvs/ccan/ccan/io/test/run-01-start-finish.c: In function ‘main’:
/home/rusty/devel/cvs/ccan/ccan/io/test/run-01-start-finish.c:89:7: warning: ‘addrinfo’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (connect(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoforeach: fixed maybe uninitialized warning in test (-O2)
Rusty Russell [Tue, 25 Oct 2016 04:45:33 +0000 (15:15 +1030)]
foreach: fixed maybe uninitialized warning in test (-O2)

/home/rusty/devel/cvs/ccan/ccan/tap/tap.h:57:59: warning: ‘max_iters’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \
                                                           ^
/home/rusty/devel/cvs/ccan/ccan/foreach/test/run-nested.c:47:17: note: ‘max_iters’ was declared here
  int i, j, sum, max_iters;

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoerr: fix warn-unused-result warning in test (-O2)
Rusty Russell [Tue, 25 Oct 2016 04:44:33 +0000 (15:14 +1030)]
err: fix warn-unused-result warning in test (-O2)

/home/rusty/devel/cvs/ccan/ccan/err/test/run.c:124:2: warning: ignoring return value of ‘pipe’, declared with attribute warn_unused_result [-Wunused-result]
  pipe(pfd);

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agocdump: fix uninitialized warning with optimization
Rusty Russell [Tue, 25 Oct 2016 04:07:00 +0000 (14:37 +1030)]
cdump: fix uninitialized warning with optimization

/home/rusty/devel/cvs/ccan/ccan/cdump/cdump.c: In function ‘get_type’:
/home/rusty/devel/cvs/ccan/ccan/strmap/strmap.h:88:39: warning: ‘m’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  tcon_cast((map), canary, strmap_get_(&(map)->raw, (member)))
                                       ^
/home/rusty/devel/cvs/ccan/ccan/cdump/cdump.c:216:20: note: ‘m’ was declared here
  cdump_map_t *m;
               ^

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoAdd appveyor.yml
Kevin Locke [Thu, 29 Sep 2016 00:44:48 +0000 (18:44 -0600)]
Add appveyor.yml

This file defines the AppVeyor CI (appveyor.com) settings.

It builds using make+bash under MSYS2 so that the current build system
can be used with minimal changes.  It currently only builds configurator
and generates config.h.

The build and test commands for more thorough testing are left as
comments in appveyor.yml so interested parties can use them as a
starting point for future work.

Note that several compiler errors not related to configurator are
printed due to make attempting to generate and include test-depends.
Although Windows-specific code could be added to Makefile to avoid
these, it seemed unwarranted if the compile errors may be fixed soon.

Changes since v2:
- Add reference to AppVeyor results for canonical repo and basic
  instructions to setup AppVeyor for forks.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoMakefile: Define CFLAGS_FORCE_C_SOURCE macro
Kevin Locke [Thu, 29 Sep 2016 00:44:47 +0000 (18:44 -0600)]
Makefile: Define CFLAGS_FORCE_C_SOURCE macro

This macro holds the C compiler flag(s) to force input files to be
recognized as C sources regardless of extension.  It is defined to allow
overriding on the make command line.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoconfigurator: DEFAULT_{COMPILER, FLAGS} for MSVC
Kevin Locke [Thu, 29 Sep 2016 00:44:46 +0000 (18:44 -0600)]
configurator: DEFAULT_{COMPILER, FLAGS} for MSVC

When compiling with Visual Studio, use default compiler name and flags
which are likely to work with the known-available compiler.

This is also a convenience for users who may not know what arguments
cl.exe may need to compile the tests.

Changes since v1:
- Use "-option" instead of "/option" to avoid issues running under msys.
- Disable C4200 warning for use of flexible array members, which MSVC
  considers an extension (since it does not fully support C99).

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoconfigurator: Add output cflag option and macro
Kevin Locke [Thu, 29 Sep 2016 00:44:45 +0000 (18:44 -0600)]
configurator: Add output cflag option and macro

Unfortunately, not all compilers support -o as a command-line option for
specifying the output file.  Visual Studio cl.exe issues warning D9035
when -o is given, which is detected as a compile warning by the
configurator.

To support such compilers, add the command-line option -O to
configurator which can be used to specify the cflag for setting the
output executable file name.  Additionally define the macro
CCAN_OUTPUT_EXE_CFLAG in config.h and use it when invoking the compiler
(e.g.  from ccanlint).

For reference, the name CCAN_OUTPUT_EXE_CFLAG was chosen to avoid
potential name conflicts in the future due to cl.exe requiring different
flags for different types of output[1] (e.g. object files are /Fo:).

1.  https://msdn.microsoft.com/en-us/library/f1cb223a.aspx

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoconfigurator: Print test source without cat
Kevin Locke [Thu, 29 Sep 2016 00:44:44 +0000 (18:44 -0600)]
configurator: Print test source without cat

Windows does not provide cat.  Instead, copy the test source to stdout
using the file stream to which it was written.

Changes since v1:
- Create fwrite_noeintr to avoid EINTR in fwrite without writing any
  data.
- Handle short reads from fread.  This can happen with non-conformant
  libc or if EINTR occurs after reading some data.
- Handle short writes from fwrite.  This can happen with non-conformant
  libc or if EINTR occurs after writing some data.

Changes since v2:
- Revert fwrite_noeintr and short read/write changes.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoconfigurator: Inline err.h functions
Kevin Locke [Thu, 29 Sep 2016 00:44:43 +0000 (18:44 -0600)]
configurator: Inline err.h functions

On systems where err.h is not provided (e.g. MSVC) configurator must
provide its own definition.  The err module can not be used by
configurator due to its dependency on config.h, so the relevant source
is copied into configurator with the minimum changes necessary.

Changes since v2:
- Use the CCAN err module sources instead of musl libc sources to avoid
  introducing another implementation of these functions.
- Prefix err.h functions with "c12r_" to avoid name conflicts and
  "static declaration follows non-static" errors.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoconfigurator: Reimplement run using popen
Kevin Locke [Thu, 29 Sep 2016 00:44:42 +0000 (18:44 -0600)]
configurator: Reimplement run using popen

Rather than using fork+pipe+system+waitpid, most of which are only
available on POSIX-like systems, use popen which is also available on
Windows (under the name _popen).

Changes since v1:
- Create fread_noeintr to avoid EINTR in fread without reading any data.
- Handle short reads from fread.  This can happen with non-conformant
  libc or if EINTR occurs after reading some data.
- Define _POSIX_C_SOURCE for popen/pclose with strict implementations
  which require it (e.g. gcc with -std=c11).

Changes since v2:
- Revert fread_noeintr and short read changes in v1 as unnecessary.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agolist: trivial: fix typos in list_for_each_off's documentation
Emilio G. Cota [Thu, 29 Sep 2016 21:54:13 +0000 (17:54 -0400)]
list: trivial: fix typos in list_for_each_off's documentation

Signed-off-by: Emilio G. Cota <cota@braap.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agotime: add timemono_since
Emilio G. Cota [Tue, 27 Sep 2016 21:57:53 +0000 (17:57 -0400)]
time: add timemono_since

time_mono()'s documentation references time_since(), which is nowhere
to be found.

A possible fix would be to just remove that stale reference.

Instead, this patch adds timemono_since(), which hopefully
captures the meaning of the original time_since().

Signed-off-by: Emilio G. Cota <cota@braap.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoconfigurator: Return pointer difference as ptrdiff_t
Kevin Locke [Fri, 23 Sep 2016 03:33:14 +0000 (21:33 -0600)]
configurator: Return pointer difference as ptrdiff_t

On LLP64 systems (like 64-bit Windows) long is 32 bits while pointers
are 64 bits, which results in a warning similar to the following:

warning C4244: 'return': conversion from '__int64' to 'long', possible loss of data

for HAVE_STACK_GROWS_UPWARDS.  Fix this by using the ptrdiff_t type
introduced by C99 for this purpose.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoconfigurator: Fix warning in HAVE_FOR_LOOP_DECLARATION
Kevin Locke [Fri, 23 Sep 2016 03:33:13 +0000 (21:33 -0600)]
configurator: Fix warning in HAVE_FOR_LOOP_DECLARATION

Visual C++ prints "warning C4702: unreachable code" due to the return
statement after the for loop which is never reached.  Fix this by
setting a variable returned by a single return statement at the end.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoconfigurator: Fix compiler warning with compare
Kevin Locke [Fri, 23 Sep 2016 03:33:10 +0000 (21:33 -0600)]
configurator: Fix compiler warning with compare

Visual Studio prints warning C4706 "assignment within conditional
expression" when there is an assignment without a comparison in a
conditional expression.  Therefore, to silence the warning, add an
explicit comparison.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoconfigurator: Mark non-Windows tests MAY_NOT_COMPILE
Kevin Locke [Fri, 23 Sep 2016 03:33:08 +0000 (21:33 -0600)]
configurator: Mark non-Windows tests MAY_NOT_COMPILE

Several of the EXECUTABLE tests depend on headers not available on
Windows.  Mark these tests MAY_NOT_COMPILE to handle this.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoconfigurator: Use native directory separator
Kevin Locke [Fri, 23 Sep 2016 03:33:07 +0000 (21:33 -0600)]
configurator: Use native directory separator

Although Windows APIs generally permit "/" or "\\" for directory
separators in paths, cmd.exe does not recognize "./" when invoking
executables using a relative path and prints the following error:

    '.' is not recognized as an internal or external command,
    operable program or batch file.

Therefore, use "\\" when invoking tests on Windows.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoconfigurator: Replace unlink with remove
Kevin Locke [Fri, 23 Sep 2016 03:33:04 +0000 (21:33 -0600)]
configurator: Replace unlink with remove

Although Windows provides unlink, using it adds complication due to the
lack of unistd.h which must be included to define the function on POSIX
systems.  Instead, use remove, which C89 requires to be in stdio.h.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoccan/list: Add list_empty_nocheck
Benjamin Herrenschmidt [Sat, 23 Jul 2016 10:46:58 +0000 (20:46 +1000)]
ccan/list: Add list_empty_nocheck

This is the same as list_empty but without the debug checks. This is
useful when wanting to check for an empty list without locks held,
potentially racing with addition/removal, which can be a valid thing
to do under some circumstances.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoaga: trivial: fix description of aga_bfs
Emilio G. Cota [Mon, 26 Sep 2016 21:27:00 +0000 (17:27 -0400)]
aga: trivial: fix description of aga_bfs

Signed-off-by: Emilio G. Cota <cota@braap.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoRemove travis workarounds for previous build system
Jon Griffiths [Wed, 21 Sep 2016 01:56:08 +0000 (13:56 +1200)]
Remove travis workarounds for previous build system

With proper dependencies and parallel safety, we can just
'make check -j N' directly. Also build quietly so that we
only get build warnings, errors and test results in the output.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
4 years agoMakefile: First try at rewriting the ccan Makefile.
Jon Griffiths [Thu, 1 Sep 2016 09:24:36 +0000 (21:24 +1200)]
Makefile: First try at rewriting the ccan Makefile.

This change contains a simpler Makefile replacement with only 62 lines
of directives, 10 rules, and a 13 line support script for dependencies. The
build dependencies have been minimised and in some cases, corrected.

FEATURES:
* All targets can be built from a clean tree in one invocation.
* Parallel builds (tested with -j32 on 8 cores).
* Auto discovery of modules via _info files.
* Hopefully complete dependencies via a simplified generator.
* CFLAGS are respected and appended to compile flags.
* LINTFLAGS can be set to add check options (e.g. LINTFLAGS=-v).
* 'make clean' doesn't build anything before cleaning now.
* 'make quiet=1' builds quietly. 'make check quiet=1 -j N' produces
  summary output like the former summary target.
* Non-phony test targets; tests are rebuilt only when dirty. Targets are:
  check, fastcheck and fullcheck, the latter runs in non-summary mode.
* 'make <module>.[check|fastcheck|fullcheck]' runs tests for single modules.

TODO:
* Support Makefile-web and any other scattered targets

NOTES:
* The changes to dependency generation expose a circular
  dependency between asort and order which is not fixed here.
* Tests always run their dependent tests. With -j support and
  minimised rebuilds via tighter dependencies, its not worth avoiding.
* Some targets have been dropped as uneeded (e.g. distclean, tools).

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
4 years agoRemove duplicate const qualifier
Jon Griffiths [Wed, 21 Sep 2016 01:48:58 +0000 (13:48 +1200)]
Remove duplicate const qualifier

This causes ccanlint to fail the 'no warnings' check under clang.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
4 years agotal/stack: fix up after tal change.
Rusty Russell [Thu, 8 Sep 2016 10:48:52 +0000 (20:18 +0930)]
tal/stack: fix up after tal change.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agotal: store length in bytes, not count, and always store if CCAN_TAL_DEBUG.
Rusty Russell [Thu, 8 Sep 2016 04:20:32 +0000 (13:50 +0930)]
tal: store length in bytes, not count, and always store if CCAN_TAL_DEBUG.

Useful for scanning all the memory, or tallying it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agotal: remove unused assigned var (scan-build warning)
Rusty Russell [Thu, 8 Sep 2016 02:05:43 +0000 (11:35 +0930)]
tal: remove unused assigned var (scan-build warning)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agopipecmd: fix minor memleak detected by scan-build.
Rusty Russell [Thu, 8 Sep 2016 02:00:08 +0000 (11:30 +0930)]
pipecmd: fix minor memleak detected by scan-build.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agotal: make tal_next() only return immediate children.
Rusty Russell [Wed, 7 Sep 2016 04:27:01 +0000 (13:57 +0930)]
tal: make tal_next() only return immediate children.

I tried to use it and got this wrong: moreover, I wanted to control
topology, which requires nested iteration, and skip children
of a node which I knew was changing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoAdd a SHA512 implementation
Jon Griffiths [Sun, 28 Aug 2016 23:43:39 +0000 (11:43 +1200)]
Add a SHA512 implementation

This largely follows the SHA256 style. I've named Rusty as the maintainer.

Currently the functions to add data of various sizes/endianness have not
been implemented: There are no public test vectors for these cases and
I believe most use cases are working on byte buffers. They can be added
later if desired.

The openssl implementation has been tested on x86-64, while the inbuilt
version has been tested on 32/64 bit, little/big endian boxes.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>