list children in a table, not in a list
[protos/libecoli.git] / lib / ecoli_node_weakref.c
index 3e202d3..f87866f 100644 (file)
@@ -43,6 +43,8 @@
 #include <ecoli_node_option.h>
 #include <ecoli_node_weakref.h>
 
+EC_LOG_TYPE_REGISTER(node_weakref);
+
 struct ec_node_weakref {
        struct ec_node gen;
        struct ec_node *child;
@@ -58,14 +60,14 @@ ec_node_weakref_parse(const struct ec_node *gen_node,
        return ec_node_parse_child(node->child, state, strvec);
 }
 
-static struct ec_completed *
+static int
 ec_node_weakref_complete(const struct ec_node *gen_node,
-                       struct ec_parsed *state,
+                       struct ec_completed *completed,
                        const struct ec_strvec *strvec)
 {
        struct ec_node_weakref *node = (struct ec_node_weakref *)gen_node;
 
-       return ec_node_complete_child(node->child, state, strvec);
+       return ec_node_complete_child(node->child, completed, strvec);
 }
 
 static struct ec_node_type ec_node_weakref_type = {
@@ -81,22 +83,23 @@ int ec_node_weakref_set(struct ec_node *gen_node, struct ec_node *child)
 {
        struct ec_node_weakref *node = (struct ec_node_weakref *)gen_node;
 
-       // XXX check node type
-
        assert(node != NULL);
 
-       if (child == NULL)
-               return -EINVAL;
+       if (child == NULL) {
+               errno = EINVAL;
+               goto fail;
+       }
 
-       gen_node->flags &= ~EC_NODE_F_BUILT;
+       if (ec_node_check_type(gen_node, &ec_node_weakref_type) < 0)
+               goto fail;
 
        node->child = child;
 
-       child->parent = gen_node;
-       // XXX else it breaks the dump()
-       //TAILQ_INSERT_TAIL(&gen_node->children, child, next); // XXX really needed?
-
        return 0;
+
+fail:
+       ec_node_free(child);
+       return -1;
 }
 
 struct ec_node *ec_node_weakref(const char *id, struct ec_node *child)