From 5070a20cd1e65d52856bd74558f9a34f8dca114f Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 12 May 2010 12:45:33 -0700 Subject: 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. --- glcpp.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'glcpp.h') diff --git a/glcpp.h b/glcpp.h index 6fea9333e8..8472570ccb 100644 --- a/glcpp.h +++ b/glcpp.h @@ -55,7 +55,7 @@ glcpp_parser_destroy (glcpp_parser_t *parser); /* Generated by glcpp-lex.l to glcpp-lex.c */ int -yylex_init (yyscan_t *scanner); +yylex_init_extra (glcpp_parser_t *parser, yyscan_t* scanner); int yylex (yyscan_t scanner); @@ -68,4 +68,14 @@ yylex_destroy (yyscan_t scanner); int yyparse (glcpp_parser_t *parser); +/* xtalloc - wrappers around talloc to check for out-of-memory */ + +#define xtalloc(ctx, type) (type *)xtalloc_named_const(ctx, sizeof(type), #type) + +void * +xtalloc_named_const (const void *context, size_t size, const char *name); + +char * +xtalloc_strdup (const void *t, const char *p); + #endif -- cgit v1.2.3