From 2caa2f1450d12a69789638fa7e19f536f90ead39 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 19 Apr 2013 05:01:10 -0400 Subject: [PATCH] Use objstack to store nodes Signed-off-by: Mathieu Desnoyers --- formats/ctf/metadata/ctf-ast.h | 1 - formats/ctf/metadata/ctf-parser.y | 10 +--------- formats/ctf/metadata/objstack.h | 5 +++++ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/formats/ctf/metadata/ctf-ast.h b/formats/ctf/metadata/ctf-ast.h index 4f4b8aba..e4cf68a4 100644 --- a/formats/ctf/metadata/ctf-ast.h +++ b/formats/ctf/metadata/ctf-ast.h @@ -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); diff --git a/formats/ctf/metadata/ctf-parser.y b/formats/ctf/metadata/ctf-parser.y index 84d4702e..1a57922b 100644 --- a/formats/ctf/metadata/ctf-parser.y +++ b/formats/ctf/metadata/ctf-parser.y @@ -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); } diff --git a/formats/ctf/metadata/objstack.h b/formats/ctf/metadata/objstack.h index 8f83f902..c026eb54 100644 --- a/formats/ctf/metadata/objstack.h +++ b/formats/ctf/metadata/objstack.h @@ -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); -- 2.34.1