Thanks for reviewing the patch. V2 is attached, see my comments below.
> On 31 Mar 2015, at 02:36, Rusty Russell <rusty@rustcorp.com.au> wrote:
>
> Delio Brignoli <brignoli.delio@gmail.com> writes:
>> Hi All,
>>
>> tal_stack implements a (trivial) stack of tal contexts. Would this be a worthy addition to CCAN? (not necessarily in its current form).
[…]
> This is cute; I’ve seen similar used in Samba. It's
Indeed, it was inspired by talloc_stack.h ;-)
[…]
> You are missing a _info file: I would create that, and put your example
> in an Example: section there.
I moved the module and tests under can/tal/stack and added a LICENSE and _info.
> Other random advice:
> 1) You should also document the tal_newframe function (particularly note
> that you're expected to tal_free the result, and that it will free
> any future unfreed frames). And note that it’s not threadsafe.
Done.
> 2) You probably want tal_newframe to be a macro, and hand file and line
> thought to the tal_alloc_ call. That makes debugging nicer when
> you iterate the tree.
Done. The macro is calling a tal_newframe_() function because I’d rather not make the module’s stack variable ‘public’.
> 3) Consider whether you want to declare a dummy type 'struct tal_stack'.
> Probably pretty unnecessary since it’s quite clear.
Skipped this one. We can declare it later if we change our minds.
Thanks
—
Delio
From c2ceb9258d97b0dcb72e7b6986cfd2bd394b254e Mon Sep 17 00:00:00 2001
From: Delio Brignoli <dbrignoli@audioscience.com>
Date: Sun, 15 Mar 2015 13:26:40 +0100
Subject: [PATCH] tal_stack: new module - V2
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Peter Barker [Fri, 10 Apr 2015 01:26:23 +0000 (11:26 +1000)]
ccanlint: avoid segfault when module_builds' linking fails
In the case that the objects built but linking failed, module_builds.c
called score_file_error with a NULL ccan_file object and 0 for line
number.
score_file_error assumed that the ccan_file object it is passed was
not-NULL when appending file errors to the score's aggregate error
string. It attempted to dereference it to get "fullname".
score_error was factored out from score_file_error. It takes a
"source" parameter, which is the file's full name (and possibly line
number) in the score_file_error case, and the ccan module name in the
case of link failure.
Eric Wong [Fri, 24 Oct 2014 22:02:32 +0000 (22:02 +0000)]
list: add list_for_each_rev_safe{,_off} macros
Deleting while iterating backwards will be needed in the
Ruby st_foreach_reverse_check implementation if we decide
to port Ruby's st.c to use ccan/list.
Signed-off-by: Eric Wong <normalperson@yhbt.net> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Eric Wong [Fri, 24 Oct 2014 22:02:31 +0000 (22:02 +0000)]
list: add list_for_each_rev_off macro
And re-implement list_for_each_rev in terms of list_for_each_rev_off
to avoid duplicating iteration logic.
Signed-off-by: Eric Wong <normalperson@yhbt.net> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Eric Wong [Fri, 24 Oct 2014 22:02:30 +0000 (22:02 +0000)]
list: new list_for_each{, _safe}_off_dir_ macros
These internal iteration macros will make implementing reverse
iteration simpler. For now, reimplement existing list_for_each_off
and list_for_each_safe_off macros on top of these macros to
prove they pass existing tests.
Signed-off-by: Eric Wong <normalperson@yhbt.net> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Eric Wong [Fri, 24 Oct 2014 22:02:29 +0000 (22:02 +0000)]
list: list_swap to exchange elements
This allows deleting and re-inserting an element in place
of the deleted element without branching.
Signed-off-by: Eric Wong <normalperson@yhbt.net> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Eric Wong [Fri, 24 Oct 2014 22:02:28 +0000 (22:02 +0000)]
list: list_add_after and list_add_before functions
These make it easy to add a new element before or after an
existing element in the middle of the list.
The existing list_add and list_add_tail functions are trivially
reimplemented on top of these new functions.
Signed-off-by: Eric Wong <normalperson@yhbt.net> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Stuart Longland [Fri, 22 Aug 2014 23:25:09 +0000 (09:25 +1000)]
stringbuilder: Functions for joining strings.
This is a small couple of functions for joining lists of strings
together. The lists can either be varadic arguments or arrays, and
delimiters are optional.
This patch incorporates some advice from David Gibson on the original
module.
Rusty Russell [Fri, 20 Mar 2015 01:06:52 +0000 (11:36 +1030)]
ntdb: fix up tests.
Mainly include path fixes.
Also Samba's unit tests were enhanced to detect the prefixes
helpapi and helprun to indicate an object was to be linked against
only api/run tests. We hack around that by #including the helper
code instead.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
David Disseldorp [Fri, 13 Mar 2015 16:45:16 +0000 (17:45 +0100)]
ntdb: next-generation trivial key-value database
ntdb is a partial rewrite of Samba's Trivial Database, providing > 4GB
database scalability and an improved API.
Obtained from the Samba repository at git://git.samba.org/samba.git, as
of bd13405e8570e9a5942165a8c52a2bc3fdc9d96e.
Rusty Russell [Wed, 29 Oct 2014 05:32:46 +0000 (16:02 +1030)]
timer: change timers_expire() to return a single timer.
The linked list method was problematic, especially if timers delete
other expired timers (eg. the next one in the expired list: the timer_del
will delete it from expired, but that's a bit unexpected).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
David Gibson [Sat, 11 Oct 2014 16:46:57 +0000 (18:46 +0200)]
bytestring: Add initializer macro
The BYTESTRING macro is constant, since it's designed to take a string
literal, but it doesn't count as constant since it involves an (inlined)
function call. That means it can't be used in a static storage duration
initializer.
Unfortunately, I can't see a portable way to make something which can be
used as an initializer, but which can also be used in other contexts where
BYTESTRING() can be used, so this patch introduces BYTESTRING_INIT() which
is similar to BYTESTRING() but produces an initializer.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Mon, 28 Jul 2014 09:33:33 +0000 (19:33 +1000)]
bytestring: Split bytestrings by a string delimiter
This introduces the functions bytestring_splitstr_first() and
bytestring_splitstr_next() which can be used to iterate through substrings
of a bytestring separated by a specified substring.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Mon, 28 Jul 2014 09:31:36 +0000 (19:31 +1000)]
bytestring: Split bytestrings by a set of character delimiters
This introduces the functions bytestring_splitchrs_first() and
bytestring_splitchrs_next() which can be used to iterate through substrings
of a bytestring separated by any of a given set of delimiter characters.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Mon, 28 Jul 2014 09:31:11 +0000 (19:31 +1000)]
bytestring: Split bytestrings by a character delimiter
This introduces the functions bytestring_splitchr_first() and
bytestring_splitchr_next() which can be used to iterate through substrings
of a bytestring separated by a single, specified delimiter character.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Wed, 22 Oct 2014 13:37:22 +0000 (15:37 +0200)]
bytestring: Implement bytestring_spn() and bytestring_cspn()
Add bytestring_spn() and bytestring_cspn() functions which, in analogy to
strspn() and strcspn() return the lengths of initial sub-bytestrings which
either contain only a given set of bytes, or anything except a given set
of bytes.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Wed, 22 Oct 2014 11:56:53 +0000 (13:56 +0200)]
mem: Implement memrchr()
The memrchr() function, which works like memchr(), but searches from the
back of the region to the front is implemented in the GNU C library, but
isn't standard.
This patch adds an implementation of the function to the mem module, when
it's not available in the system C library.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Wed, 22 Oct 2014 11:56:52 +0000 (13:56 +0200)]
mem: Correct testcases
Currently the 'mem' module testcases use test/run.c even though they don't
rely on access to the module internals. They're also missing an include
of mem.c, which has the effect that on systems with a C library memmem()
implementaiton, only that is tested, not the (re-)implementation in the
mem module itself. This corrects that by moving run.c to api.c/
Additionally, the memmem() testcases don't cover the case where the
"needle" appears multiple times in the "haystack". This patch also adds
such a test.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Wed, 22 Oct 2014 11:56:51 +0000 (13:56 +0200)]
mem: Rename memmem module to mem
Currently the 'memmem' module does nothing but provide an implementation of
the memmem() function if it is missing from the standard C library.
However there are other functions (e.g. memrchr()) also missing from some
C library implementations, so rename the module to mem to allow future
inclusion of other functions.
This also updates the rfc822 module - the only existing user of the
memmem module - to use the new name.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Chris McCormick [Sat, 25 Oct 2014 13:19:15 +0000 (21:19 +0800)]
New page layout, font, background image. Replaced table tags with headers and paragraph tags as appropriate. Redesigned logo. Added stylesheet to specify layout more easily. Meta tag for mobile device friendliness.
Chris McCormick [Wed, 22 Oct 2014 16:00:46 +0000 (00:00 +0800)]
Changed the look of the website. Added a new logo design (source SVG included). Fixed an issue with junkcode prefix not being set (broken links and images on current site). Removed /tmp/ccan in clean as it was preventing 'make webpages' running twice. Brought the HTML closer to standards compliance (doctype, encoding). Added meta tag for mobile device browsers to render nicely.
The literal "1" in "1 << (sizeof(long{, long})*8 - 1)" should be 1L or
1LL, so that the expression has the right type. Otherwise, the shift
is only by 31 bits on x86 (other platforms may behave differently). To
avoid language lawyers shouting UB at me, and since
__builtin_ctz{,l,ll} formally takes unsigned parameters, use UL and
ULL suffixes.
Also, fix a typo (missing parenthesis) in the code for CTZLL causing
the detection of __builtin_ctzll to always fail for the wrong reason.
Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
David Gibson [Thu, 2 Oct 2014 14:14:57 +0000 (00:14 +1000)]
bitmap: Switch bit indices to unsigned long
Currently all bit indices used in the bitmap module are represented as
'int'. These conceptually should be unsigned. In additional limiting
these to ints potentially prevents use of very large bitmaps. So, change
these all to unsigned long.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
David Gibson [Tue, 9 Sep 2014 14:22:52 +0000 (00:22 +1000)]
container_of: Add container_of_or_null()
It's quite common to have a pointer which could be either a pointer to a
structure member, or NULL. This needs special casing with container_of(),
or it will convert NULL into something strange.
This patch adds container_of_or_null(), which will return NULL if passed
(an appropriately typed) NULL, or the containining structure as
container_of() otherwise.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>