ccan
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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 years agoccanlint: depends_accurate: don't detect false dependency when including test files.
Rusty Russell [Tue, 30 Aug 2016 12:28:13 +0000 (21:58 +0930)]
ccanlint: depends_accurate: don't detect false dependency when including test files.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agotools/ccanlint: test_depends_accurate: catch #include of other ccan C files.
Rusty Russell [Tue, 30 Aug 2016 00:35:06 +0000 (10:05 +0930)]
tools/ccanlint: test_depends_accurate: catch #include of other ccan C files.

Jon sent a test patch for sha256 which "#include <ccan/str/hex/hex.c>"
without adding str/hex to testdepends.  It "worked" (it wouldn't have
linked with "hex.h"), but ccanlint didn't spot the dependency.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoMerge remote-tracking branch 'origin/pr/48'
Rusty Russell [Tue, 30 Aug 2016 00:32:06 +0000 (10:02 +0930)]
Merge remote-tracking branch 'origin/pr/48'

3 years agoMerge remote-tracking branch 'origin/pr/50'
Rusty Russell [Tue, 30 Aug 2016 00:27:55 +0000 (09:57 +0930)]
Merge remote-tracking branch 'origin/pr/50'

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agosha256: Use hex for test results
Jon Griffiths [Mon, 29 Aug 2016 00:47:59 +0000 (12:47 +1200)]
sha256: Use hex for test results

Users should be able to verify our crypto tests by searching for the
vectors we use. Make that easier by using hex for the expected results.

A nice side effect is that the code is simpler and endian agnostic too.

3 years agomanifest: Print the directory name if no files are found
Jon Griffiths [Wed, 24 Aug 2016 07:55:03 +0000 (19:55 +1200)]
manifest: Print the directory name if no files are found

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agoconfigurator: Fix unused parameters
Jon Griffiths [Wed, 24 Aug 2016 07:51:27 +0000 (19:51 +1200)]
configurator: Fix unused parameters

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agoshachain: Fix signed/unsigned mismatches
Jon Griffiths [Wed, 24 Aug 2016 07:50:40 +0000 (19:50 +1200)]
shachain: Fix signed/unsigned mismatches

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agociniparser: Make key arguments const
Jon Griffiths [Wed, 24 Aug 2016 07:04:24 +0000 (19:04 +1200)]
ciniparser: Make key arguments const

Keys are never modified and are likely to be literals in the
real world (as they are in the test cases).

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agobase64: Remove an invalid assertion
Jon Griffiths [Wed, 24 Aug 2016 06:59:50 +0000 (18:59 +1200)]
base64: Remove an invalid assertion

Unsigned types cannot be negative.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agostrmap: Set the license for strmap to CC0
Jon Griffiths [Wed, 24 Aug 2016 06:44:12 +0000 (18:44 +1200)]
strmap: Set the license for strmap to CC0

This matches the license in _info and the source. It also means every
module now has a LICENSE file and so anyone happening to rewrite the
ccan makefiles can use wildcard to locate modules rather than listing
them by hand.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agogenerator: Don't print variable unless the generator returned a value
Jon Griffiths [Mon, 22 Aug 2016 14:39:38 +0000 (02:39 +1200)]
generator: Don't print variable unless the generator returned a value

clang warns that the generator assignment is conditional which could
lead to passing an undefined variable to printf.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agoEnsure config.h is created before the main travis builds
Jon Griffiths [Mon, 29 Aug 2016 01:10:29 +0000 (13:10 +1200)]
Ensure config.h is created before the main travis builds

The current makefiles are not parallel safe and reliably fail on the
clang build. The real fix is to rewrite the makefiles, but in the
meantime, allow the clang tests to pass.

3 years agosha256: Simplify test
Jon Griffiths [Sun, 28 Aug 2016 23:52:44 +0000 (11:52 +1200)]
sha256: Simplify test

We can use the iteration count in the test case to determine
whether a single call is required. This simplifies the code and
also means that we don't overstate the actual number of tests
performed by a factor of 2. Simplify a couple of expressions
while we are changing this.

3 years agotlist: Place tlists last in structures
Jon Griffiths [Mon, 22 Aug 2016 14:04:06 +0000 (02:04 +1200)]
tlist: Place tlists last in structures

TCON suggests placing _tcon members last in structs. Placing variable
sized structs anywhere but last is apparently a gcc extension that
gives warnings under clang.

This applies to tlists because they use TCON internally. Update the
docs and examples to place tlists last and so compile without clang
warnings.

There are other places where this occurs; they will be dealt with
separately.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agopr_log: Fix a warning building under clang
Jon Griffiths [Mon, 22 Aug 2016 13:09:28 +0000 (01:09 +1200)]
pr_log: Fix a warning building under clang

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agotools/ccan_depends: Don't crash when no dependencies are found
Jon Griffiths [Tue, 23 Aug 2016 14:05:55 +0000 (02:05 +1200)]
tools/ccan_depends: Don't crash when no dependencies are found

Running 'tools/ccan_depends --compile ccan/crypto' without this
patch will demonstrate the crash.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agotal: Fix a comment typo
Jon Griffiths [Tue, 23 Aug 2016 13:43:05 +0000 (01:43 +1200)]
tal: Fix a comment typo

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agoMerge remote-tracking branch 'origin/pr/47'
Rusty Russell [Tue, 23 Aug 2016 03:39:44 +0000 (13:09 +0930)]
Merge remote-tracking branch 'origin/pr/47'

Closes: 47

3 years agoMerge remote-tracking branch 'origin/pr/46'
Rusty Russell [Tue, 23 Aug 2016 03:37:07 +0000 (13:07 +0930)]
Merge remote-tracking branch 'origin/pr/46'

Closes: 46

3 years agoMerge remote-tracking branch 'origin/pr/45'
Rusty Russell [Tue, 23 Aug 2016 03:33:10 +0000 (13:03 +0930)]
Merge remote-tracking branch 'origin/pr/45'

Closes: 45

3 years agoripemd160: Remove unused static function Initialize()
Jon Griffiths [Mon, 22 Aug 2016 13:20:32 +0000 (01:20 +1200)]
ripemd160: Remove unused static function Initialize()

The header macro RIPEMD160_INIT is intended to be used instead I believe.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agoripemd160: Declare variable at the start of its function
Jon Griffiths [Mon, 22 Aug 2016 11:34:19 +0000 (23:34 +1200)]
ripemd160: Declare variable at the start of its function

The resulting code is just as clear to read, so lets not require
a C99 compiler to compile this.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agohex: Simplify hex_encode
Jon Griffiths [Mon, 30 May 2016 12:39:10 +0000 (00:39 +1200)]
hex: Simplify hex_encode

The documentation for hex_encode indicates that it returns simply true or
false. The old implementation was returning the written length on success,
cast to boolean. This will elicit a warning under MSVC.

On further examination, there is no need to check/modify the length inside
the loop, since we can check it once before starting. As a result the code
can be simplified a bit.

A side affect of this change is that nothing will be written at all if the
length is incorrect, vs the previous code writing characters until the length
available is exhausted. I prefer the new semantics but YMMV.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agosha256: Use fewer magic magic numbers
Jon Griffiths [Wed, 23 Mar 2016 04:25:29 +0000 (17:25 +1300)]
sha256: Use fewer magic magic numbers

Show the derivation of the constants to match the comment above them.
The compiler doesn't care, but it helps the code read better.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agosha256: Move 'bytes' to the end of sha256_ctx and make it a size_t
Jon Griffiths [Tue, 22 Mar 2016 22:54:50 +0000 (11:54 +1300)]
sha256: Move 'bytes' to the end of sha256_ctx and make it a size_t

The code already assigns to/from bytes as a size_t, so make it
official (and better on platforms with a 32 bit size_t).

Moving bytes makes it act as a canary in the event that there is a rogue
write/off by one somewhere - since it ends up in the hash we are
more likely to detect this should we corrupt it. This also makes the
working buffer better aligned which can't hurt.

Also, initialise the buffer to zero while we are changing the initialisation
macro anyway. It costs little compared to the hashing overhead, should be
optimised away if redundant in most cases, and it removes a warning from both
gcc and clang about unititialised struct members.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agosha256: Use the same union order as the ctx structure
Jon Griffiths [Tue, 22 Mar 2016 22:51:50 +0000 (11:51 +1300)]
sha256: Use the same union order as the ctx structure

This reads better. Also remove duplicated comments for the members.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agosha256: Make our u32 and u8 fields the same size
Jon Griffiths [Tue, 22 Mar 2016 22:49:48 +0000 (11:49 +1300)]
sha256: Make our u32 and u8 fields the same size

These are just aliases to a buffer: its customary for these to
have the same size, and makes sizeof() consistent in case anyone
decides to use the members instead of the containing union.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agosha256: Mark parameters as potentially unused
Jon Griffiths [Tue, 15 Mar 2016 06:48:29 +0000 (19:48 +1300)]
sha256: Mark parameters as potentially unused

Prevents warnings from gcc at higher warning levels.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agocrypto: Comment typo
Jon Griffiths [Tue, 22 Mar 2016 11:04:04 +0000 (00:04 +1300)]
crypto: Comment typo

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agocrypto: Remove C++ comments
Jon Griffiths [Tue, 22 Mar 2016 06:57:29 +0000 (19:57 +1300)]
crypto: Remove C++ comments

Prevents warnings from gcc at higher warning levels.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agoripemd160: Fix a name typo
Jon Griffiths [Mon, 28 Mar 2016 14:09:30 +0000 (03:09 +1300)]
ripemd160: Fix a name typo

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agoripemd160: Mark parameters as potentially unused
Jon Griffiths [Tue, 22 Mar 2016 06:48:39 +0000 (19:48 +1300)]
ripemd160: Mark parameters as potentially unused

Prevents warnings from gcc at higher warning levels.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
3 years agocast: fix indentation in example.
Rusty Russell [Tue, 28 Jun 2016 20:39:52 +0000 (06:09 +0930)]
cast: fix indentation in example.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoaltstack: Don't log internal calls in test cases
David Gibson [Fri, 3 Jun 2016 08:42:03 +0000 (18:42 +1000)]
altstack: Don't log internal calls in test cases

altstack/test/run.c uses some hairy macros to intercept the standard
library functions that altstack uses.  This has two purposes: 1) to
conditionally cause those functions to fail, and thereby test altstack's
error paths, and 2) log which of the library functions was called in each
testcase.

The second function isn't actually useful - for the purposes of testing the
module, we want to check the actual behaviour, not what calls it made in
what order to accomplish it.  Explicitly checking the calls makes it much
harder to change altstack's implementation without breaking the tests.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoaltstack: Don't use 0 pointer literals
David Gibson [Fri, 3 Jun 2016 08:42:02 +0000 (18:42 +1000)]
altstack: Don't use 0 pointer literals

In a number of places the altstack module uses a literal '0' for pointer
values.  That's correct C, but doesn't make it obvious on a quick read
whether values are integers or pointers.  This patch changes those cases
to use the NULL define instead.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoaltstack: Use ptrint instead of bare casts
David Gibson [Fri, 3 Jun 2016 08:42:01 +0000 (18:42 +1000)]
altstack: Use ptrint instead of bare casts

Functions invoked with altstack take a void * parameter.  However, the
test program wants to pass an integer, and so uses the trick of casting
the integer values to (void *) and back again.

The ptrint() module handles exactly this case in a more portable and
(somewhat) typesafe way, so use that instead.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoaltstack: Restore alternate signal stack state
David Gibson [Fri, 3 Jun 2016 08:42:00 +0000 (18:42 +1000)]
altstack: Restore alternate signal stack state

altstack relies on catching a SIGSEGV caused when overrunning the stack.
This means that the SEGV handler itself can't use the already overflowed
stack, and so we use sigaltstack() to assign the signal handler a different
stack.  On completion, altstack() clears the alternate signal stack.

However, it's possible that the calling program could be using
sigaltstack() for its own reasons, so it's more correct to restore the
sigaltstack() state to that from the beginning of the altstack() call.
This patch implements this behaviour.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agoaltstack: Consolidate thread-local variables
David Gibson [Fri, 3 Jun 2016 08:41:59 +0000 (18:41 +1000)]
altstack: Consolidate thread-local variables

altstack uses a number of __thread variables to track internal state.  This
allows altstack to be thread-safe, although it's still not re-entrant.
This patch gathers all these variables into a single per-thread state
structure.  This makes it easy to see at a glance what the whole of the
required state is, and thereby easier to reason about correctness of
changes to the implementation.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
3 years agohtable: allow htable_type keys to be non-pointers.
Rusty Russell [Mon, 6 Jun 2016 04:37:44 +0000 (14:07 +0930)]
htable: allow htable_type keys to be non-pointers.

Common case is mapping ints to structures.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agohtable: htable_type add htable_copy.
Rusty Russell [Mon, 6 Jun 2016 04:20:39 +0000 (13:50 +0930)]
htable: htable_type add htable_copy.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agohtable: add htable_copy.
Rusty Russell [Mon, 6 Jun 2016 04:14:36 +0000 (13:44 +0930)]
htable: add htable_copy.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agohtable: add a htable_prev method to oppose _next
Cody P Schafer [Fri, 3 Jun 2016 15:55:45 +0000 (11:55 -0400)]
htable: add a htable_prev method to oppose _next

Useful for unwinding actions taken while iterating over a htable.

Signed-off-by: Cody P Schafer <dev@codyps.com>
4 years agotlist: Add tlist_next() and tlist_prev() functions
David Gibson [Sat, 4 Jun 2016 10:21:33 +0000 (20:21 +1000)]
tlist: Add tlist_next() and tlist_prev() functions

An odd omission from the tlist module is basic tlist_next() and
tlist_prev() macros matching list_next() and list_prev() in the basic
list module.  This adds them.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoagar: Add static graph initializer
David Gibson [Fri, 3 Jun 2016 10:07:10 +0000 (20:07 +1000)]
agar: Add static graph initializer

Sometimes it's not convenient to initialize an agar graph at runtime with
agar_init_graph().  This adds an AGAR_INIT_GRAPH() macro to do the same
thing as a static initializer.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoaga: Remove unused state defines
David Gibson [Tue, 31 May 2016 10:09:30 +0000 (20:09 +1000)]
aga: Remove unused state defines

These were left over from a previous approach which didn't pan out.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agotcon: add testcase for const members in tcon_container_of()
Rusty Russell [Thu, 2 Jun 2016 02:00:53 +0000 (11:30 +0930)]
tcon: add testcase for const members in tcon_container_of()

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agotcon: add test case for const members.
Rusty Russell [Thu, 2 Jun 2016 01:58:54 +0000 (11:28 +0930)]
tcon: add test case for const members.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agotlist2: a alternate to tlist that encodes the member offset into the container type
Cody P Schafer [Tue, 31 May 2016 19:09:13 +0000 (15:09 -0400)]
tlist2: a alternate to tlist that encodes the member offset into the container type

Signed-off-by: Cody P Schafer <dev@codyps.com>