Browse Source

ccan: update to get tal_free fix.

This allows us to make heirarchy loops, such as reference counting to
free our own parent.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
629c3db421
  1. 2
      ccan/README
  2. 18
      ccan/ccan/intmap/intmap.c
  3. 36
      ccan/ccan/intmap/intmap.h
  4. 12
      ccan/ccan/intmap/test/run-order-smallsize.c
  5. 12
      ccan/ccan/intmap/test/run-order.c
  6. 5
      ccan/ccan/intmap/test/run-signed-int.c
  7. 15
      ccan/ccan/intmap/test/run.c
  8. 2
      ccan/ccan/tal/tal.c

2
ccan/README

@ -1,3 +1,3 @@
CCAN imported from http://ccodearchive.net. CCAN imported from http://ccodearchive.net.
CCAN version: init-2403-g8502a66a CCAN version: init-2405-g41a0af50

18
ccan/ccan/intmap/intmap.c

@ -197,6 +197,24 @@ void *intmap_after_(const struct intmap *map, intmap_index_t *indexp)
return intmap_first_(&prev->u.n->child[1], indexp); return intmap_first_(&prev->u.n->child[1], indexp);
} }
void *intmap_last_(const struct intmap *map, intmap_index_t *indexp)
{
const struct intmap *n;
if (intmap_empty_(map)) {
errno = ENOENT;
return NULL;
}
n = map;
/* Anything with NULL value is a node. */
while (!n->v)
n = &n->u.n->child[1];
errno = 0;
*indexp = n->u.i;
return n->v;
}
static void clear(struct intmap n) static void clear(struct intmap n)
{ {
if (!n.v) { if (!n.v) {

36
ccan/ccan/intmap/intmap.h

@ -309,6 +309,32 @@ void *intmap_after_(const struct intmap *map, intmap_index_t *indexp);
tcon_cast((smap), sintmap_canary, \ tcon_cast((smap), sintmap_canary, \
sintmap_after_(sintmap_unwrap_(smap), (indexp))) sintmap_after_(sintmap_unwrap_(smap), (indexp)))
/**
* uintmap_last - get last value in an unsigned intmap
* @umap: the typed intmap to iterate through.
* @indexp: a pointer to store the index.
*
* Returns NULL if the map is empty, otherwise populates *@indexp and
* returns the highest entry.
*/
#define uintmap_last(umap, indexp) \
tcon_cast((umap), uintmap_canary, \
intmap_last_(uintmap_unwrap_(umap), (indexp)))
void *intmap_last_(const struct intmap *map, intmap_index_t *indexp);
/**
* sintmap_last - get last value in a signed intmap
* @smap: the typed intmap to iterate through.
* @indexp: a pointer to store the index.
*
* Returns NULL if the map is empty, otherwise populates *@indexp and
* returns the highest entry.
*/
#define sintmap_last(smap, indexp) \
tcon_cast((smap), sintmap_canary, \
sintmap_last_(sintmap_unwrap_(smap), (indexp)))
/* TODO: We could implement intmap_prefix. */ /* TODO: We could implement intmap_prefix. */
/* These make sure it really is a uintmap/sintmap */ /* These make sure it really is a uintmap/sintmap */
@ -339,4 +365,14 @@ static inline void *sintmap_after_(const struct intmap *map,
*indexp = SINTMAP_UNOFF(i); *indexp = SINTMAP_UNOFF(i);
return ret; return ret;
} }
static inline void *sintmap_last_(const struct intmap *map,
sintmap_index_t *indexp)
{
intmap_index_t i;
void *ret = intmap_last_(map, &i);
*indexp = SINTMAP_UNOFF(i);
return ret;
}
#endif /* CCAN_INTMAP_H */ #endif /* CCAN_INTMAP_H */

12
ccan/ccan/intmap/test/run-order-smallsize.c

@ -14,8 +14,9 @@ static bool check_umap(const umap *map)
{ {
/* This is a larger type than unsigned, and allows negative */ /* This is a larger type than unsigned, and allows negative */
int64_t prev; int64_t prev;
intmap_index_t i; intmap_index_t i, last_idx;
uint8_t *v; uint8_t *v;
bool last = true;
/* Must be in order, must contain value. */ /* Must be in order, must contain value. */
prev = -1; prev = -1;
@ -25,16 +26,18 @@ static bool check_umap(const umap *map)
if (*v != i) if (*v != i)
return false; return false;
prev = i; prev = i;
last = (uintmap_last(map, &last_idx) == v);
} }
return true; return last;
} }
static bool check_smap(const smap *map) static bool check_smap(const smap *map)
{ {
/* This is a larger type than int, and allows negative */ /* This is a larger type than int, and allows negative */
int64_t prev; int64_t prev;
sintmap_index_t i; sintmap_index_t i, last_idx;
int8_t *v; int8_t *v;
bool last = true;
/* Must be in order, must contain value. */ /* Must be in order, must contain value. */
prev = -0x80000001ULL; prev = -0x80000001ULL;
@ -44,8 +47,9 @@ static bool check_smap(const smap *map)
if (*v != i) if (*v != i)
return false; return false;
prev = i; prev = i;
last = (sintmap_last(map, &last_idx) == v);
} }
return true; return last;
} }
int main(void) int main(void)

12
ccan/ccan/intmap/test/run-order.c

@ -11,8 +11,9 @@ static bool check_umap(const umap *map)
{ {
/* This is a larger type than unsigned, and allows negative */ /* This is a larger type than unsigned, and allows negative */
int64_t prev; int64_t prev;
uint64_t i; uint64_t i, last_idx;
unsigned int *v; unsigned int *v;
bool last = true;
/* Must be in order, must contain value. */ /* Must be in order, must contain value. */
prev = -1; prev = -1;
@ -22,15 +23,17 @@ static bool check_umap(const umap *map)
if (*v != i) if (*v != i)
return false; return false;
prev = i; prev = i;
last = (uintmap_last(map, &last_idx) == v);
} }
return true; return last;
} }
static bool check_smap(const smap *map) static bool check_smap(const smap *map)
{ {
/* This is a larger type than int, and allows negative */ /* This is a larger type than int, and allows negative */
int64_t prev, i; int64_t prev, i, last_idx;
int *v; int *v;
bool last = true;
/* Must be in order, must contain value. */ /* Must be in order, must contain value. */
prev = -0x80000001ULL; prev = -0x80000001ULL;
@ -39,9 +42,10 @@ static bool check_smap(const smap *map)
return false; return false;
if (*v != i) if (*v != i)
return false; return false;
last = (sintmap_last(map, &last_idx) == v);
prev = i; prev = i;
} }
return true; return last;
} }
int main(void) int main(void)

5
ccan/ccan/intmap/test/run-signed-int.c

@ -9,13 +9,14 @@ int main(void)
int64_t s; int64_t s;
/* This is how many tests you plan to run */ /* This is how many tests you plan to run */
plan_tests(35); plan_tests(38);
sintmap_init(&map); sintmap_init(&map);
/* Test boundaries. */ /* Test boundaries. */
ok1(!sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL)); ok1(!sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL));
ok1(!sintmap_get(&map, -0x8000000000000000LL)); ok1(!sintmap_get(&map, -0x8000000000000000LL));
ok1(sintmap_first(&map, &s) == NULL); ok1(sintmap_first(&map, &s) == NULL);
ok1(sintmap_last(&map, &s) == NULL);
ok1(errno == ENOENT); ok1(errno == ENOENT);
s = 0x7FFFFFFFFFFFFFFFLL; s = 0x7FFFFFFFFFFFFFFFLL;
ok1(sintmap_after(&map, &s) == NULL); ok1(sintmap_after(&map, &s) == NULL);
@ -29,12 +30,14 @@ int main(void)
ok1(sintmap_add(&map, 0x7FFFFFFFFFFFFFFFLL, first)); ok1(sintmap_add(&map, 0x7FFFFFFFFFFFFFFFLL, first));
ok1(sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL) == first); ok1(sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
ok1(sintmap_first(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL); ok1(sintmap_first(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
ok1(sintmap_last(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
ok1(errno == 0); ok1(errno == 0);
ok1(sintmap_add(&map, -0x8000000000000000LL, second)); ok1(sintmap_add(&map, -0x8000000000000000LL, second));
ok1(sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL) == first); ok1(sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
ok1(sintmap_get(&map, -0x8000000000000000LL) == second); ok1(sintmap_get(&map, -0x8000000000000000LL) == second);
ok1(sintmap_first(&map, &s) == second && s == -0x8000000000000000LL); ok1(sintmap_first(&map, &s) == second && s == -0x8000000000000000LL);
ok1(sintmap_after(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL); ok1(sintmap_after(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
ok1(sintmap_last(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
ok1(errno == 0); ok1(errno == 0);
s = 0x7FFFFFFFFFFFFFFELL; s = 0x7FFFFFFFFFFFFFFELL;
ok1(sintmap_after(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL); ok1(sintmap_after(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);

15
ccan/ccan/intmap/test/run.c

@ -7,9 +7,10 @@ int main(void)
UINTMAP(char *) map; UINTMAP(char *) map;
const char val[] = "there"; const char val[] = "there";
const char none[] = ""; const char none[] = "";
uint64_t idx;
/* This is how many tests you plan to run */ /* This is how many tests you plan to run */
plan_tests(28); plan_tests(40);
uintmap_init(&map); uintmap_init(&map);
@ -21,11 +22,19 @@ int main(void)
ok1(errno == ENOENT); ok1(errno == ENOENT);
ok1(!uintmap_del(&map, 0)); ok1(!uintmap_del(&map, 0));
ok1(errno == ENOENT); ok1(errno == ENOENT);
ok1(!uintmap_first(&map, &idx));
ok1(errno == ENOENT);
ok1(!uintmap_last(&map, &idx));
ok1(errno == ENOENT);
ok1(uintmap_add(&map, 1, val)); ok1(uintmap_add(&map, 1, val));
ok1(uintmap_get(&map, 1) == val); ok1(uintmap_get(&map, 1) == val);
ok1(!uintmap_get(&map, 0)); ok1(!uintmap_get(&map, 0));
ok1(errno == ENOENT); ok1(errno == ENOENT);
ok1(uintmap_first(&map, &idx) == val);
ok1(idx == 1);
ok1(uintmap_last(&map, &idx) == val);
ok1(idx == 1);
/* Add a duplicate should fail. */ /* Add a duplicate should fail. */
ok1(!uintmap_add(&map, 1, val)); ok1(!uintmap_add(&map, 1, val));
@ -43,6 +52,10 @@ int main(void)
ok1(uintmap_add(&map, 1, val)); ok1(uintmap_add(&map, 1, val));
ok1(uintmap_get(&map, 1) == val); ok1(uintmap_get(&map, 1) == val);
ok1(uintmap_get(&map, 0) == none); ok1(uintmap_get(&map, 0) == none);
ok1(uintmap_first(&map, &idx) == none);
ok1(idx == 0);
ok1(uintmap_last(&map, &idx) == val);
ok1(idx == 1);
ok1(!uintmap_del(&map, 2)); ok1(!uintmap_del(&map, 2));
ok1(uintmap_del(&map, 0) == none); ok1(uintmap_del(&map, 0) == none);
ok1(uintmap_get(&map, 1) == val); ok1(uintmap_get(&map, 1) == val);

2
ccan/ccan/tal/tal.c

@ -502,6 +502,8 @@ void *tal_free(const tal_t *ctx)
struct tal_hdr *t; struct tal_hdr *t;
int saved_errno = errno; int saved_errno = errno;
t = debug_tal(to_tal_hdr(ctx)); t = debug_tal(to_tal_hdr(ctx));
if (unlikely(get_destroying_bit(t->parent_child)))
return NULL;
if (notifiers) if (notifiers)
notify(ignore_destroying_bit(t->parent_child)->parent, notify(ignore_destroying_bit(t->parent_child)->parent,
TAL_NOTIFY_DEL_CHILD, ctx, saved_errno); TAL_NOTIFY_DEL_CHILD, ctx, saved_errno);

Loading…
Cancel
Save