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(op, clone(expr))
24 * free(expr) // just decrease ref
26 * FAIL: expr cannot be freed due to cyclic refs
27 * The references are like this:
32 * $user ~ ~ ~ > expr ---> seq ---> op
48 * $user ~ ~ ~ > expr ---------------> seq ---> op
51 * The node expr can be freed.
54 /* on error, child is *not* freed */
55 struct ec_node *ec_node_weakref(const char *id, struct ec_node *child);
57 /* on error, child is *not* freed */
58 int ec_node_weakref_set(struct ec_node *node, struct ec_node *child);