diff options
author | Kenneth Graunke <[email protected]> | 2010-08-03 20:21:52 -0700 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2010-08-04 15:57:20 -0700 |
commit | 1ffc1cd86186ae5d03bb28a1e041c4a57761515e (patch) | |
tree | b8d694f7d27609ea6382415de379314b52814968 | |
parent | ad98aa9d93646600cc95b3e45a40eec26f18988a (diff) |
glcpp: Remove xtalloc wrappers in favor of plain talloc.
Calling exit() on a memory failure probably made sense for the
standalone preprocessor, but doesn't seem too appealing as part of
the GL library. Also, we don't use it in the main compiler.
-rw-r--r-- | src/glsl/Makefile | 3 | ||||
-rw-r--r-- | src/glsl/glcpp/Makefile.am | 3 | ||||
-rw-r--r-- | src/glsl/glcpp/glcpp-lex.l | 14 | ||||
-rw-r--r-- | src/glsl/glcpp/glcpp-parse.y | 38 | ||||
-rw-r--r-- | src/glsl/glcpp/glcpp.h | 24 | ||||
-rw-r--r-- | src/glsl/glcpp/xtalloc.c | 99 |
6 files changed, 28 insertions, 153 deletions
diff --git a/src/glsl/Makefile b/src/glsl/Makefile index f98b772a2fb..3102947494c 100644 --- a/src/glsl/Makefile +++ b/src/glsl/Makefile @@ -9,8 +9,7 @@ LIBNAME = glsl LIBGLCPP_SOURCES = \ glcpp/glcpp-lex.c \ glcpp/glcpp-parse.c \ - glcpp/pp.c \ - glcpp/xtalloc.c + glcpp/pp.c GLCPP_SOURCES = \ $(LIBGLCPP_SOURCES) \ diff --git a/src/glsl/glcpp/Makefile.am b/src/glsl/glcpp/Makefile.am index 00c6c5610eb..81147e6e12c 100644 --- a/src/glsl/glcpp/Makefile.am +++ b/src/glsl/glcpp/Makefile.am @@ -25,8 +25,7 @@ libglcpp_la_SOURCES = \ glcpp-lex.l \ glcpp-parse.y \ glcpp.h \ - pp.c \ - xtalloc.c + pp.c BUILT_SOURCES = glcpp-parse.h glcpp-parse.c glcpp-lex.c CLEANFILES = $(BUILT_SOURCES) diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l index 17a097e633a..1a0052d689a 100644 --- a/src/glsl/glcpp/glcpp-lex.l +++ b/src/glsl/glcpp/glcpp-lex.l @@ -88,7 +88,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? } {HASH}(version) { - yylval->str = xtalloc_strdup (yyextra, yytext); + yylval->str = talloc_strdup (yyextra, yytext); yylineno++; yycolumn = 0; yyextra->space_tokens = 0; @@ -98,7 +98,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? /* glcpp doesn't handle #extension, #version, or #pragma directives. * Simply pass them through to the main compiler's lexer/parser. */ {HASH}(extension|pragma)[^\n]+ { - yylval->str = xtalloc_strdup (yyextra, yytext); + yylval->str = talloc_strdup (yyextra, yytext); yylineno++; yycolumn = 0; return OTHER; @@ -186,17 +186,17 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? } {DECIMAL_INTEGER} { - yylval->str = xtalloc_strdup (yyextra, yytext); + yylval->str = talloc_strdup (yyextra, yytext); return INTEGER_STRING; } {OCTAL_INTEGER} { - yylval->str = xtalloc_strdup (yyextra, yytext); + yylval->str = talloc_strdup (yyextra, yytext); return INTEGER_STRING; } {HEXADECIMAL_INTEGER} { - yylval->str = xtalloc_strdup (yyextra, yytext); + yylval->str = talloc_strdup (yyextra, yytext); return INTEGER_STRING; } @@ -241,7 +241,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? } {IDENTIFIER} { - yylval->str = xtalloc_strdup (yyextra, yytext); + yylval->str = talloc_strdup (yyextra, yytext); return IDENTIFIER; } @@ -250,7 +250,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? } {OTHER}+ { - yylval->str = xtalloc_strdup (yyextra, yytext); + yylval->str = talloc_strdup (yyextra, yytext); return OTHER; } diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y index 855448ff20d..55a8d1761e6 100644 --- a/src/glsl/glcpp/glcpp-parse.y +++ b/src/glsl/glcpp/glcpp-parse.y @@ -503,7 +503,7 @@ _string_list_create (void *ctx) { string_list_t *list; - list = xtalloc (ctx, string_list_t); + list = talloc (ctx, string_list_t); list->head = NULL; list->tail = NULL; @@ -515,8 +515,8 @@ _string_list_append_item (string_list_t *list, const char *str) { string_node_t *node; - node = xtalloc (list, string_node_t); - node->str = xtalloc_strdup (node, str); + node = talloc (list, string_node_t); + node->str = talloc_strdup (node, str); node->next = NULL; @@ -569,7 +569,7 @@ _argument_list_create (void *ctx) { argument_list_t *list; - list = xtalloc (ctx, argument_list_t); + list = talloc (ctx, argument_list_t); list->head = NULL; list->tail = NULL; @@ -581,7 +581,7 @@ _argument_list_append (argument_list_t *list, token_list_t *argument) { argument_node_t *node; - node = xtalloc (list, argument_node_t); + node = talloc (list, argument_node_t); node->argument = argument; node->next = NULL; @@ -638,7 +638,7 @@ _token_create_str (void *ctx, int type, char *str) { token_t *token; - token = xtalloc (ctx, token_t); + token = talloc (ctx, token_t); token->type = type; token->value.str = talloc_steal (token, str); @@ -650,7 +650,7 @@ _token_create_ival (void *ctx, int type, int ival) { token_t *token; - token = xtalloc (ctx, token_t); + token = talloc (ctx, token_t); token->type = type; token->value.ival = ival; @@ -662,7 +662,7 @@ _token_list_create (void *ctx) { token_list_t *list; - list = xtalloc (ctx, token_list_t); + list = talloc (ctx, token_list_t); list->head = NULL; list->tail = NULL; list->non_space_tail = NULL; @@ -675,8 +675,8 @@ _token_list_append (token_list_t *list, token_t *token) { token_node_t *node; - node = xtalloc (list, token_node_t); - node->token = xtalloc_reference (list, token); + node = talloc (list, token_node_t); + node->token = talloc_reference (list, token); node->next = NULL; @@ -871,8 +871,8 @@ _token_paste (glcpp_parser_t *parser, token_t *token, token_t *other) { char *str; - str = xtalloc_asprintf (token, "%s%s", - token->value.str, other->value.str); + str = talloc_asprintf (token, "%s%s", token->value.str, + other->value.str); combined = _token_create_str (token, token->type, str); combined->location = token->location; return combined; @@ -927,7 +927,7 @@ glcpp_parser_create (const struct gl_extensions *extensions) glcpp_parser_t *parser; int language_version; - parser = xtalloc (NULL, glcpp_parser_t); + parser = talloc (NULL, glcpp_parser_t); glcpp_lex_init_extra (parser, &parser->scanner); parser->defines = hash_table_ctor (32, hash_table_string_hash, @@ -1294,7 +1294,7 @@ _glcpp_parser_expand_node (glcpp_parser_t *parser, token_list_t *expansion; token_t *final; - str = xtalloc_strdup (parser, token->value.str); + str = talloc_strdup (parser, token->value.str); final = _token_create_str (parser, OTHER, str); expansion = _token_list_create (parser); _token_list_append (expansion, final); @@ -1330,8 +1330,8 @@ _active_list_push (active_list_t *list, { active_list_t *node; - node = xtalloc (list, active_list_t); - node->identifier = xtalloc_strdup (node, identifier); + node = talloc (list, active_list_t); + node->identifier = talloc_strdup (node, identifier); node->marker = marker; node->next = list; @@ -1481,7 +1481,7 @@ _define_object_macro (glcpp_parser_t *parser, if (loc != NULL) _check_for_reserved_macro_name(parser, loc, identifier); - macro = xtalloc (parser, macro_t); + macro = talloc (parser, macro_t); macro->is_function = 0; macro->parameters = NULL; @@ -1502,7 +1502,7 @@ _define_function_macro (glcpp_parser_t *parser, _check_for_reserved_macro_name(parser, loc, identifier); - macro = xtalloc (parser, macro_t); + macro = talloc (parser, macro_t); macro->is_function = 1; macro->parameters = talloc_steal (macro, parameters); @@ -1628,7 +1628,7 @@ _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc, if (parser->skip_stack) current = parser->skip_stack->type; - node = xtalloc (parser, skip_node_t); + node = talloc (parser, skip_node_t); node->loc = *loc; if (current == SKIP_NO_SKIP) { diff --git a/src/glsl/glcpp/glcpp.h b/src/glsl/glcpp/glcpp.h index 0ccd957eda3..0bebdb9ae8c 100644 --- a/src/glsl/glcpp/glcpp.h +++ b/src/glsl/glcpp/glcpp.h @@ -219,28 +219,4 @@ glcpp_lex_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) - -#define xtalloc_size(ctx, size) xtalloc_named_const(ctx, size, __location__) - -void * -xtalloc_named_const (const void *context, size_t size, const char *name); - -char * -xtalloc_strdup (const void *t, const char *p); - -char * -xtalloc_strndup (const void *t, const char *p, size_t n); - -char * -xtalloc_asprintf (const void *t, const char *fmt, ...); - -void * -_xtalloc_reference_loc (const void *context, - const void *ptr, const char *location); - -#define xtalloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_xtalloc_reference_loc((ctx),(ptr), __location__) - #endif diff --git a/src/glsl/glcpp/xtalloc.c b/src/glsl/glcpp/xtalloc.c deleted file mode 100644 index a20ea8b93fa..00000000000 --- a/src/glsl/glcpp/xtalloc.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright © 2010 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#include "glcpp.h" - -void * -xtalloc_named_const (const void *context, size_t size, const char *name) -{ - void *ret; - - ret = talloc_named_const (context, size, name); - if (ret == NULL) { - fprintf (stderr, "Out of memory.\n"); - exit (1); - } - - return ret; -} - -char * -xtalloc_strdup (const void *t, const char *p) -{ - char *ret; - - ret = talloc_strdup (t, p); - if (ret == NULL) { - fprintf (stderr, "Out of memory.\n"); - exit (1); - } - - return ret; -} - -char * -xtalloc_strndup (const void *t, const char *p, size_t n) -{ - char *ret; - - ret = talloc_strndup (t, p, n); - if (ret == NULL) { - fprintf (stderr, "Out of memory.\n"); - exit (1); - } - - return ret; -} - -char * -xtalloc_asprintf (const void *t, const char *fmt, ...) -{ - va_list ap; - char *ret; - - va_start(ap, fmt); - - ret = talloc_vasprintf(t, fmt, ap); - if (ret == NULL) { - fprintf (stderr, "Out of memory.\n"); - exit (1); - } - - va_end(ap); - return ret; -} - -void * -_xtalloc_reference_loc (const void *context, - const void *ptr, const char *location) -{ - void *ret; - - ret = _talloc_reference_loc (context, ptr, location); - if (ret == NULL) { - fprintf (stderr, "Out of memory.\n"); - exit (1); - } - - return ret; -} |