ccan
4 years agotweaks from feedback - thanks
Dan Good [Thu, 10 Dec 2015 10:48:55 +0000 (10:48 +0000)]
tweaks from feedback - thanks

4 years agoAdd xstring module - bounded string builder with three valued comparator
Dan Good [Thu, 10 Dec 2015 06:05:22 +0000 (06:05 +0000)]
Add xstring module - bounded string builder with three valued comparator

4 years agoMakefile-web: Quote the names in the error message
Joel Stanley [Wed, 9 Dec 2015 01:17:52 +0000 (11:47 +1030)]
Makefile-web: Quote the names in the error message

 progress found but fubar in MOD

is now:

 'progress' found but 'fubar' in MOD

Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoweb/logo: Use a relative protocol
Joel Stanley [Wed, 9 Dec 2015 01:17:51 +0000 (11:47 +1030)]
web/logo: Use a relative protocol

The webfont forces http, which results in a mixed content warning if
you're visiting the site on https. Strip the protocol so we use whatever
the user has connected with.

Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoMakefile-web: Download prettify from git
Joel Stanley [Wed, 9 Dec 2015 01:17:50 +0000 (11:47 +1030)]
Makefile-web: Download prettify from git

The SVN mirror disappeared some time ago. It now lives on Github.

Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agopipecmd: test can't-exec case.
Rusty Russell [Fri, 20 Nov 2015 06:32:14 +0000 (17:02 +1030)]
pipecmd: test can't-exec case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agopipecmd: add pipecmdarr variant.
Rusty Russell [Fri, 20 Nov 2015 06:29:09 +0000 (16:59 +1030)]
pipecmd: add pipecmdarr variant.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agotools/namespacize: use unlink_noerr.
Rusty Russell [Fri, 20 Nov 2015 06:27:05 +0000 (16:57 +1030)]
tools/namespacize: use unlink_noerr.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agonet: use close_noerr.
Rusty Russell [Fri, 20 Nov 2015 06:26:27 +0000 (16:56 +1030)]
net: use close_noerr.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agonoerr: add free_noerr().
Rusty Russell [Fri, 20 Nov 2015 06:22:34 +0000 (16:52 +1030)]
noerr: add free_noerr().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoaga,agar: New shortcut2 sample graph and testcases based on it
David Gibson [Fri, 6 Nov 2015 01:26:17 +0000 (12:26 +1100)]
aga,agar: New shortcut2 sample graph and testcases based on it

This patch adds a new test graph "shortcut2" which includes a negative cost
edge.  Along with that we add a testcase for Dijkstra's algorithm checking
that it gracefully fails in this case.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoaga,agar: New shortcut1 sample graph and testcases based on it
David Gibson [Fri, 6 Nov 2015 01:26:03 +0000 (12:26 +1100)]
aga,agar: New shortcut1 sample graph and testcases based on it

For all the existing test graphs, the shortest path by cost is also the
shortest path by number of edges.  This patch adds a new test graph where
that is not the case, in order to test that the Dijkstra's algorithm
implementation correctly handles that case.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoaga,agar: Non-equal edge costs for parallel test graph
David Gibson [Fri, 6 Nov 2015 01:25:50 +0000 (12:25 +1100)]
aga,agar: Non-equal edge costs for parallel test graph

At the moment the "parallel" test graph just uses the default cost of 1
for all the links between the two nodes.  This patch changes that so that
the links have cost 2, except (optionally) one with cost 1.  This provides
a useful test for the Dijkstra's algorithm implementation to ensure that
it picks the correct link for the shortest path.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoaga,agar: Dijkstra's algorithm
David Gibson [Fri, 6 Nov 2015 01:25:30 +0000 (12:25 +1100)]
aga,agar: Dijkstra's algorithm

Implement Dijkstra's algorithm for one-source shortest-path.

This uses the lpq module as the implementation of the priority queue.  That
means this implementation is some way behind the theoretical efficiency of
Dijkstra's algorithm.  It should be reasonably straightforward to swap out
the priority queue for a better one in the future, though.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoaga,agar: Add edge costs
David Gibson [Fri, 6 Nov 2015 01:23:53 +0000 (12:23 +1100)]
aga,agar: Add edge costs

This allows the edge_info callback to supply a cost or length for an edge.
For now we only support 'long' valued costs.  If the callback doesn't
supply a cost, it's considered cost 1.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoMakefile-ccan: add pipecmd
Rusty Russell [Fri, 20 Nov 2015 05:40:51 +0000 (16:10 +1030)]
Makefile-ccan: add pipecmd

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agopipecmd: new module.
Rusty Russell [Fri, 20 Nov 2015 05:39:48 +0000 (16:09 +1030)]
pipecmd: new module.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agostrgrp: Cache cosine popcounts to reduce computation
Andrew Jeffery [Sun, 15 Nov 2015 10:14:57 +0000 (20:44 +1030)]
strgrp: Cache cosine popcounts to reduce computation

Neatly, this reduces some of the OpenMP-related noise in the
implementation by removing the need for the include. The loop body of
grp_for() is also clearer as a result of the change; the changes to the
function interfaces motivated a re-think of the complexity here.

4 years agostrgrp: Fix indexing of per-thread storage for cosine filter
Andrew Jeffery [Fri, 13 Nov 2015 12:25:19 +0000 (22:55 +1030)]
strgrp: Fix indexing of per-thread storage for cosine filter

4 years agoaga: Add aga_node_needs_update() internal function
David Gibson [Thu, 12 Nov 2015 11:21:10 +0000 (22:21 +1100)]
aga: Add aga_node_needs_update() internal function

There are situations where aga algorithms may want to check if a node is
up-to-date (i.e. has yet been discovered by the current algorithm) without
making it up to date if it's not.  This adds an internal function to do so.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agostrgrp: Add cosine similarity filter
Andrew Jeffery [Thu, 24 Sep 2015 12:49:39 +0000 (22:19 +0930)]
strgrp: Add cosine similarity filter

The cosine similarity measure[1] (O(m + n)) contributes a decent runtime
reduction when used as a filter prior to execution of more expensive
algorithms such as LCS[2] (O(m * n)).

A private test set of 3500 strings was used to quantify the improvement.
The shape of the test set is described by Python's Pandas module as:

    >>> frames.apply(len).describe()
    count    3500.000000
    mean       47.454286
    std        14.980197
    min        10.000000
    25%        37.000000
    50%        45.000000
    75%        61.000000
    max       109.000000
    dtype: float64
    >>>

The tests were performed on a lightly loaded Lenovo X201s stocked with a
Intel Core i7 L 640 @ 2.13GHz CPU with 3.7 GiB of memory. The test was
compiled with GCC 4.9.3:

    $ gcc --version
    gcc (Gentoo 4.9.3 p1.0, pie-0.6.2) 4.9.3
    Copyright (C) 2015 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Using the test program outlined below, ten runs for input set sizes
incrementing in batches of 500 were taken prior to filtering with cosine
similarity:

    500:  0.61, 0.25, 0.08, 0.07, 0.07, 0.07, 0.09, 0.07, 0.07, 0.07
    1000: 0.33, 0.32, 0.34, 0.32, 0.32, 0.33, 0.32, 0.32, 0.34, 0.32
    1500: 0.72, 1.53, 0.72, 0.70, 0.72, 0.70, 0.72, 0.71, 1.46, 0.71
    2000: 1.22, 1.20, 1.22, 1.98, 1.20, 1.20, 1.22, 1.94, 1.20, 1.20
    2500: 1.97, 2.72, 1.94, 2.33, 2.44, 1.94, 2.82, 1.93, 1.94, 2.69
    3000: 2.69, 3.41, 2.66, 3.38, 2.67, 3.42, 2.63, 3.44, 2.65, 3.39
    3500: 4.18, 3.65, 4.21, 4.21, 3.56, 4.21, 4.16, 3.63, 4.20, 4.13

After adding the cosine similarity filter the runtimes became:

    500:  0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02
    1000: 0.08, 0.07, 0.07, 0.07, 0.08, 0.07, 0.07, 0.08, 0.07, 0.07
    1500: 0.16, 0.16, 0.15, 0.16, 0.16, 0.15, 0.15, 0.15, 0.16, 0.16
    2000: 0.26, 0.26, 0.25, 0.26, 0.26, 0.26, 0.25, 0.26, 0.26, 0.26
    2500: 0.41, 0.41, 0.41, 0.40, 0.42, 0.42, 0.42, 0.41, 0.41, 0.41
    3000: 0.58, 0.56, 0.57, 0.56, 0.58, 0.57, 0.56, 0.56, 0.57, 0.55
    3500: 0.75, 0.74, 0.73, 0.74, 0.74, 0.73, 0.72, 0.75, 0.75, 0.75

As such, on average the runtime improvements are:

    N       Avg Pre         Avg Post        Improvement (Pre / Post)
    500     0.145           0.02            7.25
    1000    0.326           0.073           4.47
    1500    0.869           0.156           5.57
    2000    1.358           0.258           5.26
    2500    2.272           0.412           5.51
    3000    3.034           0.566           5.36
    3500    4.014           0.74            5.42

The test driver is as below, where both it and its dependencies were
compiled with 'CFLAGS=-O2 -fopenmp' and linked with 'LDFLAGS=-fopenmp',
'LDLIBS=-lm':

    $ cat test.c
    #include "config.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "ccan/strgrp/strgrp.h"

    int main(void) {
        FILE *f;
        char *buf;
        struct strgrp *ctx;
        f = fdopen(0, "r");
    #define BUF_SIZE 512
        buf = malloc(BUF_SIZE);
        ctx = strgrp_new(0.85);
        while(fgets(buf, BUF_SIZE, f)) {
            buf[strcspn(buf, "\r\n")] = '\0';
            if (!strgrp_add(ctx, buf, NULL)) {
                printf("Failed to classify %s\n", buf);
            }
        }
        strgrp_free(ctx);
        free(buf);
        fclose(f);
        return 0;
    }

[1] https://en.wikipedia.org/wiki/Cosine_similarity
[2] https://en.wikipedia.org/wiki/Longest_common_subsequence_problem

4 years agoaga: Error codes
David Gibson [Tue, 3 Nov 2015 03:20:14 +0000 (14:20 +1100)]
aga: Error codes

Add an enum to record error codes for aga routines.  The current
algorithms, dfs and bfs don't have any error conditions except those
reported by callbacks.  So, for now, the only code is "no error", but this
will be expanded in future.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoaga: Fix initialization bug in aga_for_each_edge_info
David Gibson [Tue, 3 Nov 2015 02:01:07 +0000 (13:01 +1100)]
aga: Fix initialization bug in aga_for_each_edge_info

The aga_for_each_edge_info macro is constructed so that if the edge_info
callback returns an error, the for loop terminates early and leaves the
_err parameter set to the error.  On successful completion of the loop,
_err should be zero.

However, on a node with no edges, _err will not be initialized, meaning
that it could be non-zero even on successful (trivial) completion of the
loop.  This fixes the bug.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoaga: Add function block comments
David Gibson [Mon, 2 Nov 2015 23:48:19 +0000 (10:48 +1100)]
aga: Add function block comments

Add block comments in the usual ccan format describing a number of the
important functions in the aga module.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agolpq: New module
David Gibson [Tue, 27 Oct 2015 11:10:27 +0000 (22:10 +1100)]
lpq: New module

Simple, slow priority queue implementation.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agolqueue: Streamline interface with TCON_CONTAINER
David Gibson [Tue, 20 Oct 2015 04:12:55 +0000 (15:12 +1100)]
lqueue: Streamline interface with TCON_CONTAINER

The interfaces the lqueue module currently has implement (partial) type
safety in a somewhat clunky way - types and member names need to be passed
to a number of entry points.

This patch uses the new TCON_CONTAINER magic to stash the typing
information into the declaration of the queue object, so it no longer needs
to be explicitly passed to later calls.

This does alter the lqueue interface incompatibly.  I think the module
is young enough that we can reasonably do that.  One other module,
'aga', was using lqueue, and this also includes fixes so that it still
works.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agolstack: Streamline interface with TCON_CONTAINER
David Gibson [Tue, 20 Oct 2015 03:34:02 +0000 (14:34 +1100)]
lstack: Streamline interface with TCON_CONTAINER

The interfaces the lstack module currently has implement (partial) type
safety in a somewhat clunk way - types and member names need to be passed
to a number of entry points.

This patch uses the new TCON_CONTAINER magic to stash the typing
information into the declaration of the stack object, so it no longer needs
to be explicitly passed to later calls.

This does alter the lstack interface incompatibly.  I think the module
is young enough that we can reasonably do that.  One other module,
'aga', was using lstack, and this also includes fixes so that it still
works.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agotcon: Encode information on container members in "type" canaries
David Gibson [Tue, 20 Oct 2015 02:18:17 +0000 (13:18 +1100)]
tcon: Encode information on container members in "type" canaries

Add "container canaries" to tcon.  This allows information about a specific
member of a container structure to be encoded with TCON or TCON_WRAP.  Once
that's done, tcon_container_of() and tcon_member_of() can be used to
translate between member and container pointers based on the canary
information, without having to repeat the type and member details.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agotcon: Encode integer values into "type" canaries
David Gibson [Tue, 20 Oct 2015 01:34:30 +0000 (12:34 +1100)]
tcon: Encode integer values into "type" canaries

Add the ability to encode, as well as types, integer values (must be
positive, compile time constant and in the range of size_t) into TCON
constructed "type" canaries.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agotcon: Add tcon_sizeof() helper
David Gibson [Mon, 19 Oct 2015 14:46:41 +0000 (01:46 +1100)]
tcon: Add tcon_sizeof() helper

Add a new tcon_sizeof() helper macro which returns the size of a type for
which a canary has been constructed with TCON or TCON_WRAP.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agotcon: Add an alternate way of building type canaries
David Gibson [Tue, 20 Oct 2015 03:23:37 +0000 (14:23 +1100)]
tcon: Add an alternate way of building type canaries

The tcon module allows you to add "type canaries" to a structures, which
can be used for later typechecks.  The canaries are implemented using
a flexible array member, to avoid them taking any actual space at runtime.
That means the canaries must go at the end of your structure.

That doesn't seem like a big limitation, except that it also means the
structure containing the canaries must be at the end of any structure it
is embedded in in turn, which is a rather more serious limitation.

This patch adds a TCON_WRAP() macro which wraps a given type in a new type
which also contains type canaries, and doesn't suffer the last member
limitation.  The drawback is that if the wrapped type has smaller size than
a pointer, the type canaries will pad the wrapped type out to the size of a
pointer.

By constructing the wrappers carefully, the existing tcon macros will work
on both wrapper types constructed with TCON_WRAP and on structures
explicitly including TCON type canaries.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agolstack, lqueue: Move from MODS_WITH_SRC to MODS_NO_SRC
David Gibson [Sun, 25 Oct 2015 12:30:55 +0000 (23:30 +1100)]
lstack, lqueue: Move from MODS_WITH_SRC to MODS_NO_SRC

The lstack and lqueue modules are entirely implemented in a single header.
However, in Makefile-ccan they're listed in MODS_WITH_SRC, instead of
MODS_NO_SRC.  This appears to be harmless, but this patch moves them to
the correct category anyway.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoptrint: ptr2int and int2ptr are constant functions
David Gibson [Sun, 25 Oct 2015 12:00:06 +0000 (23:00 +1100)]
ptrint: ptr2int and int2ptr are constant functions

By construction these functions depend only on their arguments, so declare
them as CONST_FUNCTION using the helper from ccan/compiler.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoFixing odd formatting of info caused by unnecessary indentations.
Paul Wayper [Wed, 21 Oct 2015 21:07:15 +0000 (08:07 +1100)]
Fixing odd formatting of info caused by unnecessary indentations.

4 years agoopt: don't use raw malloc for errors.
Rusty Russell [Wed, 21 Oct 2015 05:35:49 +0000 (16:05 +1030)]
opt: don't use raw malloc for errors.

We should be allocating them with opt's allocator (we use it to free them!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agomem: switch descriptions for memeqzero/memeqstr
Rusty Russell [Tue, 20 Oct 2015 03:17:59 +0000 (13:47 +1030)]
mem: switch descriptions for memeqzero/memeqstr

Closes: #32
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoRemove stale file ccan/priority_queue/test/run.c
David Gibson [Sun, 18 Oct 2015 10:45:01 +0000 (21:45 +1100)]
Remove stale file ccan/priority_queue/test/run.c

In commit 3782543 "order: Scalar comparison functions", I accidentally
checked in a file which didn't belong with that commit, and was actually
from a module I was experimenting with but wasn't ready to commit.

This cleans up the bogus extra file.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoorder: total_order_cmp() helper and better tests
David Gibson [Sun, 18 Oct 2015 10:10:58 +0000 (21:10 +1100)]
order: total_order_cmp() helper and better tests

Add a wrapper macro total_order_cmp() to more conveniently use the
total_order structures.  Add some tests for it, which also improve tests
the "fancy_cmp" function.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agotal/str: fix error in tal_strndup()
Rusty Russell [Fri, 16 Oct 2015 19:42:40 +0000 (06:12 +1030)]
tal/str: fix error in tal_strndup()

It used strlen() on the source, which might not be valid.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agomem: get clever with memeqzero().
Rusty Russell [Thu, 15 Oct 2015 05:10:15 +0000 (15:40 +1030)]
mem: get clever with memeqzero().

Best of both worlds.

Before:
1: 6ns
2: 7ns
4: 7ns
8: 7ns
16: 7ns
32: 8ns
64: 9ns
128: 13ns
256: 24ns
512: 47ns
1024: 92ns
2048: 185ns
4096: 376ns
8192: 739ns
16384: 1463ns
32768: 2914ns
65536: 5800ns
2: 7ns
3: 7ns
5: 7ns
9: 7ns
17: 7ns
33: 8ns
65: 9ns
129: 20ns
257: 31ns
513: 49ns
1025: 96ns
2049: 189ns
4097: 381ns
8193: 745ns
16385: 1477ns
32769: 2930ns
65537: 5824ns
total = 599391004

After:
1: 3ns
2: 3ns
4: 4ns
8: 5ns
16: 12ns
32: 13ns
64: 15ns
128: 19ns
256: 25ns
512: 35ns
1024: 57ns
2048: 105ns
4096: 183ns
8192: 324ns
16384: 607ns
32768: 1317ns
65536: 2774ns
2: 3ns
3: 3ns
5: 4ns
9: 6ns
17: 11ns
33: 13ns
65: 14ns
129: 19ns
257: 24ns
513: 35ns
1025: 57ns
2049: 106ns
4097: 183ns
8193: 324ns
16385: 607ns
32769: 1315ns
65537: 2773ns
total = 599391004

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agomem: optimize.
Rusty Russell [Thu, 15 Oct 2015 04:20:34 +0000 (14:50 +1030)]
mem: optimize.

Better for larger, worse for smaller compares.

Before:
1: 3ns
2: 3ns
4: 5ns
8: 9ns
16: 11ns
32: 33ns
64: 45ns
128: 87ns
256: 157ns
512: 296ns
1024: 579ns
2048: 1139ns
4096: 2251ns
8192: 4505ns
16384: 9704ns
32768: 18482ns
65536: 36144ns
2: 4ns
3: 6ns
5: 8ns
9: 9ns
17: 12ns
33: 22ns
65: 45ns
129: 90ns
257: 175ns
513: 357ns
1025: 607ns
2049: 1204ns
4097: 2278ns
8193: 4552ns
16385: 9011ns
32769: 18405ns
65537: 36153ns
total = 599391004

After:
1: 6ns
2: 7ns
4: 7ns
8: 7ns
16: 7ns
32: 8ns
64: 9ns
128: 13ns
256: 24ns
512: 47ns
1024: 92ns
2048: 185ns
4096: 376ns
8192: 739ns
16384: 1463ns
32768: 2914ns
65536: 5800ns
2: 7ns
3: 7ns
5: 7ns
9: 7ns
17: 7ns
33: 8ns
65: 9ns
129: 20ns
257: 31ns
513: 49ns
1025: 96ns
2049: 189ns
4097: 381ns
8193: 745ns
16385: 1477ns
32769: 2930ns
65537: 5824ns
total = 599391004

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agomem: add memzero benchmark.
Rusty Russell [Thu, 15 Oct 2015 03:48:47 +0000 (14:18 +1030)]
mem: add memzero benchmark.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agomem: add memeqzero.
Rusty Russell [Thu, 15 Oct 2015 03:29:43 +0000 (13:59 +1030)]
mem: add memeqzero.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoTravis: do make in parallel to test if that gives slight speedup.
Rusty Russell [Fri, 9 Oct 2015 02:05:28 +0000 (12:35 +1030)]
Travis: do make in parallel to test if that gives slight speedup.

Seems to.  Numbers are noisy, but before was 5 min 32 sec, after this
commit was 3 min 42 sec.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoTravis: upgrade, try using apt dependencies.
Rusty Russell [Fri, 9 Oct 2015 01:43:58 +0000 (12:13 +1030)]
Travis: upgrade, try using apt dependencies.

I've filed bugs to get those dev packages whitelisted:
  https://github.com/travis-ci/apt-package-whitelist/issues/1366
  https://github.com/travis-ci/apt-package-whitelist/issues/1367
  https://github.com/travis-ci/apt-package-whitelist/issues/1368
  https://github.com/travis-ci/apt-package-whitelist/issues/1369

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoccanlint: enhance and streamline "output" testing lines.
Rusty Russell [Mon, 28 Sep 2015 03:14:40 +0000 (12:44 +0930)]
ccanlint: enhance and streamline "output" testing lines.

1) Require "" around input
2) Make them optional around output: if not there, loose match whitespace
3) Handle \n in output.
4) Document that "Given xxx" is optional.
5) Reject any non-matching comment lines starting with "given" or "outputs"
6) Fix missed test in ccan/cast

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agopermutation: Generate permutations of arrays
David Gibson [Mon, 28 Sep 2015 14:59:17 +0000 (00:59 +1000)]
permutation: Generate permutations of arrays

New module.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agomem: add memcheck() for valgrind.
Rusty Russell [Thu, 24 Sep 2015 02:19:40 +0000 (11:49 +0930)]
mem: add memcheck() for valgrind.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoconfigurator: check for valgrind/memcheck.h
Rusty Russell [Thu, 24 Sep 2015 01:50:56 +0000 (11:20 +0930)]
configurator: check for valgrind/memcheck.h

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agostrgrp: Fix compile errors in example
David Gibson [Mon, 14 Sep 2015 11:06:11 +0000 (21:06 +1000)]
strgrp: Fix compile errors in example

Commit 63f13d6 "strgrp: Tidy up kerneldoc in _info" introduced some compile
errors into the example in strgrp/_info.  This fixes them.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agomem: Add memswap() function
David Gibson [Wed, 9 Sep 2015 11:27:32 +0000 (21:27 +1000)]
mem: Add memswap() function

Add a memswap() function to the mem module, which exchanges two (equal
sized, non-overlapping) memory regions.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agomem: Add function to check whether memory ranges overlap
David Gibson [Wed, 9 Sep 2015 08:04:33 +0000 (18:04 +1000)]
mem: Add function to check whether memory ranges overlap

The test is simple, but every time I do it by hand, I always spend ages
convincing myself it's actually correct.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agomem: Remove array_size dependency
David Gibson [Sat, 5 Sep 2015 04:32:24 +0000 (14:32 +1000)]
mem: Remove array_size dependency

The mem module declares array_size as a test dependency, and includes it in
test/api.c, but doesn't actually use it.  This removes the unneeded
dependency.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agostrgrp: Tidy up kerneldoc in _info
Andrew Jeffery [Fri, 11 Sep 2015 12:10:43 +0000 (21:40 +0930)]
strgrp: Tidy up kerneldoc in _info

The documentation as it stood rendered badly in HTML due to a lack of
knowledge of kerneldoc formatting.

4 years agostrgrp: Optionally include OpenMP pragma
Andrew Jeffery [Sat, 5 Sep 2015 14:33:05 +0000 (00:03 +0930)]
strgrp: Optionally include OpenMP pragma

4 years agoccanlint: Add cflags support to _info
Andrew Jeffery [Sat, 5 Sep 2015 13:00:43 +0000 (22:30 +0930)]
ccanlint: Add cflags support to _info

4 years agoconfigurator: Add OpenMP detection
Andrew Jeffery [Sat, 5 Sep 2015 14:09:59 +0000 (23:39 +0930)]
configurator: Add OpenMP detection

4 years agostrgrp: new module
Andrew Jeffery [Thu, 20 Aug 2015 06:16:31 +0000 (15:46 +0930)]
strgrp: new module

4 years agomem: add memends_str() helper for symmetry
Cody P Schafer [Sun, 6 Sep 2015 01:21:06 +0000 (21:21 -0400)]
mem: add memends_str() helper for symmetry

Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agomem: mark all functions as PURE
Cody P Schafer [Sun, 6 Sep 2015 01:21:05 +0000 (21:21 -0400)]
mem: mark all functions as PURE

This might allow compilers that support the anotation to make better
choices when optimizing, and all these functions meet the requirements
for being marked pure.

Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agobytestring: use newly added mem helpers
Cody P Schafer [Sun, 6 Sep 2015 01:21:04 +0000 (21:21 -0400)]
bytestring: use newly added mem helpers

Reviwed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agomem: add mem helper functions
Cody P Schafer [Sun, 6 Sep 2015 01:21:03 +0000 (21:21 -0400)]
mem: add mem helper functions

Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agoarray_size: fix spurious test fail with gcc-5
Rusty Russell [Thu, 20 Aug 2015 01:39:44 +0000 (11:09 +0930)]
array_size: fix spurious test fail with gcc-5

It now warns about sizeof(function-param-not-really-an-array).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agopr_log: a new module that provides a simple run-time controlled logging interface
Cody P Schafer [Wed, 19 Aug 2015 02:29:54 +0000 (22:29 -0400)]
pr_log: a new module that provides a simple run-time controlled logging interface

A simple printf logging infra where levels are determined by the
value of the "DEBUG" environment variable.

This is loosely based on the interfaces & functionality of Linux's
printk() and pr_*() wrapper macros.

Note that the current implementation uses "<N>" prefixes (where N is a
syslog level in ascii), allowing other programs that parse log output
(like systemd's journald) to know what the priority level is.

Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agolist: suppress unused argument warnings
Cody P Schafer [Sun, 16 Aug 2015 22:33:48 +0000 (18:33 -0400)]
list: suppress unused argument warnings

Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoconfigurator: avoid potential unused parameter warnings hosing our config.h
Cody P Schafer [Sun, 16 Aug 2015 22:54:39 +0000 (18:54 -0400)]
configurator: avoid potential unused parameter warnings hosing our config.h

Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoconfigurator: sometimes _GNU_SOURCE is already defined, in those cases avoid redefinition
Cody P Schafer [Sun, 16 Aug 2015 22:54:38 +0000 (18:54 -0400)]
configurator: sometimes _GNU_SOURCE is already defined, in those cases avoid redefinition

Config defines are disabled if a warning is emitted (we may want to
reconsider that), and warnings are emitted for define redefinition.

Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoconfigurator: hide type punning
Cody P Schafer [Sun, 16 Aug 2015 22:54:37 +0000 (18:54 -0400)]
configurator: hide type punning

As for the type punning: gcc-5.1 with optimization (at least) warns about type punning in
the previous example. The new usage should be exactly equivalent to the
old, but just seperates the cast and deref into 2 statements. Frankly,
I'm suprised gcc's type-punning analysis is so limited.

Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agobytestring: Add rational comment to testcase
David Gibson [Tue, 18 Aug 2015 23:17:02 +0000 (16:17 -0700)]
bytestring: Add rational comment to testcase

Reviewing the previous patch it took me some time to work out what the
purpose of the compile_fail-BYTESTRING-2.c test.  Add a comment to avoid
that in future.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agobytestring: avoid compile_fail failure due to uninitialized warning
Cody P Schafer [Tue, 18 Aug 2015 00:33:31 +0000 (20:33 -0400)]
bytestring: avoid compile_fail failure due to uninitialized warning

bytestring: Module tests compile (tests_compile): FAIL
/home/x/g/ccc/ccan/ccan/bytestring/test/compile_fail-BYTESTRING-2.c:Compile gave warnings without -DFAIL:
/home/x/g/ccc/ccan/ccan/bytestring/test/compile_fail-BYTESTRING-2.c: In function ‘main’:
/home/x/g/ccc/ccan/ccan/bytestring/test/compile_fail-BYTESTRING-2.c:15:2: warning: ‘bs.len’ is used uninitialized in this function [-Wuninitialized]
  printf("%zd %s\n", bs.len, x);
  ^

Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agotalloc: avoid a comparison mismatch & at the same time switch to non-legacy sysconf()
Cody P Schafer [Sun, 16 Aug 2015 22:58:32 +0000 (18:58 -0400)]
talloc: avoid a comparison mismatch & at the same time switch to non-legacy sysconf()

Without this, gcc warns about a sign mismatch in the comparison.

Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoconfigurator: avoid leaks that LeakSanitizer doesn't like
Cody P Schafer [Sun, 16 Aug 2015 22:54:37 +0000 (18:54 -0400)]
configurator: avoid leaks that LeakSanitizer doesn't like

These leaks aren't really an issue since they are completely bounded,
but if one is building with leak sanitizer enabled (as
-fsanitize=address does in gcc-5.1), it kills the configurator, which
isn't very useful for us. Add the few free() calls it's looking for.

This is not an actual code issue, they just workaround
some optional compiler peculiarities.

Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (split off leak change)
4 years agocpuid: update inline docs
A. Samy [Sat, 15 Aug 2015 01:13:01 +0000 (01:13 +0000)]
cpuid: update inline docs

Signed-off-by: A. Samy <f.fallen45@gmail.com>
4 years agocpuid: use a hardcoded constant when comparing CPU names
A. Samy [Sat, 15 Aug 2015 01:06:12 +0000 (01:06 +0000)]
cpuid: use a hardcoded constant when comparing CPU names

Signed-off-by: A. Samy <f.fallen45@gmail.com>
4 years agocpuid: fix test.
Rusty Russell [Fri, 14 Aug 2015 00:24:40 +0000 (09:54 +0930)]
cpuid: fix test.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agocpuid: namespacize some functions and define them as null if unsupported
A. Samy [Tue, 11 Aug 2015 05:21:42 +0000 (05:21 +0000)]
cpuid: namespacize some functions and define them as null if unsupported

4 years agocpuid: cpuid_write_info(): have outfile a file pointer instead
A. Samy [Tue, 11 Aug 2015 05:14:57 +0000 (05:14 +0000)]
cpuid: cpuid_write_info(): have outfile a file pointer instead

4 years agocpuid: rename ___cpuid to get_cpuid
A. Samy [Tue, 11 Aug 2015 05:10:15 +0000 (05:10 +0000)]
cpuid: rename ___cpuid to get_cpuid

4 years agocpuid: minor clean up
A. Samy [Tue, 11 Aug 2015 05:09:32 +0000 (05:09 +0000)]
cpuid: minor clean up

4 years agoMakefile-ccan: add new modules.
Rusty Russell [Wed, 12 Aug 2015 02:33:01 +0000 (12:03 +0930)]
Makefile-ccan: add new modules.

I really need to get rid of this...

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agoagar: Re-entrant Abstract Graph Algorithms
David Gibson [Fri, 17 Jul 2015 14:54:44 +0000 (00:54 +1000)]
agar: Re-entrant Abstract Graph Algorithms

New module

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
5 years agoaga: Add lazytrie testcase
David Gibson [Mon, 11 May 2015 10:35:34 +0000 (22:35 +1200)]
aga: Add lazytrie testcase

This adds a more complex testcase to the aga module.  This one is a trie
(basically a radix tree for strings).

It demonstrates different ways of constructing edge information from an
internal representation than the existing testcases.  Importantly, it also
demonstrates aga's ability to cope with the edge function lazily
constructing nodes on the fly.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
5 years agoaga: Testcase for attempt to run concurrent algorithms
David Gibson [Thu, 7 May 2015 11:29:19 +0000 (21:29 +1000)]
aga: Testcase for attempt to run concurrent algorithms

The aga algorithms can't be run concurrently, because they store state
information in the aga_node structures.  However, they are supposed to
detect an attempt to re-enter and safely report an error.  This adds a
testcase for this.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
5 years agoaga: Breadth first search
David Gibson [Sat, 13 Jun 2015 15:33:23 +0000 (01:33 +1000)]
aga: Breadth first search

This implements breadth first search for the abstract graph algorithms
module.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
5 years agoaga: Depth first search
David Gibson [Sat, 13 Jun 2015 15:34:40 +0000 (01:34 +1000)]
aga: Depth first search

This implements depth first search for the abstract graph algorithms
module.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
5 years agoaga: Simple test graphs
David Gibson [Thu, 21 May 2015 09:23:19 +0000 (21:23 +1200)]
aga: Simple test graphs

This adds code for a number of example graphs for use in tests of the aga
module.  They also demonstrate several different ways of constructing
graphs using the aga callbacks.

It adds one actual testcase, which just verifies that the example graph
look like what they're supposed to.  Specifically it computes a set of
adjacency lists for the example graphs from the callback code, then
compares that to a canned example of what it should be.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
5 years agoaga: Abstract Graph Algorithms
David Gibson [Tue, 21 Jul 2015 11:38:22 +0000 (21:38 +1000)]
aga: Abstract Graph Algorithms

New module.

This patch just adds the module, with some generic helper routines, no
actual algorithms are implemented yet.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
5 years agodaemonize: check setsid() return value
Maxim Zakharov [Thu, 30 Jul 2015 01:58:36 +0000 (11:58 +1000)]
daemonize: check setsid() return value

5 years agodaemonize: exit parent without triggering atexit() processing
Maxim Zakharov [Thu, 30 Jul 2015 01:49:20 +0000 (11:49 +1000)]
daemonize: exit parent without triggering atexit() processing

5 years agoshort_types: Fix warning in test
Joel Stanley [Mon, 20 Jul 2015 06:01:23 +0000 (15:31 +0930)]
short_types: Fix warning in test

Our project builds the ccan tests with -Wextra, so we get warnings about
the unused variables.

Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agotools/modfiles: include _info (unless requested not to)
Rusty Russell [Thu, 9 Jul 2015 05:31:01 +0000 (15:01 +0930)]
tools/modfiles: include _info (unless requested not to)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agotools/create-ccan-tree: clean up modfiles binary after use.
Rusty Russell [Thu, 9 Jul 2015 05:28:50 +0000 (14:58 +0930)]
tools/create-ccan-tree: clean up modfiles binary after use.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agotools/create-ccan-tree: fix nested modules with -a
Rusty Russell [Thu, 9 Jul 2015 05:20:27 +0000 (14:50 +0930)]
tools/create-ccan-tree: fix nested modules with -a

The cp -a would copy nested submodules, and worse, if that submodule
was copied later it would end up duplicated in a subdir,
eg. "ccan/tal/str/str/".

Using modfiles handles this properly, and also uses git to filter
out ignored files & other junk.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agotools/modfiles: list files in a module.
Rusty Russell [Thu, 9 Jul 2015 05:04:56 +0000 (14:34 +0930)]
tools/modfiles: list files in a module.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agotools: include LICENSE file in manifest.
Rusty Russell [Thu, 9 Jul 2015 05:04:05 +0000 (14:34 +0930)]
tools: include LICENSE file in manifest.

It's generally a symlink, so the lstat & S_ISREG tests were eliminating it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agotools: don't include submodules in manifest.
Rusty Russell [Thu, 9 Jul 2015 02:56:48 +0000 (12:26 +0930)]
tools: don't include submodules in manifest.

They currently get classed as "other_files"; they should be entirely
ignored.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agocrypto/sha256: add license file for intel code in benchmarks/
Rusty Russell [Thu, 9 Jul 2015 01:05:10 +0000 (10:35 +0930)]
crypto/sha256: add license file for intel code in benchmarks/

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agoMakefile-ccan: add order to MOD list.
Rusty Russell [Wed, 8 Jul 2015 06:37:11 +0000 (16:07 +0930)]
Makefile-ccan: add order to MOD list.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agocrypto/ripemd160: new module.
Rusty Russell [Wed, 8 Jul 2015 06:34:50 +0000 (16:04 +0930)]
crypto/ripemd160: new module.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agocrypto/sha256: fix up CCAN_CRYPTO_SHA256_USE_OPENSSL implementation.
Rusty Russell [Wed, 8 Jul 2015 06:33:29 +0000 (16:03 +0930)]
crypto/sha256: fix up CCAN_CRYPTO_SHA256_USE_OPENSSL implementation.

sha256_update_bytes is sha256_update since f989a43b55795c04a6225b392f3f58afd2cd6543.

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