]> git.ozlabs.org Git - ccan/log
ccan
15 months agobase64: fix for unsigned chars (e.g. ARM).
Rusty Russell [Tue, 1 Aug 2023 01:43:53 +0000 (11:13 +0930)]
base64: fix for unsigned chars (e.g. ARM).

```
ccan/ccan/base64/base64.c:34:10: error: result of comparison of constant 255 with expression of type 'int8_t' (aka 'signed char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
        if (ret == (char)0xff) {
            ~~~ ^  ~~~~~~~~~~
ccan/ccan/base64/base64.c:44:57: error: result of comparison of constant 255 with expression of type 'const signed char' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
        return (maps->decode_map[(const unsigned char)b64char] != (char)0xff);
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~
```

Reported-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
17 months agoopt: allow show callbacks to return false.
Rusty Russell [Mon, 8 May 2023 01:30:31 +0000 (11:00 +0930)]
opt: allow show callbacks to return false.

Sometimes, arguments are optional, so it's useful to decide at runtime
whether to print a default in --help.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
17 months agoccan: update show callback to take explicit length.
Rusty Russell [Mon, 8 May 2023 01:30:26 +0000 (11:00 +0930)]
ccan: update show callback to take explicit length.

For now we still use 80, but we could vary that in future.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
17 months agoccan: allow user to set some bits in opt_table.type.
Rusty Russell [Mon, 8 May 2023 01:30:22 +0000 (11:00 +0930)]
ccan: allow user to set some bits in opt_table.type.

In particular, Core Lightning wants to use this to flag arguments
which can be specified multiple times (without overriding).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
17 months agoccan: break out routine to parse a single long argument.
Rusty Russell [Mon, 8 May 2023 01:27:41 +0000 (10:57 +0930)]
ccan: break out routine to parse a single long argument.

Core Lightning (ab)uses opt for config file parsing; this makes
that quite a bit neater!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
17 months agoccan: add test that second arg in multiple arg string is correctly reported.
Rusty Russell [Sat, 29 Apr 2023 06:11:13 +0000 (15:41 +0930)]
ccan: add test that second arg in multiple arg string is correctly reported.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
17 months agoconfigurator: increase stack size in HAVE_POINTER_SAFE_MAKECONTEXT test
Rusty Russell [Tue, 20 Jun 2023 03:00:32 +0000 (12:30 +0930)]
configurator: increase stack size in HAVE_POINTER_SAFE_MAKECONTEXT test

This was *hanging* on GitHub's CI (Ubuntu 22.04) with clang.  The increase
seems to have fixed it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
17 months agorunes: allow underscores in field names, as per Python runes 0.6
Rusty Russell [Tue, 30 May 2023 03:03:07 +0000 (12:33 +0930)]
runes: allow underscores in field names, as per Python runes 0.6

Suggested-by: @niftynei
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
17 months agotal: remove undefined behavior.
Rusty Russell [Wed, 22 Mar 2023 02:12:18 +0000 (12:42 +1030)]
tal: remove undefined behavior.

In particular, we were casting between struct prop_hdr ** and char **:
fixing this properly was quite a rework.

And in one case we were using a pre-realloc pointer in tests: though to be
fair, we tested it for equality.  But ubsan got upset anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
18 months agoungraph: new module
Rusty Russell [Thu, 2 Jun 2022 08:32:09 +0000 (18:02 +0930)]
ungraph: new module

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
18 months agotcon: fix warning when it's used with NULL on some gcc versions.
Rusty Russell [Mon, 9 Jan 2023 02:06:22 +0000 (12:36 +1030)]
tcon: fix warning when it's used with NULL on some gcc versions.

Seems to be happening with gcc 12.2.0-3ubuntu1:

```
lightningd/jsonrpc.c: In function ‘destroy_json_command’:
lightningd/jsonrpc.c:1180:63: error: the comparison will always evaluate as ‘false’ for the address of ‘canary’ will never be NULL [-Werror=address]
lightningd/jsonrpc.c:108:53: note: ‘canary’ declared here
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agofdpass: avoid memory leak in example.
Rusty Russell [Mon, 9 Jan 2023 02:23:22 +0000 (12:53 +1030)]
fdpass: avoid memory leak in example.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agostringbuilder: avoid overwriting end of buffer with nul terminator.
Rusty Russell [Mon, 9 Jan 2023 02:22:22 +0000 (12:52 +1030)]
stringbuilder: avoid overwriting end of buffer with nul terminator.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agotally: avoid complaints about bitshifts on giant bucket sizes.
Rusty Russell [Mon, 9 Jan 2023 02:21:22 +0000 (12:51 +1030)]
tally: avoid complaints about bitshifts on giant bucket sizes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agoobjset: avoid memleak report in example.
Rusty Russell [Mon, 9 Jan 2023 02:20:22 +0000 (12:50 +1030)]
objset: avoid memleak report in example.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agorbuf: avoid doing memchr(NULL, ..., 0).
Rusty Russell [Mon, 9 Jan 2023 02:19:22 +0000 (12:49 +1030)]
rbuf: avoid doing memchr(NULL, ..., 0).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agoopt: avoid bad access on empty usage message, free all mem in tests.
Rusty Russell [Mon, 9 Jan 2023 02:18:22 +0000 (12:48 +1030)]
opt: avoid bad access on empty usage message, free all mem in tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agomembuf: avoid buffer overrun in example code, memleak.
Rusty Russell [Mon, 9 Jan 2023 02:17:22 +0000 (12:47 +1030)]
membuf: avoid buffer overrun in example code, memleak.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agoidtree: make sanitizer happier about shifts.
Rusty Russell [Mon, 9 Jan 2023 02:16:22 +0000 (12:46 +1030)]
idtree: make sanitizer happier about shifts.

```
/home/rusty/devel/cvs/ccan/ccan/idtree/test/run-wrap.c:/home/rusty/devel/cvs/ccan/ccan/idtree/idtree.c:76:21: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agoversion: fix version() function.
Rusty Russell [Mon, 9 Jan 2023 02:15:22 +0000 (12:45 +1030)]
version: fix version() function.

```
/home/rusty/devel/cvs/ccan/ccan/version/test/run.c:/home/rusty/devel/cvs/ccan/ccan/version/version.h:58:35: runtime error: left shift of 65535 by 16 places cannot be represented in type 'int'
```

20 months agoconfigurator: fix bitshift tests (-fsanitize=undefined)
Rusty Russell [Mon, 9 Jan 2023 02:14:22 +0000 (12:44 +1030)]
configurator: fix bitshift tests (-fsanitize=undefined)

```
configuratortest.c:5:24: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agoantithread, htable, ilog: more misc sanitizer complaints.
Rusty Russell [Mon, 9 Jan 2023 02:13:22 +0000 (12:43 +1030)]
antithread, htable, ilog: more misc sanitizer complaints.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agofailtest: avoid complaints about copying uninitializes memory.
Rusty Russell [Mon, 9 Jan 2023 02:12:22 +0000 (12:42 +1030)]
failtest: avoid complaints about copying uninitializes memory.

True, we don't actually use the "call", so omit it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agobytestring, crypto/hmac_sha256, darray, mem, tal: avoid mem* with NULL.
Rusty Russell [Mon, 9 Jan 2023 02:11:22 +0000 (12:41 +1030)]
bytestring, crypto/hmac_sha256, darray, mem, tal: avoid mem* with NULL.

I swear the C standards committee likes compilers more than they like
programmers :(

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agobitops: fix -fsanitize=undefined warning:
Rusty Russell [Mon, 9 Jan 2023 02:10:22 +0000 (12:40 +1030)]
bitops: fix -fsanitize=undefined warning:

```
/home/rusty/devel/cvs/ccan/ccan/bitops/test/run.c:28:3: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

bitops: Module's run and api tests pass (tests_pass): FAIL (+1/2)
/home/rusty/devel/cvs/ccan/ccan/bitops/test/run.c:1..632
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agotcon: fix overzealous gcc 12.2.0 warning.
Rusty Russell [Mon, 9 Jan 2023 02:09:22 +0000 (12:39 +1030)]
tcon: fix overzealous gcc 12.2.0 warning.

At least with -fsanitize=address -fno-sanitize-recover=address -fsanitize=undefined -fno-sanitize-recover=undefined:

```
/home/rusty/devel/cvs/ccan/ccan/tcon/test/compile_fail-container1.c:Compile gave warnings without -DFAIL:
In file included from /home/rusty/devel/cvs/ccan/ccan/tcon/test/compile_fail-container1.c:3:
/home/rusty/devel/cvs/ccan/ccan/tcon/tcon.h: In function ‘main’:
/home/rusty/devel/cvs/ccan/ccan/tcon/tcon.h:332:25: warning: ‘innerp’ may be used uninitialized [-Wmaybe-uninitialized]
  332 |                 canary, tcon_container_of_((member_ptr),                \
      |                         ^~~~~~~~~~~~~~~~~~
/home/rusty/devel/cvs/ccan/ccan/tcon/tcon.h:335:21: note: by argument 1 of type ‘const void *’ to ‘tcon_container_of_’ declared here
  335 | static inline void *tcon_container_of_(const void *member_ptr, size_t offset)
      |                     ^~~~~~~~~~~~~~~~~~
/home/rusty/devel/cvs/ccan/ccan/tcon/test/compile_fail-container1.c:28:22: note: ‘ovar’ declared here
   28 |         struct outer ovar;
      |                      ^~~~

tcon: Total score: 33/41 FAIL!
```

20 months agoccanlint: do fewer reallocs, to speed up under -fsanitize=address
Rusty Russell [Mon, 9 Jan 2023 02:08:22 +0000 (12:38 +1030)]
ccanlint: do fewer reallocs, to speed up under -fsanitize=address

This is just a hack, but it makes the speed managable for ccan/utf8
which produces a lot of output!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 months agoccanlint: fix use-after-free in verbose mode.
Rusty Russell [Mon, 9 Jan 2023 02:07:22 +0000 (12:37 +1030)]
ccanlint: fix use-after-free in verbose mode.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agorune: add helpers for users doing DIY parsing.
Rusty Russell [Thu, 18 Aug 2022 03:32:16 +0000 (13:02 +0930)]
rune: add helpers for users doing DIY parsing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agorune: avoid shadowing var in test/run.c
Rusty Russell [Thu, 18 Aug 2022 02:10:21 +0000 (11:40 +0930)]
rune: avoid shadowing var in test/run.c

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agorune: fix encoding of alternates which need escapes.
Rusty Russell [Thu, 18 Aug 2022 02:06:59 +0000 (11:36 +0930)]
rune: fix encoding of alternates which need escapes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agonet: fix gcc warning about mismatch.
Rusty Russell [Mon, 18 Jul 2022 12:30:17 +0000 (22:00 +0930)]
net: fix gcc warning about mismatch.

Header can't use pollfds[2] because type is unknown.  And gcc complains:

ccan/net/net.c:78:70: warning: argument 2 of type ‘struct pollfd[2]’ with mismatched bound [-Warray-parameter=]

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agoalloc: fix shadowed variable
Rusty Russell [Mon, 18 Jul 2022 12:29:51 +0000 (21:59 +0930)]
alloc: fix shadowed variable

Thanks -Wshadow=local!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agotal: fix shadowed variable name.
Rusty Russell [Mon, 18 Jul 2022 12:29:28 +0000 (21:59 +0930)]
tal: fix shadowed variable name.

Thanks -Wshadow=local!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agoMakefile: add -Wshadow=local, fix configurator!
Rusty Russell [Mon, 18 Jul 2022 12:28:20 +0000 (21:58 +0930)]
Makefile: add -Wshadow=local, fix configurator!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agoccan/base64: fix GCC warning.
Rusty Russell [Wed, 6 Jul 2022 05:10:20 +0000 (14:40 +0930)]
ccan/base64: fix GCC warning.

```
ccan/ccan/base64/base64.c:146:71: error: argument 2 of type ‘char[3]’ with mismatched bound [-Werror=array-parameter=]
  146 | ssize_t base64_decode_tail_using_maps(const base64_maps_t *maps, char dest[3],
      |                                                                  ~~~~~^~~~~~~
In file included from ccan/ccan/base64/base64.c:2:
ccan/ccan/base64/base64.h:119:72: note: previously declared as ‘char *’
  119 | ssize_t base64_decode_tail_using_maps(const base64_maps_t *maps, char *dest,
      |                                                                  ~~~~~~^~~~
cc1: all warnings being treated as errors
make: *** [Makefile:817: ccan-base64.o] Error 1
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agoccan/rune: compile without warnings on -O3.
Rusty Russell [Mon, 4 Jul 2022 00:11:57 +0000 (09:41 +0930)]
ccan/rune: compile without warnings on -O3.

```
ccan/ccan/rune/rune.c: In function ‘rune_alt_single_int’:
ccan/ccan/rune/rune.c:257:5: error: ‘runeval_int’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  257 |  if (cond)
      |     ^
ccan/ccan/rune/rune.c:305:6: note: ‘runeval_int’ was declared here
  305 |  s64 runeval_int;
      |      ^~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:919: ccan-rune-rune.o] Error 1
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agoccan/rune: simplify check helper interfaces, allow explicit string lengths.
Rusty Russell [Sat, 2 Jul 2022 05:36:14 +0000 (15:06 +0930)]
ccan/rune: simplify check helper interfaces, allow explicit string lengths.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agoccan/rune: add explicit-length variants.
Rusty Russell [Sat, 2 Jul 2022 01:01:14 +0000 (10:31 +0930)]
ccan/rune: add explicit-length variants.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agoccan/rune: fix take() logic which caused memory leaks.
Rusty Russell [Fri, 1 Jul 2022 07:25:33 +0000 (16:55 +0930)]
ccan/rune: fix take() logic which caused memory leaks.

You have to tal_steal() if you want to keep it!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agoccan/io: add debugging helper for seeing if module is in charge of an fd.
Rusty Russell [Thu, 30 Jun 2022 05:42:35 +0000 (15:12 +0930)]
ccan/io: add debugging helper for seeing if module is in charge of an fd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agostrmap: add strmap_getn for non-terminated string search.
Rusty Russell [Sun, 26 Jun 2022 05:42:33 +0000 (15:12 +0930)]
strmap: add strmap_getn for non-terminated string search.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agoio: fix typo in example.
Rusty Russell [Thu, 23 Jun 2022 04:41:58 +0000 (14:11 +0930)]
io: fix typo in example.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agorune: new module to implement runes.
Rusty Russell [Thu, 23 Jun 2022 04:37:37 +0000 (14:07 +0930)]
rune: new module to implement runes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agohtable: opportunistically avoid delete marker.
Rusty Russell [Fri, 17 Jun 2022 04:34:14 +0000 (14:04 +0930)]
htable: opportunistically avoid delete marker.

Fairly cheap test, we can see a drop in initial re-inserting, probably
because it has just been cleaned at this point with the old code, but
generally we do better with churn.

I also tried a variant which only checked if next bucket was on same
cacheline, but no significant difference.

5 runs of tools/speed 10000000:

```
-Initial re-inserting: 88-99(94.6+/-5) ns
+Initial re-inserting: 104-116(107.2+/-4.4) ns
-Adding (a different) half: 94-101(98.6+/-3) ns
+Adding (a different) half: 38-44(39.8+/-2.1) ns
-Lookup after half-change (miss): 90-105(96.4+/-5.7) ns
+Lookup after half-change (miss): 112-118(113.4+/-2.3) ns
-Churning third time: 301-323(314.4+/-9.8) ns
+Churning third time: 233-259(239+/-10) ns
-Details: worst run 146 (24 deleted)
+Details: worst run 115 (2 deleted)
-Lookup after churn & spread (match): 78-87(83.6+/-4.2) ns
+Lookup after churn & spread (match): 71-81(73.6+/-3.8) ns
-Lookup after churn & spread (miss): 118-137(124.2+/-6.9) ns
+Lookup after churn & spread (miss): 93-104(95.4+/-4.3) ns
-Adding (a different) half after churn & spread: 81-89(85.4+/-3.6) ns
+Adding (a different) half after churn & spread: 38-43(39.6+/-1.7) ns
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agohtable: increase density from 75% to 87.5%
Rusty Russell [Fri, 17 Jun 2022 04:33:53 +0000 (14:03 +0930)]
htable: increase density from 75% to 87.5%

Across all benchmarks (on various sizes) this actually drops
performance by 3%.  However, density increasing by 15% is probably a
worthwhile tradeoff.

```
-Initial insert: 227-237(230+/-3.7) ns
+Initial insert: 266-281(273.4+/-6.5) ns
-Initial lookup (match): 65-66(65.4+/-0.49) ns
+Initial lookup (match): 67-78(70.6+/-3.8) ns
-Initial lookup (miss): 79-80(79.4+/-0.49) ns
+Initial lookup (miss): 82-93(84.8+/-4.2) ns
-Initial lookup (random): 111-115(112.6+/-1.6) ns
+Initial lookup (random): 118-138(123.4+/-7.4) ns
-Initial delete all: 66-68(66.6+/-0.8) ns
+Initial delete all: 79-90(82+/-4.1) ns
-Initial re-inserting: 87-90(88+/-1.3) ns
+Initial re-inserting: 104-116(107.2+/-4.4) ns
-Deleting first half: 32-33(32.4+/-0.49) ns
+Deleting first half: 37-43(39+/-2.1) ns
-Lookup after half-change (match): 67-69(68+/-0.89) ns
+Lookup after half-change (match): 72-81(74.2+/-3.4) ns
-Churning second time: 272-276(274.2+/-1.5) ns
+Churning second time: 304-332(310.2+/-11) ns
-Churning third time: 290-296(293+/-2) ns
+Churning third time: 233-259(239+/-10) ns
-Churning fourth time: 289-295(292+/-2.2) ns
+Churning fourth time: 309-337(315.6+/-11) ns
-Churning fifth time: 289-294(291.8+/-1.9) ns
+Churning fifth time: 307-337(315+/-11) ns
-Details: worst run 146 (24 deleted)
+Details: worst run 115 (2 deleted)
-Lookup after churn & spread (miss): 110-111(110.6+/-0.49) ns
+Lookup after churn & spread (miss): 93-104(95.4+/-4.3) ns
-Deleting half after churn & spread: 36-37(36.4+/-0.49) ns
+Deleting half after churn & spread: 39-45(40.4+/-2.3) ns
-Adding (a different) half after churn & spread: 81-82(81.6+/-0.49) ns
+Adding (a different) half after churn & spread: 38-43(39.6+/-1.7) ns
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agohtable: tools/density
Rusty Russell [Fri, 17 Jun 2022 02:53:34 +0000 (12:23 +0930)]
htable: tools/density

Everyone loves stats: this looks at different levels of table density
and lookup speed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agohtable: fix vanishing entries properly.
Rusty Russell [Mon, 13 Jun 2022 12:18:19 +0000 (21:48 +0930)]
htable: fix vanishing entries properly.

A hash table entry consists of the pointer, but we mask out bits which
are common to all pointers, and replace them with hash bits.

The entry values 0 and 1 are special, meaning "empty" and "deleted"
respectively.

However, if a hash has mainly zero bits, and an pointer's non-shared
bits are all zero, we can create an entry which looks empty or
deleted.

The solution in this case is to share another bit (there must be some
bit which is not zero, since we don't allow 0 and 1 as pointers in the
hash table).

It's unusual, so I put this in a cold function: it shares code with
the existing "oh, we need to reduce the common bits, since this new
pointer doesn't look like the previous ones" case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agoPartial revert "htable: handle v. unlikely case where entries look deleted/empty."
Rusty Russell [Mon, 13 Jun 2022 12:14:05 +0000 (21:44 +0930)]
Partial revert "htable: handle v. unlikely case where entries look deleted/empty."

This reverts commit 7218ee2476d8a7e4f9413781e2bedcd2daaa8190.

Except for:
 - Leaves the test behind though (which fail!
 - Leaves the reversion of 0b93bd102aad6b61f1e569fb12aabc6352a1d7cd, since
   we're about to fix it, and properly!

2 years agoRevert "htable: optimize a little more."
Rusty Russell [Sun, 12 Jun 2022 03:58:52 +0000 (13:28 +0930)]
Revert "htable: optimize a little more."

This reverts commit 0f144bfe0ca3cc06564e19a7f3ea40177d1a3c2c.

2 years agohtable: optimize a little more.
Rusty Russell [Thu, 9 Jun 2022 04:10:40 +0000 (13:40 +0930)]
htable: optimize a little more.

tools/speed (10 runs) vs before fix:

-Lookup after half-change (match): 53-61(54.8+/-2.3) ns
+Lookup after half-change (match): 63-97(72.4+/-9) ns
-Churning fifth time: 171-181(175.4+/-2.9) ns
+Churning fifth time: 179-198(183.9+/-5.2) ns

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agohtable: handle v. unlikely case where entries look deleted/empty.
Rusty Russell [Thu, 9 Jun 2022 03:12:31 +0000 (12:42 +0930)]
htable: handle v. unlikely case where entries look deleted/empty.

If the hash function doesn't set any bits we use, and the common
bits are all zero the slot will look empty (or, just the lower bit is
set: the slow looks deleted).

However, each bucket is distinct since there are no duplicates, so
at worse there can be two "looks invalid but actually is valid"
buckets.  Keep them at the end.

Lookup suffers in raw tools/speed though:

-Lookup after half-change (match): 53-61(54.8+/-2.3) ns
+Lookup after half-change (match): 61-113(83.3+/-17) ns
-Lookup after churn & spread (match): 54-90(59.9+/-11) ns
+Lookup after churn & spread (match): 70-108(85.2+/-14) ns

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agoio: add new io_sock_shutdown helper.
Rusty Russell [Tue, 4 Jan 2022 02:36:34 +0000 (13:06 +1030)]
io: add new io_sock_shutdown helper.

Turns out that there's no good way to flush a socket:

https://blog.netherlabs.nl/articles/2009/01/18/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reliable

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agotal: add tal_dup_or_null and tal_dup_talarr helpers. origin/master
Rusty Russell [Wed, 15 Dec 2021 01:35:08 +0000 (12:05 +1030)]
tal: add tal_dup_or_null and tal_dup_talarr helpers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agocrc32c, crypto/xtea: check in LICENSE symlinks.
Rusty Russell [Mon, 13 Dec 2021 23:35:39 +0000 (10:05 +1030)]
crc32c, crypto/xtea: check in LICENSE symlinks.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2 years agographql: latest changes from @rl-d
Rusty Russell [Mon, 13 Dec 2021 23:32:47 +0000 (10:02 +1030)]
graphql: latest changes from @rl-d

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoccan: make tal_dump() format more regular.
Rusty Russell [Wed, 24 Nov 2021 02:06:52 +0000 (12:36 +1030)]
ccan: make tal_dump() format more regular.

Putting a \n in there was a pain: I had to do:

awk '/CHILDREN/ { SAVED=$0 } !/CHILDREN/ { print SAVED$0; SAVED="" }' < lightningd-tal_dump > lightningd-tal_dump-children-on-same-line

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agopipecmd: Use closefrom instead of iterating directly.
ZmnSCPxj jxPCSnmZ [Tue, 19 Oct 2021 01:55:48 +0000 (09:55 +0800)]
pipecmd: Use closefrom instead of iterating directly.

Signed-off-by: ZmnSCPxj jxPCSnmZ <ZmnSCPxj@protonmail.com>
3 years agoclosefrom: fix minor issues found by ccanlint
Rusty Russell [Thu, 21 Oct 2021 04:31:18 +0000 (15:01 +1030)]
closefrom: fix minor issues found by ccanlint

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoclosefrom: Close all file descriptors above a certain value.
ZmnSCPxj jxPCSnmZ [Tue, 19 Oct 2021 01:51:43 +0000 (09:51 +0800)]
closefrom: Close all file descriptors above a certain value.

For more information: https://github.com/ElementsProject/lightning/issues/4868

Signed-off-by: ZmnSCPxj jxPCSnmZ <ZmnSCPxj@protonmail.com>
3 years agoweb: create "versioned" tarballs.
Rusty Russell [Wed, 8 Sep 2021 07:29:02 +0000 (16:59 +0930)]
web: create "versioned" tarballs.

Fixes: https://github.com/rustyrussell/ccan/issues/90
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agobase64: fix assignment to wrong type, use ssize_t
Martin Milata [Thu, 11 May 2017 16:28:24 +0000 (18:28 +0200)]
base64: fix assignment to wrong type, use ssize_t

Functions that returned int have been modified to return ssize_t
instead.

Found by gcc:

base64.c:196:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (more == -1) {
           ^

Signed-off-by: Martin Milata <martin@martinmilata.cz>
3 years agonit: daemonize.c: fix Stevens' in comment
Jan Sarenik [Tue, 27 Oct 2020 07:21:25 +0000 (08:21 +0100)]
nit: daemonize.c: fix Stevens' in comment

3 years agoSetting the same name as at the implementation
Renat Idrisov [Tue, 4 Jun 2019 21:05:40 +0000 (14:05 -0700)]
Setting the same name as at the implementation

3 years agoconfigurator: always true branch
Niklas Claesson [Wed, 5 Feb 2020 21:03:10 +0000 (22:03 +0100)]
configurator: always true branch

3 years agoFix "for loop initial declarations are only allowed in C99 mode" compile errors.
Christopher McGeorge [Mon, 22 Mar 2021 22:24:16 +0000 (16:24 -0600)]
Fix "for loop initial declarations are only allowed in C99 mode" compile errors.

3 years agodocs: fix simple typo, unchaged -> unchanged
Tim Gates [Fri, 11 Dec 2020 18:59:26 +0000 (05:59 +1100)]
docs: fix simple typo, unchaged -> unchanged

There is a small typo in ccan/objset/objset.h.

Should read `unchanged` rather than `unchaged`.

3 years agofix warnings
rl-d [Wed, 8 Sep 2021 04:07:28 +0000 (00:07 -0400)]
fix warnings

3 years agoGraphQL lexer and parser (without optional type system)
rl-d [Wed, 8 Sep 2021 02:03:07 +0000 (22:03 -0400)]
GraphQL lexer and parser (without optional type system)

3 years agotal: tal_dump() now prints to stderr.
Rusty Russell [Mon, 23 Aug 2021 06:40:10 +0000 (16:10 +0930)]
tal: tal_dump() now prints to stderr.

This is more widely available than stdout, which can interfere with
other things.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agocompiler: RETURNS_NONNULL macro
Rusty Russell [Wed, 9 Jun 2021 05:42:28 +0000 (15:12 +0930)]
compiler: RETURNS_NONNULL macro

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoconfigurator: HAVE_ATTRIBUTE_RETURNS_NONNULL
Rusty Russell [Wed, 9 Jun 2021 05:42:22 +0000 (15:12 +0930)]
configurator: HAVE_ATTRIBUTE_RETURNS_NONNULL

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agotimer: handle time going backwards.
Rusty Russell [Tue, 23 Mar 2021 03:06:50 +0000 (13:36 +1030)]
timer: handle time going backwards.

As seen in https://github.com/ElementsProject/lightning/issues/4401

OpenBSD 6.8 inside VirtualBox.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
3 years agoutf8: don't allow NUL in decoded strings.
Rusty Russell [Tue, 1 Dec 2020 00:35:48 +0000 (11:05 +1030)]
utf8: don't allow NUL in decoded strings.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agojson_out: make json_out_finished finish buffer.
Rusty Russell [Mon, 14 Sep 2020 05:30:55 +0000 (15:00 +0930)]
json_out: make json_out_finished finish buffer.

For JSON RPC, we can actually write multiple JSON objects back
to back, and we don't want a comma between them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years ago*: Fix build with recent gcc/binutils
Kirill Smelkov [Thu, 10 Sep 2020 19:16:19 +0000 (19:16 +0000)]
*: Fix build with recent gcc/binutils

With current Debian testing I get:

tools/ccanlint/ccanlint -s --deps-fail-ignore   ccan/compiler/ && touch ccan/compiler/.ok
compiler: Module tests compile (tests_compile): FAIL
/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/ccan/compiler/test/run-is_compile_constant.c:Compile failed:
/usr/bin/ld: /tmp/ccanlint-129350.1804289383/tap.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/ccan/tap/tap.h:249: multiple definition of `tap_fail_callback'; /tmp/ccrAwqbl.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/ccan/tap/tap.h:249: first defined here
collect2: error: ld returned 1 exit status
...

cc -g3 -ggdb -Wall -Wstrict-prototypes -Wold-style-definition -Wundef -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings -DCCAN_STR_DEBUG=1 -I.  -MMD -MP -MFtools/ccanlint/ccanlint.d -MTtools/ccanlint/ccanlint tools/ccanlint/ccanlint.c tools/ccanlint/async.o tools/ccanlint/file_analysis.o tools/ccanlint/licenses.o tools/ccanlint/tests/avoids_cpp_reserved.o tools/ccanlint/tests/depends_accurate.o tools/ccanlint/tests/depends_build.o tools/ccanlint/tests/depends_build_without_features.o tools/ccanlint/tests/depends_exist.o tools/ccanlint/tests/examples_compile.o tools/ccanlint/tests/examples_exist.o tools/ccanlint/tests/examples_relevant.o tools/ccanlint/tests/examples_run.o tools/ccanlint/tests/hash_if.o tools/ccanlint/tests/headers_idempotent.o tools/ccanlint/tests/info_compiles.o tools/ccanlint/tests/info_documentation_exists.o tools/ccanlint/tests/info_exists.o tools/ccanlint/tests/info_ported.o tools/ccanlint/tests/info_summary_single_line.o tools/ccanlin
 t/tests/license_comment.o tools/ccanlint/tests/license_depends_compat.o tools/ccanlint/tests/license_exists.o tools/ccanlint/tests/license_file_compat.o tools/ccanlint/tests/main_header_compiles.o tools/ccanlint/tests/main_header_exists.o tools/ccanlint/tests/module_builds.o tools/ccanlint/tests/module_links.o tools/ccanlint/tests/no_trailing_whitespace.o tools/ccanlint/tests/objects_build.o tools/ccanlint/tests/objects_build_with_stringchecks.o tools/ccanlint/tests/objects_build_without_features.o tools/ccanlint/tests/reduce_features.o tools/ccanlint/tests/tests_compile.o tools/ccanlint/tests/tests_compile_coverage.o tools/ccanlint/tests/tests_coverage.o tools/ccanlint/tests/tests_exist.o tools/ccanlint/tests/tests_helpers_compile.o tools/ccanlint/tests/tests_pass.o tools/ccanlint/tests/tests_pass_valgrind.o tools/ccanlint/tests/tests_pass_without_features.o ccan/autodata/autodata.o ccan/dgraph/dgraph.o ccan/ilog/ilog.o ccan/lbalance/lbalance.o ccan/ptr_valid/ptr_valid.o ccan/strma
 p/strmap.o tools/ccan_dir.o tools/compi
le.o tools/depends.o tools/doc_extract-core.o tools/gcov.o tools/manifest.o tools/read_config_header.o tools/tools.o ccan/asort/asort.o ccan/err/err.o ccan/foreach/foreach.o ccan/hash/hash.o ccan/htable/htable.o ccan/list/list.o ccan/membuf/membuf.o ccan/noerr/noerr.o ccan/opt/helpers.o ccan/opt/opt.o ccan/opt/parse.o ccan/opt/usage.o ccan/rbuf/rbuf.o ccan/read_write_all/read_write_all.o ccan/str/debug.o ccan/str/str.o ccan/take/take.o ccan/tal/tal.o ccan/tal/grab_file/grab_file.o ccan/tal/link/link.o ccan/tal/path/path.o ccan/tal/str/str.o ccan/time/time.o -lm -o tools/ccanlint/ccanlint
/usr/bin/ld: tools/ccanlint/async.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/tools/ccanlint/../ccanlint/licenses.h:33: multiple definition of `license_compatible'; /tmp/cc72h7qq.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/tools/ccanlint/../ccanlint/licenses.h:33: first defined here
/usr/bin/ld: tools/ccanlint/file_analysis.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/tools/ccanlint/../ccanlint/licenses.h:33: multiple definition of `license_compatible'; /tmp/cc72h7qq.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/tools/ccanlint/../ccanlint/licenses.h:33: first defined here
/usr/bin/ld: tools/ccanlint/licenses.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/tools/ccanlint/licenses.h:33: multiple definition of `license_compatible'; /tmp/cc72h7qq.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/tools/ccanlint/../ccanlint/licenses.h:33: first defined here
/usr/bin/ld: tools/ccanlint/tests/avoids_cpp_reserved.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/./tools/ccanlint/../ccanlint/licenses.h:33: multiple definition of `license_compatible'; /tmp/cc72h7qq.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/tools/ccanlint/../ccanlint/licenses.h:33: first defined
here
/usr/bin/ld: tools/ccanlint/tests/depends_accurate.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/./tools/ccanlint/../ccanlint/licenses.h:33: multiple definition of `license_compatible'; /tmp/cc72h7qq.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/tools/ccanlint/../ccanlint/licenses.h:33: first defined here
/usr/bin/ld: tools/ccanlint/tests/depends_build.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/./tools/ccanlint/../ccanlint/licenses.h:33: multiple definition of `license_compatible'; /tmp/cc72h7qq.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/tools/ccanlint/../ccanlint/licenses.h:33: first defined here
/usr/bin/ld: tools/ccanlint/tests/depends_build_without_features.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/./tools/ccanlint/../ccanlint/licenses.h:33: multiple definition of `license_compatible'; /tmp/cc72h7qq.o:/home/kirr/src/wendelin/wendelin.core/3rdparty/ccan/tools/ccanlint/../ccanlint/licenses.h:33: first defined here
...

The errors are valid becuase symbols are declared without extern in .h
files and those .h files are included from multiple translation units.

-> Fix it. I'm not sure why it used to compile ok before.

Signed-off-by: Kirill Smelkov <kirr@nexedi.com>
Message-Id: <20200910191610.131510-1-kirr@nexedi.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4 years agotools/configurator: fix compile error with -O2
Rusty Russell [Fri, 17 Jul 2020 01:56:51 +0000 (11:26 +0930)]
tools/configurator: fix compile error with -O2

In file included from /usr/include/string.h:495,
                 from configuratortest.c:2:
In function ‘strncpy’,
    inlined from ‘main’ at configuratortest.c:6:2:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ specified bound 8 equals destination size [-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agotal: document tal_steal(ctx, NULL) as OK.
Rusty Russell [Fri, 19 Jun 2020 01:45:21 +0000 (11:15 +0930)]
tal: document tal_steal(ctx, NULL) as OK.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agohtable: add htable_type _delval.
Rusty Russell [Thu, 20 Feb 2020 02:31:19 +0000 (13:01 +1030)]
htable: add htable_type _delval.

To match the raw delval

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agohtable: fix type of htable_type _pick return.
Rusty Russell [Thu, 20 Feb 2020 02:23:11 +0000 (12:53 +1030)]
htable: fix type of htable_type _pick return.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agohtable: htable_pick helper to select a random entry.
Rusty Russell [Wed, 19 Feb 2020 23:48:10 +0000 (10:18 +1030)]
htable: htable_pick helper to select a random entry.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agotal: don't defer-after-free if a destructor deletes itself.
Rusty Russell [Mon, 17 Feb 2020 00:12:46 +0000 (10:42 +1030)]
tal: don't defer-after-free if a destructor deletes itself.

==10868==    at 0x109A96: notify (tal.c:220)
==10868==    by 0x109F7E: del_tree (tal.c:397)
==10868==    by 0x10A31A: tal_free (tal.c:481)
==10868==    by 0x10BE73: main (run-destructor.c:75)
==10868==  Address 0x4a60bd8 is 8 bytes inside a block of size 32 free'd
==10868==    at 0x483BA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==10868==    by 0x109D4F: del_notifier_property (tal.c:340)
==10868==    by 0x10A610: tal_del_notifier_ (tal.c:564)
==10868==    by 0x10A687: tal_del_destructor_ (tal.c:576)
==10868==    by 0x10B653: remove_own_destructor (run-destructor.c:35)
==10868==    by 0x109A67: notify (tal.c:235)
==10868==    by 0x109F7E: del_tree (tal.c:397)
==10868==    by 0x10A31A: tal_free (tal.c:481)
==10868==    by 0x10BE73: main (run-destructor.c:75)
==10868==  Block was alloc'd at
==10868==    at 0x483A7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==10868==    by 0x109AD5: allocate (tal.c:245)
==10868==    by 0x109C3E: add_notifier_property (tal.c:300)
==10868==    by 0x10A467: tal_add_destructor_ (tal.c:516)
==10868==    by 0x10BDFE: main (run-destructor.c:74)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoopt: fix opt_unregister.
Rusty Russell [Tue, 11 Feb 2020 04:09:43 +0000 (14:39 +1030)]
opt: fix opt_unregister.

Instead of memmoving N structs, we were memmoving N bytes.

But why did the test pass then?  It was doing memmove(..., 1)
instead of memmove(..., sizeof(struct opt_table)!

Because the two structures were really similar; the main difference
was the first entry, which points to the name.  But they were allocated
consecutively, and Intel being little-endian, the only difference was
the first byte!  Thus memmove(1) was enough to make it "work".

Change two options in the test to be sufficiently different, and
the bug shows up.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoxtea: new module.
Rusty Russell [Tue, 4 Feb 2020 02:38:02 +0000 (13:08 +1030)]
xtea: new module.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoopt: add opt_unregister.
Rusty Russell [Tue, 4 Feb 2020 01:10:36 +0000 (11:40 +1030)]
opt: add opt_unregister.

Sometimes we all make mistakes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agotools/configurator: simplify wrapper code a little.
Rusty Russell [Tue, 4 Feb 2020 00:38:35 +0000 (11:08 +1030)]
tools/configurator: simplify wrapper code a little.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
4 years agoconfigurator: Enable running configurator in wrapper
Niklas Claesson [Tue, 28 Jan 2020 23:50:15 +0000 (00:50 +0100)]
configurator: Enable running configurator in wrapper

Since the probing binaries compiled by the configurator needs to run on
the host machine we provide a variable CONFIGURATOR_WRAPPER that can be
set to anything that you want to wrap the calls with.

One example is `qemu-aarch64-static`.

5 years agobitmap: Allow bitmap type to be forward declared
Kirill Smelkov [Mon, 21 Oct 2019 15:09:20 +0000 (15:09 +0000)]
bitmap: Allow bitmap type to be forward declared

Currently bitmap type is defined via untagged struct which makes it
impossible to forward declare it. Forward-declaring is useful since all
bitmap functions only use bitmap* and in public user-visible
headers/datastructures it is enough to indicate that a data field with
bitmap pointer is there, whereas bitmap.h can be included only in
implementation.

Beside that some headers are included by both C and C++ parts of a
project, and when ccan/bitmap.h is processed by C++ compiler it gives:

    ./3rdparty/ccan/ccan/bitmap/bitmap.h: In function ‘bitmap* bitmap_alloc(long unsigned int)’:
    ./3rdparty/ccan/ccan/bitmap/bitmap.h:201:15: error: invalid conversion from ‘void*’ to ‘bitmap*’ [-fpermissive]
      return malloc(bitmap_sizeof(nbits));
             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
    ./3rdparty/ccan/ccan/bitmap/bitmap.h: In function ‘bitmap* bitmap_realloc0(bitmap*, long unsigned int, long unsigned int)’:
    ./3rdparty/ccan/ccan/bitmap/bitmap.h:227:18: error: invalid conversion from ‘void*’ to ‘bitmap*’ [-fpermissive]
      bitmap = realloc(bitmap, bitmap_sizeof(nbits));
               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ./3rdparty/ccan/ccan/bitmap/bitmap.h: In function ‘bitmap* bitmap_realloc1(bitmap*, long unsigned int, long unsigned int)’:
    ./3rdparty/ccan/ccan/bitmap/bitmap.h:238:18: error: invalid conversion from ‘void*’ to ‘bitmap*’ [-fpermissive]
      bitmap = realloc(bitmap, bitmap_sizeof(nbits));

-> Give to users ability not to force-include ccan/bitmap.h by
forward-declaring bitmaps like this:

    typedef struct bitmap bitmap;
    ...
    struct MyStruct {
        bitmap *my_bitmap;
    };

Cc: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Kirill Smelkov <kirr@nexedi.com>
Message-Id: <20191021150903.25159-1-kirr@nexedi.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
5 years agointmap: implement intmap_before()
Rusty Russell [Thu, 10 Oct 2019 05:06:00 +0000 (15:36 +1030)]
intmap: implement intmap_before()

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agofailtest, rbuf: fix up incorrect lseek arg order.
Rusty Russell [Fri, 4 Oct 2019 05:07:14 +0000 (14:37 +0930)]
failtest, rbuf: fix up incorrect lseek arg order.

SEEK_SET == 0, so it's not hurting anyone now, but when I cut & paste
it elsewhere...

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agopipecmd: close fds in child.
Rusty Russell [Wed, 14 Aug 2019 03:43:46 +0000 (13:13 +0930)]
pipecmd: close fds in child.

This is usually what you want; I didn't even add a flag to stop it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agohtable: add htable_count().
Rusty Russell [Tue, 13 Aug 2019 03:02:42 +0000 (12:32 +0930)]
htable: add htable_count().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agoSuppress false positive warning "-Wmaybe-uninitialized" with GCC -O3
Chirimen-Jako [Wed, 31 Jul 2019 09:21:58 +0000 (18:21 +0900)]
Suppress false positive warning "-Wmaybe-uninitialized" with GCC -O3

5 years agoconfigurator: fix openmp test on some versions of clang.
Rusty Russell [Wed, 31 Jul 2019 06:56:30 +0000 (16:26 +0930)]
configurator: fix openmp test on some versions of clang.

Discovered on bionic's Travis install, it failed at *runtime* when
it couldn't find the shared library.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agobitmap: Fix some bugs on 32-bit platforms
David Gibson [Thu, 11 Jul 2019 02:07:33 +0000 (12:07 +1000)]
bitmap: Fix some bugs on 32-bit platforms

The bitmap_word type is an unsigned long.  However in some places we assign
it using -1ULL, a 64-bit value on many platforms.  We sometimes get away
with this because it masks correctly, but in other cases it breaks things.

To clean this up define a new BITMAP_WORD_1 constant, indicating a
bitmap_word with all bits set, and use that instead of explicit UL or ULL
qualifiers.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
5 years agoccan/crc: remove broken "crc32c" routines which gave wrong results.
Rusty Russell [Tue, 11 Jun 2019 04:56:02 +0000 (14:26 +0930)]
ccan/crc: remove broken "crc32c" routines which gave wrong results.

I copied them from the kernel, but obviously didn't find good test
vectors.  In particular, the CRC of all zeroes is not 0!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agoccan/crc32c: new module for accelerated CRC32 (on x86-64).
Rusty Russell [Tue, 11 Jun 2019 04:54:56 +0000 (14:24 +0930)]
ccan/crc32c: new module for accelerated CRC32 (on x86-64).

Note: the previous code in ccan/crc is wrong, so I started fresh with
actual test vectors.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agoccan/compiler: add cpu_supports() macro.
Rusty Russell [Tue, 11 Jun 2019 04:54:11 +0000 (14:24 +0930)]
ccan/compiler: add cpu_supports() macro.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agoconfigurator: detect __builtin_cpu_supports.
Rusty Russell [Tue, 11 Jun 2019 04:53:52 +0000 (14:23 +0930)]
configurator: detect __builtin_cpu_supports.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
5 years agojson_out: pass through OOM failures.
Rusty Russell [Thu, 23 May 2019 05:29:44 +0000 (14:59 +0930)]
json_out: pass through OOM failures.

And fix escaping to work with addstr(), and assert in debug mode
if they don't specify quotes.

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