Use objstack to store nodes
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 19 Apr 2013 09:01:10 +0000 (05:01 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 19 Apr 2013 09:01:10 +0000 (05:01 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/metadata/ctf-ast.h
formats/ctf/metadata/ctf-parser.y
formats/ctf/metadata/objstack.h

index 4f4b8aba8938d5f103fb3be50dc24a53952e0355..e4cf68a42b6c9051e3153078aa838dfbf89ad733 100644 (file)
@@ -294,7 +294,6 @@ struct ctf_node {
 
 struct ctf_ast {
        struct ctf_node root;
-       struct bt_list_head allocated_nodes;
 };
 
 const char *node_type(struct ctf_node *node);
index 84d4702ebb30afa0cb78b8e9008c3475487a1a23..1a57922b65b289c4ab24138a65857ca4aeef9212 100644 (file)
@@ -362,19 +362,16 @@ static void add_type(struct ctf_scanner *scanner, char *id)
 static struct ctf_node *make_node(struct ctf_scanner *scanner,
                                  enum node_type type)
 {
-       struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
        struct ctf_node *node;
 
-       node = malloc(sizeof(*node));
+       node = objstack_alloc(scanner->objstack, sizeof(*node));
        if (!node) {
                printfl_fatal(yyget_lineno(scanner->scanner), "out of memory");
                return &error_node;
        }
-       memset(node, 0, sizeof(*node));
        node->type = type;
        node->lineno = yyget_lineno(scanner->scanner);
        BT_INIT_LIST_HEAD(&node->tmp_head);
-       bt_list_add(&node->gc, &ast->allocated_nodes);
        bt_list_add(&node->siblings, &node->tmp_head);
 
        switch (type) {
@@ -964,7 +961,6 @@ static struct ctf_ast *ctf_ast_alloc(void)
        if (!ast)
                return NULL;
        memset(ast, 0, sizeof(*ast));
-       BT_INIT_LIST_HEAD(&ast->allocated_nodes);
        ast->root.type = NODE_ROOT;
        BT_INIT_LIST_HEAD(&ast->root.tmp_head);
        BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
@@ -979,10 +975,6 @@ static struct ctf_ast *ctf_ast_alloc(void)
 
 static void ctf_ast_free(struct ctf_ast *ast)
 {
-       struct ctf_node *node, *tmp;
-
-       bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
-               free(node);
        free(ast);
 }
 
index 8f83f9022dbc0d2813c9ed2bbccee1edee227993..c026eb54664d4b50f1da74d4ffbb8695070a6f5c 100644 (file)
@@ -33,6 +33,11 @@ BT_HIDDEN
 struct objstack *objstack_create(void);
 BT_HIDDEN
 void objstack_destroy(struct objstack *objstack);
+
+/*
+ * Allocate len bytes of zeroed memory.
+ * Return NULL on error.
+ */
 BT_HIDDEN
 void *objstack_alloc(struct objstack *objstack, size_t len);
 
This page took 0.026423 seconds and 4 git commands to generate.