summaryrefslogtreecommitdiff
path: root/glcpp-parse.y
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2010-05-12 12:45:33 -0700
committerCarl Worth <cworth@cworth.org>2010-05-12 12:47:29 -0700
commit5070a20cd1e65d52856bd74558f9a34f8dca114f (patch)
treea8cd5b178480c7b670b0a8e63ccd15dff190c7b3 /glcpp-parse.y
parent33cc400714f379ef13e876b4aedd0de8cb5d033d (diff)
Convert lexer to talloc and add xtalloc wrappers.
The lexer was previously using strdup (expecting the parser to free), but is now more consistent, easier to use, and slightly more efficent by using talloc along with the parser. Also, we add xtalloc and xtalloc_strdup wrappers around talloc and talloc_strdup to put all of the out-of-memory-checking code in one place.
Diffstat (limited to 'glcpp-parse.y')
-rw-r--r--glcpp-parse.y39
1 files changed, 10 insertions, 29 deletions
diff --git a/glcpp-parse.y b/glcpp-parse.y
index eae96efb30..1a7ec4970d 100644
--- a/glcpp-parse.y
+++ b/glcpp-parse.y
@@ -71,21 +71,20 @@ input:
content:
token {
_print_resolved_token (parser, $1);
- free ($1);
+ talloc_free ($1);
}
| directive
| content token {
_print_resolved_token (parser, $2);
- free ($2);
+ talloc_free ($2);
}
| content directive
;
directive:
DEFINE IDENTIFIER replacement_list NEWLINE {
- char *key = talloc_strdup ($3, $2);
- free ($2);
- hash_table_insert (parser->defines, $3, key);
+ talloc_steal ($3, $2);
+ hash_table_insert (parser->defines, $3, $2);
printf ("\n");
}
;
@@ -97,7 +96,7 @@ replacement_list:
| replacement_list token {
_list_append ($1, $2);
- free ($2);
+ talloc_free ($2);
$$ = $1;
}
;
@@ -114,12 +113,7 @@ _list_create (void *ctx)
{
list_t *list;
- list = talloc (ctx, list_t);
- if (list == NULL) {
- fprintf (stderr, "Out of memory.\n");
- exit (1);
- }
-
+ list = xtalloc (ctx, list_t);
list->head = NULL;
list->tail = NULL;
@@ -131,17 +125,8 @@ _list_append (list_t *list, const char *str)
{
node_t *node;
- node = talloc (list, node_t);
- if (node == NULL) {
- fprintf (stderr, "Out of memory.\n");
- exit (1);
- }
-
- node->str = talloc_strdup (node, str);
- if (node->str == NULL) {
- fprintf (stderr, "Out of memory.\n");
- exit (1);
- }
+ node = xtalloc (list, node_t);
+ node->str = xtalloc_strdup (node, str);
node->next = NULL;
@@ -165,13 +150,9 @@ glcpp_parser_create (void)
{
glcpp_parser_t *parser;
- parser = talloc (NULL, glcpp_parser_t);
- if (parser == NULL) {
- fprintf (stderr, "Out of memory.\n");
- exit (1);
- }
+ parser = xtalloc (NULL, glcpp_parser_t);
- yylex_init (&parser->scanner);
+ yylex_init_extra (parser, &parser->scanner);
parser->defines = hash_table_ctor (32, hash_table_string_hash,
hash_table_string_compare);