X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftal%2Ftal.c;h=194e74c68afc8d9662b00a2924a2b2cb1da28fb6;hp=350b34be9d902ee2ae531cdf04bbe531cc2c7943;hb=ca6991d861a02d1da8d51f71607a4d9d8e145850;hpb=0f6d854ab9d85ac7e4487ff3eee464be6bb528aa diff --git a/ccan/tal/tal.c b/ccan/tal/tal.c index 350b34be..194e74c6 100644 --- a/ccan/tal/tal.c +++ b/ccan/tal/tal.c @@ -154,11 +154,11 @@ static struct tal_hdr *to_tal_hdr(const void *ctx) t = (struct tal_hdr *)((char *)ctx - sizeof(struct tal_hdr)); check_bounds(t); - if (t->prop && !is_literal(t->prop)) - check_bounds(t->prop); check_bounds(ignore_destroying_bit(t->parent_child)); check_bounds(t->list.next); check_bounds(t->list.prev); + if (t->prop && !is_literal(t->prop)) + check_bounds(t->prop); return t; } @@ -258,6 +258,28 @@ static struct destructor *add_destructor_property(struct tal_hdr *t, return prop; } +static bool del_destructor_property(struct tal_hdr *t, + void (*destroy)(void *)) +{ + struct prop_hdr **p; + + for (p = (struct prop_hdr **)&t->prop; *p; p = &(*p)->next) { + struct destructor *d; + + if (is_literal(*p)) + break; + if ((*p)->type != DESTRUCTOR) + continue; + d = (struct destructor *)*p; + if (d->destroy == destroy) { + *p = (*p)->next; + freefn(d); + return true; + } + } + return false; +} + static struct name *add_name_property(struct tal_hdr *t, const char *name) { struct name *prop; @@ -399,6 +421,11 @@ bool tal_add_destructor_(tal_t *ctx, void (*destroy)(void *me)) return add_destructor_property(debug_tal(to_tal_hdr(ctx)), destroy); } +bool tal_del_destructor_(tal_t *ctx, void (*destroy)(void *me)) +{ + return del_destructor_property(debug_tal(to_tal_hdr(ctx)), destroy); +} + bool tal_set_name_(tal_t *ctx, const char *name, bool literal) { struct tal_hdr *t = debug_tal(to_tal_hdr(ctx));