Skip to content

Commit

Permalink
ccan: update so we can apply notifiers to toplevel "NULL".
Browse files Browse the repository at this point in the history
This will make leak detection more thorough.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Aug 24, 2018
1 parent 898655f commit c02ab12
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 44 deletions.
2 changes: 1 addition & 1 deletion ccan/README
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CCAN imported from http://ccodearchive.net.

CCAN version: init-2440-g55d81423
CCAN version: init-2442-ga8722345
6 changes: 3 additions & 3 deletions ccan/ccan/asort/test/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion ccan/ccan/autodata/autodata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 18 additions & 18 deletions ccan/ccan/bitops/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion ccan/ccan/crypto/sha256/benchmarks/double-sha-bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions ccan/ccan/intmap/intmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions ccan/ccan/list/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
*
Expand All @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion ccan/ccan/str/hex/_info
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion ccan/ccan/str/hex/hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions ccan/ccan/tal/tal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ");
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ccan/ccan/tal/tal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
33 changes: 29 additions & 4 deletions ccan/ccan/tal/test/run-notifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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)
{
Expand All @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion ccan/ccan/time/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c02ab12

Please sign in to comment.