tal: add del_destructor().
[ccan] / ccan / tal / tal.c
index 8245aba95028d90a007eb0c4b6edf83284d9b984..194e74c68afc8d9662b00a2924a2b2cb1da28fb6 100644 (file)
@@ -258,6 +258,28 @@ static struct destructor *add_destructor_property(struct tal_hdr *t,
        return prop;
 }
 
        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;
 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);
 }
 
         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));
 bool tal_set_name_(tal_t *ctx, const char *name, bool literal)
 {
         struct tal_hdr *t = debug_tal(to_tal_hdr(ctx));