Cody P Schafer [Sun, 16 Aug 2015 22:54:37 +0000 (18:54 -0400)]
configurator: avoid leaks that LeakSanitizer doesn't like
These leaks aren't really an issue since they are completely bounded,
but if one is building with leak sanitizer enabled (as
-fsanitize=address does in gcc-5.1), it kills the configurator, which
isn't very useful for us. Add the few free() calls it's looking for.
This is not an actual code issue, they just workaround
some optional compiler peculiarities.
Signed-off-by: Cody P Schafer <dev@codyps.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (split off leak change)
David Gibson [Mon, 11 May 2015 10:35:34 +0000 (22:35 +1200)]
aga: Add lazytrie testcase
This adds a more complex testcase to the aga module. This one is a trie
(basically a radix tree for strings).
It demonstrates different ways of constructing edge information from an
internal representation than the existing testcases. Importantly, it also
demonstrates aga's ability to cope with the edge function lazily
constructing nodes on the fly.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Thu, 7 May 2015 11:29:19 +0000 (21:29 +1000)]
aga: Testcase for attempt to run concurrent algorithms
The aga algorithms can't be run concurrently, because they store state
information in the aga_node structures. However, they are supposed to
detect an attempt to re-enter and safely report an error. This adds a
testcase for this.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Thu, 21 May 2015 09:23:19 +0000 (21:23 +1200)]
aga: Simple test graphs
This adds code for a number of example graphs for use in tests of the aga
module. They also demonstrate several different ways of constructing
graphs using the aga callbacks.
It adds one actual testcase, which just verifies that the example graph
look like what they're supposed to. Specifically it computes a set of
adjacency lists for the example graphs from the callback code, then
compares that to a canned example of what it should be.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Thu, 18 Jun 2015 09:30:18 +0000 (19:30 +1000)]
avl: Use definitions from order module
The AvlCompare type defined in the avl module is identical in signature to
the compare function used by qsort() and bsearch(). That has a common
definition in the new order module, so use that rather than defining its
own.
In addition use the standard comparison functions from order where possible
for the avl test code.
Cc: Joey Adams <joeyadams3.14159@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Thu, 18 Jun 2015 09:29:37 +0000 (19:29 +1000)]
asort: Use order module definitions
The asort routine takes a user-supplied comparison function. Use the
definitions from the new order module to slightly simplify the declaration
and handling of this function.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Tue, 2 Jun 2015 07:30:58 +0000 (17:30 +1000)]
order: Scalar comparison functions
Extend the order module to provide simple, standard, comparison
callbacks for scalar types (i.e. integer and floating point types).
In addition to the usual variants comparing a plain scalar, this also
provides helper macros to construct a suitably typed callback and context
pointer to order structures by a specified scalar field.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Tue, 2 Jun 2015 07:26:49 +0000 (17:26 +1000)]
order: Module for comparison callbacks
Many common algorithms take a callback for comparing items - effectively
giving the items a user defined order.
For example, the standard library qsort() and bsearch() routines take such
a callback. The ccan/avl module takes an identical one. The ccan/asort
and ccan/asearch modules use a different variant: their callback takes an
additional context parameter, and is also typed via use of macros and
typesafe_cb.
This module provides helper types and macros for easily declaring any of
the common variants on comparison functions: the 2-parameter untyped form
(as used by qsort), the 3-parameter untyped form (used by the asort back
end) and the 3-parameter typed form (used by the asort front end). It
provides a wrapper macro for doing the typesafe_cb conversion from
3-parameter typed to 3-parameter untyped.
It also provides a container struct to describe both a comparison callback
and a context value as a single structure. This also comes in both
untyped and typed variants.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Sat, 13 Jun 2015 14:24:57 +0000 (00:24 +1000)]
lqueue: Allow a queueu to be initialized from an existing back element
There are occasional cases where you might construct a valid queue, and
retain a direct pointer to the back element, but not the struct lqueue
used to build it.
This patch adds a new lqueue_init_from_back() macro to reconstruct a valid
struct lqueue from the element pointer for cases like this.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Sat, 13 Jun 2015 14:23:39 +0000 (00:23 +1000)]
lstack: Allow a stack to be initialized from an existing top element
There are occasional cases where you might construct a valid stack, and
retain a direct pointer to the top element, but not the struct lstack
used to build it.
This patch adds a new lstack_init_from_top() macro to reconstruct a valid
struct lstack from the element pointer for cases like this.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson [Wed, 27 May 2015 14:17:35 +0000 (00:17 +1000)]
asearch: Add context pointer to asearch comparison callback
asearch, like the standard library bsearch, takes a comparison callback.
Like bsearch() that callback doesn't include a user supplied context
pointer. As well as being generally limiting, that makes the comparison
functions used by asearch gratuitously different from those used by the
asort module.
This patch alters this. Note that this is an incompatible change to the
asearch interface. I think this is worth it to correct the oversight, but
others might disagree. At present the only user within ccan is ntdb, which
is corrected to match.
This means actually supplying a binary search implementation, rather than
relying on bsearch() from the standard library. We follow the lead of the
asort module and steal^H^H^H^H^Hadapt the implementation from glibc.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
David Gibson [Wed, 27 May 2015 14:17:34 +0000 (00:17 +1000)]
asearch: Correct license tag to LGPL 2.1+
The _info file for asearch currently gives the license as just "LGPL".
That gives a warning from ccanlint, because it interprets that as the
latest LGPL 3 whereas asearch.h and the license link indicate it's actually
LGPL 2.1+.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
David Gibson [Tue, 26 May 2015 12:56:50 +0000 (22:56 +1000)]
ptrint: Module for encoding integers into void * pointers
For callbacks which need a void * context pointer in the general case,
there are often simpler cases where an integer would suffice. These are
often handled by casting the integer into a pointer, rather than having
to allocate that integer somewhere.
This adds a module with some helpers for this. It has some advantages over
direct casts:
* It uses pointer arithmetic against NULL instead of casts which should
make it more portable, even to weird platforms with odd representations
for NULL. I don't know the C standard well enough to know if it's
totally portable though.
* In particular it means that the truth value of the pointer
representation matches that of the encoded integer.
* The conversion functions are inlines providing more type safety than
raw casts.
* It uses a ptrint_t * type which can be used to mark such pointer
encoded integers. ptrint_t is a deliberately incomplete type so such
pointers can never be dereferenced.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Rusty Russell [Tue, 19 May 2015 06:59:54 +0000 (16:29 +0930)]
timer: fix two corruption bugs.
We fill the upper buckets after we've moved on from the first bucket
in this layer. This means two things:
1) If we have to look at an upper layer, we need to look at the next bucket,
unless offset is 0.
2) We need to keep looking up layers in the corner case, too.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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.