mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
ccan: update so we can apply notifiers to toplevel "NULL".
This will make leak detection more thorough. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
898655f40c
commit
c02ab124aa
13 changed files with 69 additions and 44 deletions
|
@ -1,3 +1,3 @@
|
|||
CCAN imported from http://ccodearchive.net.
|
||||
|
||||
CCAN version: init-2440-g55d81423
|
||||
CCAN version: init-2442-ga8722345
|
||||
|
|
|
@ -35,7 +35,7 @@ static bool is_reverse_sorted(const int arr[], unsigned int size)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void psuedo_random_array(int arr[], unsigned int size)
|
||||
static void pseudo_random_array(int arr[], unsigned int size)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
|
@ -52,14 +52,14 @@ int main(void)
|
|||
|
||||
plan_tests(4);
|
||||
|
||||
psuedo_random_array(tmparr, TEST_SIZE);
|
||||
pseudo_random_array(tmparr, TEST_SIZE);
|
||||
ok1(!is_sorted(tmparr, TEST_SIZE));
|
||||
ok1(!is_reverse_sorted(tmparr, TEST_SIZE));
|
||||
|
||||
asort(tmparr, TEST_SIZE, test_cmp, &multiplier);
|
||||
ok1(is_sorted(tmparr, TEST_SIZE));
|
||||
|
||||
psuedo_random_array(tmparr, TEST_SIZE);
|
||||
pseudo_random_array(tmparr, TEST_SIZE);
|
||||
multiplier = -1;
|
||||
asort(tmparr, TEST_SIZE, test_cmp, &multiplier);
|
||||
ok1(is_reverse_sorted(tmparr, TEST_SIZE));
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* @name: the name for this set of autodata
|
||||
* @type: the type this autodata points to
|
||||
*
|
||||
* This macro is usually placed in a header: it must preceed any
|
||||
* This macro is usually placed in a header: it must precede any
|
||||
* autodata functions in the file.
|
||||
*
|
||||
* Example:
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/**
|
||||
* bitops_ffs32: find first set bit in a uint32_t
|
||||
*
|
||||
* Returns 1 for least signficant bit, 32 for most significant bit, 0
|
||||
* Returns 1 for least significant bit, 32 for most significant bit, 0
|
||||
* for no bits set.
|
||||
*/
|
||||
static inline int bitops_ffs32(uint32_t u)
|
||||
|
@ -26,7 +26,7 @@ static inline int bitops_ffs32(uint32_t u)
|
|||
/**
|
||||
* bitops_ffs64: find lowest set bit in a uint64_t
|
||||
*
|
||||
* Returns 1 for least signficant bit, 32 for most significant bit, 0
|
||||
* Returns 1 for least significant bit, 32 for most significant bit, 0
|
||||
* for no bits set.
|
||||
*/
|
||||
static inline int bitops_ffs64(uint64_t u)
|
||||
|
@ -46,8 +46,8 @@ int bitops_ffs64(uint64_t u);
|
|||
/**
|
||||
* bitops_clz32: count leading zeros in a uint32_t (must not be 0)
|
||||
*
|
||||
* Returns 0 if most signficant bit is set, 31 if only least
|
||||
* signficant bit is set.
|
||||
* Returns 0 if most significant bit is set, 31 if only least
|
||||
* significant bit is set.
|
||||
*/
|
||||
static inline int bitops_clz32(uint32_t u)
|
||||
{
|
||||
|
@ -58,8 +58,8 @@ static inline int bitops_clz32(uint32_t u)
|
|||
/**
|
||||
* bitops_clz64: count leading zeros in a uint64_t (must not be 0)
|
||||
*
|
||||
* Returns 0 if most signficant bit is set, 63 if only least
|
||||
* signficant bit is set.
|
||||
* Returns 0 if most significant bit is set, 63 if only least
|
||||
* significant bit is set.
|
||||
*/
|
||||
static inline int bitops_clz64(uint64_t u)
|
||||
{
|
||||
|
@ -79,8 +79,8 @@ int bitops_clz64(uint64_t u);
|
|||
/**
|
||||
* bitops_ctz32: count trailing zeros in a uint32_t (must not be 0)
|
||||
*
|
||||
* Returns 0 if least signficant bit is set, 31 if only most
|
||||
* signficant bit is set.
|
||||
* Returns 0 if least significant bit is set, 31 if only most
|
||||
* significant bit is set.
|
||||
*/
|
||||
static inline int bitops_ctz32(uint32_t u)
|
||||
{
|
||||
|
@ -91,8 +91,8 @@ static inline int bitops_ctz32(uint32_t u)
|
|||
/**
|
||||
* bitops_ctz64: count trailing zeros in a uint64_t (must not be 0)
|
||||
*
|
||||
* Returns 0 if least signficant bit is set, 63 if only most
|
||||
* signficant bit is set.
|
||||
* Returns 0 if least significant bit is set, 63 if only most
|
||||
* significant bit is set.
|
||||
*/
|
||||
static inline int bitops_ctz64(uint64_t u)
|
||||
{
|
||||
|
@ -111,7 +111,7 @@ int bitops_ctz64(uint64_t u);
|
|||
/**
|
||||
* bitops_ls32: find lowest set bit in a uint32_t (must not be zero)
|
||||
*
|
||||
* Returns 0 for least signficant bit, 31 for most significant bit.
|
||||
* Returns 0 for least significant bit, 31 for most significant bit.
|
||||
*/
|
||||
static inline int bitops_ls32(uint32_t u)
|
||||
{
|
||||
|
@ -122,7 +122,7 @@ static inline int bitops_ls32(uint32_t u)
|
|||
/**
|
||||
* bitops_ls64: find lowest set bit in a uint64_t (must not be zero)
|
||||
*
|
||||
* Returns 0 for least signficant bit, 63 for most significant bit.
|
||||
* Returns 0 for least significant bit, 63 for most significant bit.
|
||||
*/
|
||||
static inline int bitops_ls64(uint64_t u)
|
||||
{
|
||||
|
@ -133,7 +133,7 @@ static inline int bitops_ls64(uint64_t u)
|
|||
/**
|
||||
* bitops_hs32: find highest set bit in a uint32_t (must not be zero)
|
||||
*
|
||||
* Returns 0 for least signficant bit, 31 for most significant bit.
|
||||
* Returns 0 for least significant bit, 31 for most significant bit.
|
||||
*/
|
||||
static inline int bitops_hs32(uint32_t u)
|
||||
{
|
||||
|
@ -144,7 +144,7 @@ static inline int bitops_hs32(uint32_t u)
|
|||
/**
|
||||
* bitops_hs64: find highest set bit in a uint64_t (must not be zero)
|
||||
*
|
||||
* Returns 0 for least signficant bit, 63 for most significant bit.
|
||||
* Returns 0 for least significant bit, 63 for most significant bit.
|
||||
*/
|
||||
static inline int bitops_hs64(uint64_t u)
|
||||
{
|
||||
|
@ -155,7 +155,7 @@ static inline int bitops_hs64(uint64_t u)
|
|||
/**
|
||||
* bitops_lc32: find lowest clear bit in a uint32_t (must not be 0xFFFFFFFF)
|
||||
*
|
||||
* Returns 0 for least signficant bit, 31 for most significant bit.
|
||||
* Returns 0 for least significant bit, 31 for most significant bit.
|
||||
*/
|
||||
static inline int bitops_lc32(uint32_t u)
|
||||
{
|
||||
|
@ -165,7 +165,7 @@ static inline int bitops_lc32(uint32_t u)
|
|||
/**
|
||||
* bitops_lc64: find lowest clear bit in a uint64_t (must not be 0xFFFFFFFFFFFFFFFF)
|
||||
*
|
||||
* Returns 0 for least signficant bit, 63 for most significant bit.
|
||||
* Returns 0 for least significant bit, 63 for most significant bit.
|
||||
*/
|
||||
static inline int bitops_lc64(uint64_t u)
|
||||
{
|
||||
|
@ -175,7 +175,7 @@ static inline int bitops_lc64(uint64_t u)
|
|||
/**
|
||||
* bitops_hc32: find highest clear bit in a uint32_t (must not be 0xFFFFFFFF)
|
||||
*
|
||||
* Returns 0 for least signficant bit, 31 for most significant bit.
|
||||
* Returns 0 for least significant bit, 31 for most significant bit.
|
||||
*/
|
||||
static inline int bitops_hc32(uint32_t u)
|
||||
{
|
||||
|
@ -185,7 +185,7 @@ static inline int bitops_hc32(uint32_t u)
|
|||
/**
|
||||
* bitops_hc64: find highest clear bit in a uint64_t (must not be 0xFFFFFFFFFFFFFFFF)
|
||||
*
|
||||
* Returns 0 for least signficant bit, 63 for most significant bit.
|
||||
* Returns 0 for least significant bit, 63 for most significant bit.
|
||||
*/
|
||||
static inline int bitops_hc64(uint64_t u)
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@ int main(int argc, char *argv[])
|
|||
block.h.u.u8[3], block.h.u.u8[4], block.h.u.u8[5],
|
||||
(unsigned long long)time_to_nsec(diff));
|
||||
|
||||
/* Now, don't re-initalize every time; use Transform */
|
||||
/* Now, don't re-initialize every time; use Transform */
|
||||
memset(&block, 0, sizeof(block));
|
||||
sha256(&block.h, &n, sizeof(n));
|
||||
block.u8[sizeof(block.h)] = 0x80;
|
||||
|
|
|
@ -286,7 +286,7 @@ void *intmap_first_(const struct intmap *map, intmap_index_t *indexp);
|
|||
/**
|
||||
* uintmap_after - get the closest following index in an unsigned intmap
|
||||
* @umap: the typed intmap to iterate through.
|
||||
* @indexp: the preceeding index (may not exist)
|
||||
* @indexp: the preceding index (may not exist)
|
||||
*
|
||||
* Returns NULL if the there is no entry > @indexp, otherwise
|
||||
* populates *@indexp and returns the lowest entry > @indexp.
|
||||
|
@ -300,7 +300,7 @@ void *intmap_after_(const struct intmap *map, intmap_index_t *indexp);
|
|||
/**
|
||||
* sintmap_after - get the closest following index in a signed intmap
|
||||
* @smap: the typed intmap to iterate through.
|
||||
* @indexp: the preceeding index (may not exist)
|
||||
* @indexp: the preceding index (may not exist)
|
||||
*
|
||||
* Returns NULL if the there is no entry > @indexp, otherwise
|
||||
* populates *@indexp and returns the lowest entry > @indexp.
|
||||
|
|
|
@ -708,7 +708,7 @@ static inline void list_prepend_list_(struct list_head *to,
|
|||
/**
|
||||
* list_for_each_off - iterate through a list of memory regions.
|
||||
* @h: the list_head
|
||||
* @i: the pointer to a memory region wich contains list node data.
|
||||
* @i: the pointer to a memory region which contains list node data.
|
||||
* @off: offset(relative to @i) at which list node data resides.
|
||||
*
|
||||
* This is a low-level wrapper to iterate @i over the entire list, used to
|
||||
|
@ -740,7 +740,7 @@ static inline void list_prepend_list_(struct list_head *to,
|
|||
/**
|
||||
* list_for_each_rev_off - iterate through a list of memory regions backwards
|
||||
* @h: the list_head
|
||||
* @i: the pointer to a memory region wich contains list node data.
|
||||
* @i: the pointer to a memory region which contains list node data.
|
||||
* @off: offset(relative to @i) at which list node data resides.
|
||||
*
|
||||
* See list_for_each_off for details
|
||||
|
@ -752,7 +752,7 @@ static inline void list_prepend_list_(struct list_head *to,
|
|||
* list_for_each_safe_off - iterate through a list of memory regions, maybe
|
||||
* during deletion
|
||||
* @h: the list_head
|
||||
* @i: the pointer to a memory region wich contains list node data.
|
||||
* @i: the pointer to a memory region which contains list node data.
|
||||
* @nxt: the structure containing the list_node
|
||||
* @off: offset(relative to @i) at which list node data resides.
|
||||
*
|
||||
|
@ -771,7 +771,7 @@ static inline void list_prepend_list_(struct list_head *to,
|
|||
* list_for_each_rev_safe_off - iterate backwards through a list of
|
||||
* memory regions, maybe during deletion
|
||||
* @h: the list_head
|
||||
* @i: the pointer to a memory region wich contains list node data.
|
||||
* @i: the pointer to a memory region which contains list node data.
|
||||
* @nxt: the structure containing the list_node
|
||||
* @off: offset(relative to @i) at which list node data resides.
|
||||
*
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
/**
|
||||
* str/hex - hex-to-string conversions and vice-versa
|
||||
*
|
||||
* This code contains simple routines for hexidecimal strings.
|
||||
* This code contains simple routines for hexadecimal strings.
|
||||
*
|
||||
* License: CC0 (Public domain)
|
||||
* Author: Rusty Russell <rusty@rustcorp.com.au>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
/**
|
||||
* hex_decode - Unpack a hex string.
|
||||
* @str: the hexidecimal string
|
||||
* @str: the hexadecimal string
|
||||
* @slen: the length of @str
|
||||
* @buf: the buffer to write the data into
|
||||
* @bufsize: the length of @buf
|
||||
|
|
|
@ -191,14 +191,14 @@ static void *from_tal_hdr(const struct tal_hdr *hdr)
|
|||
return (void *)(hdr + 1);
|
||||
}
|
||||
|
||||
#ifdef TAL_DEBUG
|
||||
static void *from_tal_hdr_or_null(struct tal_hdr *hdr)
|
||||
static void *from_tal_hdr_or_null(const struct tal_hdr *hdr)
|
||||
{
|
||||
if (hdr == &null_parent.hdr)
|
||||
return NULL;
|
||||
return from_tal_hdr(hdr);
|
||||
}
|
||||
|
||||
#ifdef TAL_DEBUG
|
||||
static struct tal_hdr *debug_tal(struct tal_hdr *tal)
|
||||
{
|
||||
tal_check(from_tal_hdr_or_null(tal), "TAL_DEBUG ");
|
||||
|
@ -234,7 +234,7 @@ static void notify(const struct tal_hdr *ctx,
|
|||
else
|
||||
n->u.destroy(from_tal_hdr(ctx));
|
||||
} else
|
||||
n->u.notifyfn(from_tal_hdr(ctx), type,
|
||||
n->u.notifyfn(from_tal_hdr_or_null(ctx), type,
|
||||
(void *)info);
|
||||
}
|
||||
}
|
||||
|
@ -495,7 +495,7 @@ void *tal_steal_(const tal_t *new_parent, const tal_t *ctx)
|
|||
old_parent = ignore_destroying_bit(t->parent_child)->parent;
|
||||
|
||||
if (unlikely(!add_child(newpar, t))) {
|
||||
/* We can always add to old parent, becuase it has a
|
||||
/* We can always add to old parent, because it has a
|
||||
* children property already. */
|
||||
if (!add_child(old_parent, t))
|
||||
abort();
|
||||
|
@ -528,7 +528,7 @@ bool tal_add_destructor2_(const tal_t *ctx, void (*destroy)(void *me, void *arg)
|
|||
bool tal_add_notifier_(const tal_t *ctx, enum tal_notify_type types,
|
||||
void (*callback)(tal_t *, enum tal_notify_type, void *))
|
||||
{
|
||||
tal_t *t = debug_tal(to_tal_hdr(ctx));
|
||||
struct tal_hdr *t = debug_tal(to_tal_hdr_or_null(ctx));
|
||||
struct notifier *n;
|
||||
|
||||
assert(types);
|
||||
|
@ -556,7 +556,7 @@ bool tal_del_notifier_(const tal_t *ctx,
|
|||
void (*callback)(tal_t *, enum tal_notify_type, void *),
|
||||
bool match_extra_arg, void *extra_arg)
|
||||
{
|
||||
struct tal_hdr *t = debug_tal(to_tal_hdr(ctx));
|
||||
struct tal_hdr *t = debug_tal(to_tal_hdr_or_null(ctx));
|
||||
enum tal_notify_type types;
|
||||
|
||||
types = del_notifier_property(t, callback, match_extra_arg, extra_arg);
|
||||
|
|
|
@ -227,7 +227,7 @@ enum tal_notify_type {
|
|||
|
||||
/**
|
||||
* tal_add_notifier - add a callback function when this context changes.
|
||||
* @ptr: The tal allocated object.
|
||||
* @ptr: The tal allocated object, or NULL.
|
||||
* @types: Bitwise OR of the types the callback is interested in.
|
||||
* @callback: the function to call.
|
||||
*
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
static enum tal_notify_type expect;
|
||||
static void *expect_info;
|
||||
static char *ctx;
|
||||
static unsigned int notified1, notified2;
|
||||
static unsigned int notified1, notified2, notified_null;
|
||||
|
||||
/* Make sure we always move on resize. */
|
||||
static void *my_realloc(void *old, size_t size)
|
||||
|
@ -20,9 +20,9 @@ static void *my_realloc(void *old, size_t size)
|
|||
return new;
|
||||
}
|
||||
|
||||
static void notify1(char *p UNNEEDED, enum tal_notify_type notify, void *info)
|
||||
static void notify1(char *p, enum tal_notify_type notify, void *info)
|
||||
{
|
||||
ok1(ctx == ctx);
|
||||
ok1(p == ctx);
|
||||
ok1(notify == expect);
|
||||
if (expect_info == &expect_info)
|
||||
expect_info = info;
|
||||
|
@ -38,6 +38,17 @@ static void notify2(char *ctx UNNEEDED,
|
|||
notified2++;
|
||||
}
|
||||
|
||||
static void notify_null(void *p, enum tal_notify_type notify, void *info)
|
||||
{
|
||||
ok1(p == NULL);
|
||||
ok1(notify == expect);
|
||||
if (expect_info == &expect_info)
|
||||
expect_info = info;
|
||||
else
|
||||
ok1(info == expect_info);
|
||||
notified_null++;
|
||||
}
|
||||
|
||||
static bool seen_move, seen_resize;
|
||||
static void resize_notifier(char *p, enum tal_notify_type notify, void *info)
|
||||
{
|
||||
|
@ -62,7 +73,7 @@ int main(void)
|
|||
{
|
||||
char *child, *new_ctx;
|
||||
|
||||
plan_tests(56);
|
||||
plan_tests(65);
|
||||
|
||||
ctx = tal(NULL, char);
|
||||
ok1(tal_add_notifier(ctx, 511, notify1));
|
||||
|
@ -119,6 +130,20 @@ int main(void)
|
|||
ok1(notified1 == 7);
|
||||
ok1(notified2 == 1);
|
||||
|
||||
/* Notifiers on NULL work, too. */
|
||||
ok1(tal_add_notifier(NULL, TAL_NOTIFY_ADD_CHILD|TAL_NOTIFY_DEL_CHILD,
|
||||
notify_null));
|
||||
expect = TAL_NOTIFY_ADD_CHILD;
|
||||
expect_info = &expect_info;
|
||||
child = tal(NULL, char);
|
||||
ok1(notified_null == 1);
|
||||
|
||||
expect = TAL_NOTIFY_DEL_CHILD;
|
||||
expect_info = child;
|
||||
tal_free(child);
|
||||
ok1(notified_null == 2);
|
||||
ok1(tal_del_notifier(NULL, notify_null));
|
||||
|
||||
tal_set_backend(NULL, my_realloc, NULL, NULL);
|
||||
ctx = new_ctx = tal(NULL, char);
|
||||
ok1(tal_add_notifier(new_ctx, 511, resize_notifier));
|
||||
|
|
|
@ -42,7 +42,7 @@ struct timerel {
|
|||
};
|
||||
|
||||
/**
|
||||
* struct timeabs - an absolue time.
|
||||
* struct timeabs - an absolute time.
|
||||
* @ts: the actual timespec value.
|
||||
*
|
||||
* For example, Midnight UTC January 1st, 1970: ts.tv_sec = 0, ts.tv_nsec = 0
|
||||
|
|
Loading…
Add table
Reference in a new issue