[ccan] [PATCH] btree: Add custom allocator interface.

David Gibson david at gibson.dropbear.id.au
Mon Feb 8 13:17:38 AEDT 2016


On Sun, Feb 07, 2016 at 10:10:39AM +1000, stuartl at longlandclan.id.au wrote:
> From: Stuart Longland <me at vk4msl.id.au>
> 
> This provides a way for btree to be used with external allocator
> libraries such as the tal or talloc modules.

Rusty's comments seconded, and a couple of my own:

> ---
>  ccan/btree/btree.c | 194 +++++++++++++++++++++++++++++++----------------------
>  ccan/btree/btree.h |  29 +++++---
>  2 files changed, 136 insertions(+), 87 deletions(-)
> 
> diff --git a/ccan/btree/btree.c b/ccan/btree/btree.c
> index 636edbc..5bb2435 100644
> --- a/ccan/btree/btree.c
> +++ b/ccan/btree/btree.c
> @@ -29,12 +29,15 @@
>  #define MAX (BTREE_ITEM_MAX)
>  #define MIN (BTREE_ITEM_MAX >> 1)
>  
> -static struct btree_node *node_alloc(int internal);
> +static struct btree_node *node_alloc(const struct btree_allocator* alloc, int internal);
>  static void node_delete(struct btree_node *node, struct btree *btree);
> +static void node_free(struct btree_node *node);
>  
>  static void branch_begin(btree_iterator iter);
>  static void branch_end(btree_iterator iter);
>  static void begin_end_lr(btree_iterator iter, struct btree_node *node, int lr);
> +static void* default_malloc(const struct btree_allocator* alloc, size_t size);

Existing style in this function suggests "void *foo" rather than
"void* foo".

[snip]
> +/* Default allocator implementation */
> +const struct btree_allocator BTREE_DEFAULT_ALLOCATOR = {

Use of all-caps for a non-macro is a bit unexpected.

> +	.malloc = default_malloc,
> +	.free = default_free,
> +};

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/ccan/attachments/20160208/5c69a7cf/attachment.sig>


More information about the ccan mailing list