ccan
6 years agocpuid: Minor improvements
Ahmed Samy [Wed, 25 Sep 2013 14:46:09 +0000 (14:46 +0000)]
cpuid: Minor improvements

Remove the assembly file that checks if the CPUID instruction is
supported and have it in inline assembly as suggested by Rusty.

Signed-off-by: Ahmed Samy <f.fallen45@gmail.com>
6 years agocpuid: only compile source file if x86 cpu
Ahmed Samy [Mon, 23 Sep 2013 22:40:41 +0000 (22:40 +0000)]
cpuid: only compile source file if x86 cpu

Suggested-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Ahmed Samy <f.fallen45@gmail.com>
6 years agocpuid: prefix every function with cpuid_
Ahmed Samy [Mon, 23 Sep 2013 08:20:08 +0000 (08:20 +0000)]
cpuid: prefix every function with cpuid_

Also merge extended features and non-extended in 1 function.

Suggested-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Ahmed Samy <f.fallen45@gmail.com>
6 years agocpuid: add 2 new functions + some more tests
Ahmed Samy [Sun, 22 Sep 2013 07:42:15 +0000 (07:42 +0000)]
cpuid: add 2 new functions + some more tests

The new functions are:
- get_cpu_type
- get_cpu_type_string

Also add more tests on how one would parse the low-level stuff.

Signed-off-by: Ahmed Samy <f.fallen45@gmail.com>
6 years agocpuid: add proper documentation
Ahmed Samy [Sat, 21 Sep 2013 10:03:11 +0000 (10:03 +0000)]
cpuid: add proper documentation

Forgot to add this to the main commit, sorry.

Signed-off-by: Ahmed Samy <f.fallen45@gmail.com>
6 years agocpuid: new module
Ahmed Samy [Sat, 21 Sep 2013 09:45:06 +0000 (09:45 +0000)]
cpuid: new module

This module parses data provided by the cpuid instruction.
It still needs more work, however, it works for most important
stuff.

Signed-off-by: Ahmed Samy <f.fallen45@gmail.com>
6 years agoMerge branch 'master' of ozlabs.org:ccan
Rusty Russell [Fri, 13 Sep 2013 00:08:40 +0000 (09:38 +0930)]
Merge branch 'master' of ozlabs.org:ccan

6 years agoAdd bitmap module to Makefile.
Rusty Russell [Fri, 13 Sep 2013 00:05:14 +0000 (09:35 +0930)]
Add bitmap module to Makefile.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
6 years agoMerge https://github.com/dgibson/ccan
Rusty Russell [Fri, 13 Sep 2013 00:01:17 +0000 (09:31 +0930)]
Merge https://github.com/dgibson/ccan

6 years agoheap: add example on empty heap check
Emilio G. Cota [Thu, 12 Sep 2013 16:45:49 +0000 (12:45 -0400)]
heap: add example on empty heap check

Suggested-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Emilio G. Cota <cota@braap.org>
6 years agoheap: new module
Emilio G. Cota [Tue, 10 Sep 2013 00:32:19 +0000 (20:32 -0400)]
heap: new module

Signed-off-by: Emilio G. Cota <cota@braap.org>
6 years agoilog: reformat so webpage doesn't get confused.
Rusty Russell [Mon, 9 Sep 2013 07:23:38 +0000 (16:53 +0930)]
ilog: reformat so webpage doesn't get confused.

The extra spaces make my web formatter think they're literal text, which
looks weird.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
6 years agoilog: relicense to Public Domain.
Rusty Russell [Mon, 9 Sep 2013 07:21:14 +0000 (16:51 +0930)]
ilog: relicense to Public Domain.

I noted to Timothy in 2011:
   I finally got around to implementing license checking in ccanlint,
   and it shows that your public domain ccan/isaac module uses your LGPL
   ccan/ilog module, which partially defeats the point.

   You and I are the only ones who did anything significant to ilog; I'm
   happy to relicense to PD or whatever else you want.  Or leave it, in
   which case I'll need to document it clearly.

He finally got back to me, and I sent him this patch, to which he replied:

     Ack.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
6 years agotal: add tal_resizez for zero-padded expansion.
Rusty Russell [Sun, 8 Sep 2013 06:53:02 +0000 (16:23 +0930)]
tal: add tal_resizez for zero-padded expansion.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
6 years agoendian: add documentation on endian typedefs.
Rusty Russell [Sun, 8 Sep 2013 04:13:05 +0000 (13:43 +0930)]
endian: add documentation on endian typedefs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
6 years agoshort_types: update documentation on be32/le32 etc.
Rusty Russell [Sun, 8 Sep 2013 04:11:35 +0000 (13:41 +0930)]
short_types: update documentation on be32/le32 etc.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
6 years agoendian/short_types: sparse support.
Rusty Russell [Sun, 8 Sep 2013 04:09:12 +0000 (13:39 +0930)]
endian/short_types: sparse support.

If you're doing endian work, sparse's bitwise annotation is extremely useful.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
6 years agobitmap: Add helper macro to statically declare bitmaps
David Gibson [Thu, 5 Sep 2013 14:37:14 +0000 (00:37 +1000)]
bitmap: Add helper macro to statically declare bitmaps

For use as direct locals, or when the size is a constant, inside
structure definitions.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agobitmap: Rework to assume always multiple of words storage length
David Gibson [Thu, 5 Sep 2013 14:28:36 +0000 (00:28 +1000)]
bitmap: Rework to assume always multiple of words storage length

Handling bitmaps which extend some odd number of bits, and assuring they
don't clobber partially overlapped variables is not worth the bother.

Also avoid namespace pollution.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agobitmap: Rework types and sizing macros
David Gibson [Thu, 5 Sep 2013 12:40:19 +0000 (22:40 +1000)]
bitmap: Rework types and sizing macros

Go with "words" rather than explicitly referencing longs in the macros

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agobitmap: Use a typesafe(ish) parameters instead of void *
David Gibson [Wed, 4 Sep 2013 14:16:47 +0000 (00:16 +1000)]
bitmap: Use a typesafe(ish) parameters instead of void *

This also fixes a bug which will hit on platforms where it's not safe to
dereference a (long *) which is not correctly aligned.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agolist: add list_next and list_prev helpers.
Rusty Russell [Thu, 29 Aug 2013 00:48:47 +0000 (10:18 +0930)]
list: add list_next and list_prev helpers.

Some way towards iterating in the middle of the list.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
6 years agobitmap: Add first cut at a bitmap module
David Gibson [Thu, 22 Aug 2013 12:39:02 +0000 (22:39 +1000)]
bitmap: Add first cut at a bitmap module

This adds a module for manipulating bitmaps, based on the API from the
Linux kernel's bitmap.h.  So far it's missing the trickier bits, but is
a little more flexible, allowing bitmaps that don't have to be contained
in an integer number of unsigned longs.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
7 years agoccan: Fix calling memset with zero length parameter
Volker Lendecke [Thu, 11 Jul 2013 12:57:53 +0000 (14:57 +0200)]
ccan: Fix calling memset with zero length parameter

Signed-off-by: Volker Lendecke <vl@samba.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal/path: fix unset vars in error paths.
Rusty Russell [Tue, 11 Jun 2013 05:10:49 +0000 (14:40 +0930)]
tal/path: fix unset vars in error paths.

Compiling with optimization FTW.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agobreakpoint: new module.
Rusty Russell [Mon, 27 May 2013 12:23:55 +0000 (21:53 +0930)]
breakpoint: new module.

Thanks to Jeremy Kerr for the idea!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoendian: remove unnecessary _CONST postfixes.
Rusty Russell [Mon, 13 May 2013 06:52:53 +0000 (16:22 +0930)]
endian: remove unnecessary _CONST postfixes.

It makes the names longer, whereas the CAPS is probably sufficient.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoendian: add constant versions.
Rusty Russell [Mon, 8 Apr 2013 07:08:24 +0000 (16:38 +0930)]
endian: add constant versions.

Sometimes you really need a compile-time constant, but there's no generic way
to create a macro which does this and only evaluates its argument once.

Thus we need specific const macros.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoendian: change license to CC0.
Rusty Russell [Mon, 8 Apr 2013 05:38:08 +0000 (15:08 +0930)]
endian: change license to CC0.

Not worth LGPL for just this header.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotimer: clean up.
Rusty Russell [Fri, 5 Apr 2013 06:33:54 +0000 (17:03 +1030)]
timer: clean up.

Add examples and a documentation fix.
Remove unused cascade function (was used in initial always-step-1-bucket
 version).
Restore timers_dump() to within CCAN_TIMER_DEBUG.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotimer: increase default span to 5.
Rusty Russell [Fri, 5 Apr 2013 06:13:49 +0000 (16:43 +1030)]
timer: increase default span to 5.

There's a sweet spot around 5, without going all the way to 13 (which
would make each level 64/128k large).

TIMER_LEVEL_BITS 2: 100000000 in 5.833399-5.884659(5.85912+/-0.015) (18 levels / 32)
TIMER_LEVEL_BITS 3: 100000000 in 5.267610-5.303589(5.29018+/-0.011) (12-13(12.5+/-0.5) levels / 22)
TIMER_LEVEL_BITS 4: 100000000 in 4.215605-4.417297(4.27771+/-0.062) (9-10(9.1+/-0.3) levels / 16)
TIMER_LEVEL_BITS 5: 100000000 in 3.859340-3.972603(3.90149+/-0.034) (7-8(7.1+/-0.3) levels / 13)
TIMER_LEVEL_BITS 6: 100000000 in 3.976157-4.037230(4.00199+/-0.02) (6 levels / 11)
TIMER_LEVEL_BITS 7: 100000000 in 4.014228-4.082031(4.05024+/-0.022) (5-6(5.4+/-0.49) levels / 10)
TIMER_LEVEL_BITS 8: 100000000 in 3.915615-3.978781(3.94972+/-0.02) (5 levels / 8)
TIMER_LEVEL_BITS 9: 100000000 in 3.859413-4.025842(3.89993+/-0.046) (4-5(4.6+/-0.49) levels / 8)
TIMER_LEVEL_BITS 10: 100000000 in 3.983507-4.170152(4.06743+/-0.055) (4 levels / 7)
TIMER_LEVEL_BITS 11: 100000000 in 3.468756-3.610746(3.52843+/-0.04) (4 levels / 6)
TIMER_LEVEL_BITS 12: 100000000 in 3.274397-3.377530(3.3192+/-0.026) (4 levels / 6)
TIMER_LEVEL_BITS 13: 100000000 in 3.116845-3.178162(3.1398+/-0.017) (3 levels / 5)
TIMER_LEVEL_BITS 14: 100000000 in 3.152599-3.264060(3.20733+/-0.043) (3 levels / 5)
TIMER_LEVEL_BITS 15: 100000000 in 3.186556-3.552432(3.25597+/-0.11) (3 levels / 5)
TIMER_LEVEL_BITS 16: 100000000 in 3.139352-3.485653(3.27263+/-0.11) (3 levels / 4)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotimer: cache the minimal value.
Rusty Russell [Fri, 5 Apr 2013 06:13:48 +0000 (16:43 +1030)]
timer: cache the minimal value.

We spend a lot of time searching for the next timer to expire: by caching
the minimum, we can skip most of this work.  Even if timers are deleted,
the minimum will be a starting point for searching.

The expected-usage benchmark has to be increased by a factor of 100,
otherwise it's now too short.

Before:
$ ./expected-usage
1000000 in 12.701647935

After:
$ ./expected-usage  1000000
1000000 in 0.061095153

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotimers: implementation of lazily-ordered timers.
Rusty Russell [Fri, 5 Apr 2013 06:13:27 +0000 (16:43 +1030)]
timers: implementation of lazily-ordered timers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoAdd Henry Eshbaugh's log module to junkcode for the moment.
Rusty Russell [Thu, 4 Apr 2013 23:59:01 +0000 (10:29 +1030)]
Add Henry Eshbaugh's log module to junkcode for the moment.

It's got some useful stuff in it, but doesn't pass ccanlint here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoMakefile: don't separate all modules with external dependencies.
Rusty Russell [Mon, 1 Apr 2013 03:22:55 +0000 (13:52 +1030)]
Makefile: don't separate all modules with external dependencies.

Using ccanlint's --deps-fail-ignore, we can just test every module
with "make check".  Still exclude them from the 'libccan.a' build
though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agonfs: add licenses into generated files.
Rusty Russell [Mon, 1 Apr 2013 03:22:35 +0000 (13:52 +1030)]
nfs: add licenses into generated files.

Otherwise ccanlint complains about missing license comments.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoccanlint: --deps-fail-ignore.
Rusty Russell [Mon, 1 Apr 2013 02:44:00 +0000 (13:14 +1030)]
ccanlint: --deps-fail-ignore.

Useful for bulk testing modules, where some might not have required
external (non-CCAN) dependencies.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoogg_to_pcm: fix compilation of example in _info.
Rusty Russell [Mon, 1 Apr 2013 00:00:30 +0000 (10:30 +1030)]
ogg_to_pcm: fix compilation of example in _info.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoccanlint: don't crash if given bad directory name.
Rusty Russell [Sun, 31 Mar 2013 06:40:50 +0000 (17:10 +1030)]
ccanlint: don't crash if given bad directory name.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoAdd a set of simple version comparison helpers
Peter Hutterer [Wed, 27 Mar 2013 23:38:48 +0000 (09:38 +1000)]
Add a set of simple version comparison helpers

These version helpers help to compare major.minor style version numbers,
without the need for open-coded and error-prone bitshifting, multiplication,
and similar.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agonet: add server support.
Rusty Russell [Sun, 17 Mar 2013 04:48:10 +0000 (15:18 +1030)]
net: add server support.

Creating a server for IPv4 and IPv6 has similar issues to clients,
with some novel twists.  Slightly different arguments need to be given
to getaddrinfo(), but worse, some platforms (Linux without
/proc/sys/net/ipv6/bindv6only set) automatically bind IPv6 sockets to IPv4
ports as well.

Thus we need a function which can bind (and listen) to one or two fds.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agolist: list_pop
Rusty Russell [Sun, 17 Mar 2013 04:42:14 +0000 (15:12 +1030)]
list: list_pop

list_top + list_del, as suggested by Ben Herrenschmidt.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agolist: list_append_list / list_prepend_list
Rusty Russell [Sun, 17 Mar 2013 04:41:48 +0000 (15:11 +1030)]
list: list_append_list / list_prepend_list

Operations for moving the entire contents of a list.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoautodata: make note about not being generally useful for shared libraries.
Rusty Russell [Sun, 17 Mar 2013 03:56:31 +0000 (14:26 +1030)]
autodata: make note about not being generally useful for shared libraries.

If you have sections, it might still work for some cases though: on x86
Ubuntu it worked once I changed the section name from autodata to xautodata.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoiscsi, ttxml: fix warning [-Wunused-but-set-variable]
Tinggong [Fri, 8 Mar 2013 15:11:23 +0000 (23:11 +0800)]
iscsi, ttxml: fix warning [-Wunused-but-set-variable]

hi all,

here is a trival path to fix warning [-Wunused-but-set-variable].

Thanks.
Tinggong

Signed-off-by: Tinggong <wangtinggong@gmail.com>
7 years agofailtest: fix warning [-Wformat]
Tinggong [Fri, 8 Mar 2013 15:09:02 +0000 (23:09 +0800)]
failtest: fix warning [-Wformat]

hi rusty,

here is a trival path to fix warning [-Wformat].

Thanks.
Tinggong

Signed-off-by: Tinggong <wangtinggong@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agonet: make tests more robust.
Rusty Russell [Thu, 7 Feb 2013 00:42:27 +0000 (11:12 +1030)]
net: make tests more robust.

Andreas Schlick reports failure on systems without IPv6 support (in particular
ones with no IPv6 addresses for localhost).  We should be more robust in
these cases, and also where IPv4 support is missing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoforeach: fix overzealous test.
Rusty Russell [Thu, 7 Feb 2013 00:25:01 +0000 (10:55 +1030)]
foreach: fix overzealous test.

Andreas Schlick reported a failure on 64-bit systems; we should simply
test that the number of iterators does not grow on second iteration,
rather than assuming an explicit limit as compilers may vary.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoMakefile: Add hacks for the nested modules for make check.
Andreas Schlick [Tue, 5 Feb 2013 19:05:35 +0000 (20:05 +0100)]
Makefile: Add hacks for the nested modules for make check.

7 years agoMerge commit 'add31d8'
Rusty Russell [Sat, 2 Feb 2013 04:15:34 +0000 (14:45 +1030)]
Merge commit 'add31d8'

7 years agosparse_bsearch: fixed the no ssize_t defined error.
Riceball LEE [Thu, 24 Jan 2013 01:01:14 +0000 (09:01 +0800)]
sparse_bsearch: fixed the no ssize_t defined error.

7 years agosiphash: Use uint64_t directly, remove typedef
Ulrik Sverdrup [Fri, 25 Jan 2013 19:48:35 +0000 (20:48 +0100)]
siphash: Use uint64_t directly, remove typedef

7 years agosiphash: Simplify helper function W64's signature
Ulrik Sverdrup [Fri, 25 Jan 2013 19:48:35 +0000 (20:48 +0100)]
siphash: Simplify helper function W64's signature

7 years agosiphash: Use ~7 correctly
Ulrik Sverdrup [Fri, 25 Jan 2013 19:48:35 +0000 (20:48 +0100)]
siphash: Use ~7 correctly

7 in ~7 needs to be size_t for it to be correct when len > INT_MAX.

7 years agosiphash: Write siphash_epilogue in nicer style
Ulrik Sverdrup [Mon, 14 Jan 2013 22:11:56 +0000 (23:11 +0100)]
siphash: Write siphash_epilogue in nicer style

7 years agosiphash: Use simple but misalignment-correct implementation of W64
Ulrik Sverdrup [Sun, 13 Jan 2013 15:24:11 +0000 (16:24 +0100)]
siphash: Use simple but misalignment-correct implementation of W64

A simple implementation compiles very well with gcc and clang on ppc and
x86, and will handle any-aligned input.

7 years agosiphash: A keyed hash designed by Aumasson and djb
Ulrik Sverdrup [Sun, 13 Jan 2013 15:24:11 +0000 (16:24 +0100)]
siphash: A keyed hash designed by Aumasson and djb

7 years agoccanlint: fix stack smash.
Rusty Russell [Mon, 14 Jan 2013 07:40:59 +0000 (18:10 +1030)]
ccanlint: fix stack smash.

"engla" on IRC reported that ccanlint on linux/powerpc would loop
infinitely calling dep_failed after all tests are run and the score is
output.

Reproduced, and discovered that cannot_run() takes a container_of(),
except our top node is not a struct ccanlint.  The result was harmless on
x86, but set dep_failed to the return address on powerpc, causing that
to be called repeatedly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agodgraph: add dgraph_check and CCAN_DGRAPH_DEBUG
Rusty Russell [Mon, 14 Jan 2013 07:35:14 +0000 (18:05 +1030)]
dgraph: add dgraph_check and CCAN_DGRAPH_DEBUG

This is good form for datastructures, so caller can track weird bugs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoccanlint: handle when _info doesn't compile.
Rusty Russell [Sat, 12 Jan 2013 05:34:58 +0000 (16:04 +1030)]
ccanlint: handle when _info doesn't compile.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoMerge branch 'rfc822'
Rusty Russell [Thu, 3 Jan 2013 01:06:59 +0000 (11:36 +1030)]
Merge branch 'rfc822'

7 years agorfc822: switch to ccan/tal. origin/rfc822
Rusty Russell [Thu, 3 Jan 2013 01:06:55 +0000 (11:36 +1030)]
rfc822: switch to ccan/tal.

We use TAL_USE_TALLOC to use libtalloc as the backend: you can test that with
ccanlint --compiler="cc -DTAL_USE_TALLOC".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal/str: use tal/talloc backend #ifdef TAL_USE_TALLOC.
Rusty Russell [Thu, 3 Jan 2013 01:06:55 +0000 (11:36 +1030)]
tal/str: use tal/talloc backend #ifdef TAL_USE_TALLOC.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoccanlint: ignore "unused" non-ccan dependencies.
Rusty Russell [Thu, 3 Jan 2013 01:06:48 +0000 (11:36 +1030)]
ccanlint: ignore "unused" non-ccan dependencies.

We can't really tell if non-ccan dependencies are used, so don't try.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal/talloc: new module for backending tal onto talloc.
Rusty Russell [Thu, 3 Jan 2013 01:04:22 +0000 (11:34 +1030)]
tal/talloc: new module for backending tal onto talloc.

David Gibson points out that a project may already be using talloc, so
this gives a simple adapter if one module uses tal.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: don't automatically register cleanup function.
Rusty Russell [Mon, 17 Dec 2012 03:25:42 +0000 (13:55 +1030)]
tal: don't automatically register cleanup function.

It may interfere with other at_exit() calls, so let them call it manually.
Also, use memset to zero, which really does make valgrind notice any leaks.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoconfigurator: fix single-arg case.
Rusty Russell [Mon, 17 Dec 2012 03:24:15 +0000 (13:54 +1030)]
configurator: fix single-arg case.

In this case, CCAN_CFLAGS should be "".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: append the length property to the initial allocation.
Rusty Russell [Mon, 17 Dec 2012 03:23:25 +0000 (13:53 +1030)]
tal: append the length property to the initial allocation.

Since we never post-add a length property, we can save some cycles by
allocating it together with the object itself:

Before:
$ ./samba-allocs talloc.dump --tal
Tal time:                6058997-6215211(6102645)ns
Tal_free time:           4791112-4968964(4824814)ns
Single tal_free time:    3173647-3331584(3200183)ns
$ ./samba-allocs talloc.dump --tal-size
Virtual size = 9809920, RSS = 3952640

After:
$ ./samba-allocs talloc.dump --tal
Tal time:                5911994-6043808(5956914)ns
Tal_free time:           4676026-4834598(4719908)ns
Single tal_free time:    2888195-3067365(2922298)ns
$ ./samba-allocs talloc.dump --tal-size
Virtual size = 9809920, RSS = 3948544

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: don't always allocate an array in the samba benchmark.
Rusty Russell [Fri, 14 Dec 2012 21:02:06 +0000 (07:32 +1030)]
tal: don't always allocate an array in the samba benchmark.

Since we added the length property, this penalizes us with an extra
alloc.  Unfortunately, we can't tell from the talloc.dump which are
array tallocs and which are single tallocs, but grepping the sources
gives a rate of 1 in 27.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: fix skipping tal in samba-allocs benchmark.
Rusty Russell [Fri, 14 Dec 2012 20:57:50 +0000 (07:27 +1030)]
tal: fix skipping tal in samba-allocs benchmark.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: fix compilation of speed benchmark.
Rusty Russell [Fri, 14 Dec 2012 20:57:19 +0000 (07:27 +1030)]
tal: fix compilation of speed benchmark.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agorfc822: fix sigaction test, wean off ccan-specific talloc_set_allocator()
Rusty Russell [Fri, 7 Dec 2012 05:56:37 +0000 (16:26 +1030)]
rfc822: fix sigaction test, wean off ccan-specific talloc_set_allocator()

The first ok() line was actually failing, because sigaction returns 0
on success, but because the program exit(0) out the abort handler,
that wasn't being seen.

So remove tap and just abort and assert our way through the test,
which I think is clearer.

We use macros to mug the talloc entry points, since talloc_set_allocator()
is not in mainline talloc.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agorfc822: beef up _info example.
Rusty Russell [Fri, 7 Dec 2012 05:56:37 +0000 (16:26 +1030)]
rfc822: beef up _info example.

Now it's a useful little command line utility, with tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoccanlint: fix --compiler and --cflags options to apply to _info files as well.
Rusty Russell [Fri, 7 Dec 2012 05:56:07 +0000 (16:26 +1030)]
ccanlint: fix --compiler and --cflags options to apply to _info files as well.

We weren't using the compiler and cflags options in tools/compile.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotools: manifest.c should use path_canon.
Rusty Russell [Mon, 3 Dec 2012 11:36:40 +0000 (22:06 +1030)]
tools: manifest.c should use path_canon.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoccanlint: remove redundant num_lines in struct ccan_file.
Rusty Russell [Mon, 3 Dec 2012 11:36:40 +0000 (22:06 +1030)]
ccanlint: remove redundant num_lines in struct ccan_file.

We can use tal_count.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoccanlint: print module name properly for nested modules.
Rusty Russell [Mon, 3 Dec 2012 11:36:40 +0000 (22:06 +1030)]
ccanlint: print module name properly for nested modules.

eg:
tal/str: Module's tests cover all the code (tests_coverage): PASS (+3/6)
tal/str: Total score: 55/58

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotools: use tal/path instead of opencoding most paths.
Rusty Russell [Mon, 3 Dec 2012 11:36:40 +0000 (22:06 +1030)]
tools: use tal/path instead of opencoding most paths.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotools: use tal/path instead of writing own path handlers.
Rusty Russell [Mon, 3 Dec 2012 11:36:40 +0000 (22:06 +1030)]
tools: use tal/path instead of writing own path handlers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotools: use tal instead of talloc.
Rusty Russell [Mon, 3 Dec 2012 11:36:40 +0000 (22:06 +1030)]
tools: use tal instead of talloc.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotools: use rbuf instead of grab_file.
Rusty Russell [Mon, 3 Dec 2012 11:36:40 +0000 (22:06 +1030)]
tools: use rbuf instead of grab_file.

Slowly removing the talloc dependency.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agorbuf: new module.
Rusty Russell [Mon, 3 Dec 2012 11:36:40 +0000 (22:06 +1030)]
rbuf: new module.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal/link: new module for reference-count style coding for tal.
Rusty Russell [Mon, 3 Dec 2012 11:36:38 +0000 (22:06 +1030)]
tal/link: new module for reference-count style coding for tal.

Tests and example copied from talloc_link, which I also wrote.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal/str: add tal_append_fmt() and tal_append_vfmt() helpers.
Rusty Russell [Mon, 3 Dec 2012 08:59:39 +0000 (19:29 +1030)]
tal/str: add tal_append_fmt() and tal_append_vfmt() helpers.

They are far too convenient, despite their inefficiency.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal/str: rename tal_asprintf/tal_vasprintf to tal_fmt/tal_vfmt.
Rusty Russell [Mon, 3 Dec 2012 08:59:39 +0000 (19:29 +1030)]
tal/str: rename tal_asprintf/tal_vasprintf to tal_fmt/tal_vfmt.

Shorter, sweeter, and less legacy.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal/str: add tal_strcat().
Rusty Russell [Mon, 3 Dec 2012 08:59:39 +0000 (19:29 +1030)]
tal/str: add tal_strcat().

Useful for joining two strings.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: add tal_expand().
Rusty Russell [Mon, 3 Dec 2012 08:59:39 +0000 (19:29 +1030)]
tal: add tal_expand().

Helper to reallocate and append to an array.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal/str: move tal string functions here from tal.
Rusty Russell [Mon, 3 Dec 2012 08:59:39 +0000 (19:29 +1030)]
tal/str: move tal string functions here from tal.

They don't need anything internal to tal, they're just helpers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal/str: use tal_ prefix.
Rusty Russell [Mon, 3 Dec 2012 08:59:39 +0000 (19:29 +1030)]
tal/str: use tal_ prefix.

It's short, and much clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal/str: make tal_count() work for strsplit.
Rusty Russell [Mon, 3 Dec 2012 08:59:39 +0000 (19:29 +1030)]
tal/str: make tal_count() work for strsplit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: add tal_count() and length properties for arrays.
Rusty Russell [Mon, 3 Dec 2012 08:59:39 +0000 (19:29 +1030)]
tal: add tal_count() and length properties for arrays.

Unlike talloc, we don't have a count on everything, just on array
allocations.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: adding or removing a notifier/destructor can be const.
Rusty Russell [Mon, 3 Dec 2012 08:59:38 +0000 (19:29 +1030)]
tal: adding or removing a notifier/destructor can be const.

You don't need write access to the context to attach a destructor;
it's meta.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: optimize case where no (non-destructor) notifiers are used.
Rusty Russell [Mon, 3 Dec 2012 08:59:38 +0000 (19:29 +1030)]
tal: optimize case where no (non-destructor) notifiers are used.

$ for i in `seq 10`; do ./samba-allocs talloc.dump --tal; done | stats.c --trim-outliers
Before:
Read 25998 nodes
Tal time:                2857988-2981158(2904324)ns
Tal_free time:           2417170-2582088(2470931)ns
Single tal_free time:    1551654-1609583(1575984)ns

After:
Read 25998 nodes
Tal time:                2780974-2901323(2839352)ns
Tal_free time:           2241725-2355309(2285165)ns
Single tal_free time:    1549908-1612485(1566609)ns

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: use notifier infrastructure for destructors.
Rusty Russell [Mon, 3 Dec 2012 08:59:38 +0000 (19:29 +1030)]
tal: use notifier infrastructure for destructors.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: add general notifiers.
Rusty Russell [Mon, 3 Dec 2012 08:59:38 +0000 (19:29 +1030)]
tal: add general notifiers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: add del_destructor().
Rusty Russell [Mon, 3 Dec 2012 08:59:38 +0000 (19:29 +1030)]
tal: add del_destructor().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: check headers more carefully.
Rusty Russell [Mon, 3 Dec 2012 08:59:38 +0000 (19:29 +1030)]
tal: check headers more carefully.

We sanity check tal headers by ensuring that the pointers are in the
bounds of things we've allocated.  But the first one we check is the
prop ptr, which may also be a literal: this is_literal() dereferences
the pointer, which means we usually crash here if it's not a tal
object.

Move that last, and we have far more success with our sanity checking.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotal: simplify.
Rusty Russell [Mon, 3 Dec 2012 08:59:38 +0000 (19:29 +1030)]
tal: simplify.

All the effort trying to keep the header size down to 2 pointers turns
out to be wasted.  In addition, getting the parent of a tal pointer is
now much faster.

./samba-allocs talloc.dump --tal-size:
Before:
Virtual size = 9633792, RSS = 3952640
After:
Virtual size = 9793536, RSS = 3948544

And we're much faster now, esp. on free.

./samba-allocs talloc.dump --tal:
Before:
Tal time:                2718068ns
Tal_free time:           3360258ns
Single tal_free time:    1667412ns
After:
Tal time:                2788287ns
Tal_free time:           2290167ns
Single tal_free time:    1566998ns

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Header from folded patch 'tal-fix-set-destroying-bit.patch':

tal: fix destroying bit usage.

Actually looking at a destroying contexts' parent didn't work, and a couple
of places didn't filter out the destroying bit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agoccanlint: handle nested modules when mentioned in examples.
Rusty Russell [Mon, 3 Dec 2012 08:59:23 +0000 (19:29 +1030)]
ccanlint: handle nested modules when mentioned in examples.

If we see an ccan include line in an example, we add that to the
dependencies to try to build the example, but we didn't handle nested
modules.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
7 years agotools: don't abort on malformed documentation lines.
Rusty Russell [Mon, 3 Dec 2012 07:55:41 +0000 (18:25 +1030)]
tools: don't abort on malformed documentation lines.

ccanlint would abort with 'Malformed line 53' if there was a bad header.
That's very poor, and deeply unhelpful.

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