1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
5 #ifndef ECOLI_NODE_WEAKREF_
6 #define ECOLI_NODE_WEAKREF_
8 #include <ecoli_node.h>
10 /* A node that just behaves like its child and that does not free
11 * its child when freed. **The child has to be freed manually**.
13 * useful to create cyclic graphs of nodes:
14 * creating a loop (with clones) result in something that is not
15 * freeable, due to reference counters
21 * seq = seq(clone(op), clone(expr))
22 * expr.add(clone(seq))
23 * expr.add(clone(val))
28 * FAIL: expr cannot be freed due to cyclic refs
29 * The references are like this:
34 * $user ---> expr ---> seq ---> op
42 * seq = seq(clone(op), clone(weak))
43 * expr.add(clone(seq))
44 * expr.add(clone(val))
54 * $user ---> expr ---------------> seq ---> op
57 * The node expr can be freed.
60 /* on error, child is *not* freed */
61 struct ec_node *ec_node_weakref(const char *id, struct ec_node *child);
63 /* on error, child is *not* freed */
64 int ec_node_weakref_set(struct ec_node *node, struct ec_node *child);