tal: fix benchmark/Makefile

We need ccan/take here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Makefile: score nested modules.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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>
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>
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>
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>
tal: add del_destructor().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
tal: add general notifiers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
tal: use notifier infrastructure for destructors.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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>
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>
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>
tal/str: make tal_count() work for strsplit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
tal/str: use tal_ prefix.

It's short, and much clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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>
tal: add tal_expand().

Helper to reallocate and append to an array.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
tal/str: add tal_strcat().

Useful for joining two strings.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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>
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>
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>