glcpp: Remove xtalloc wrappers in favor of plain talloc.
authorKenneth Graunke <kenneth@whitecape.org>
Wed, 4 Aug 2010 03:21:52 +0000 (20:21 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 4 Aug 2010 22:57:20 +0000 (15:57 -0700)
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.

src/glsl/Makefile
src/glsl/glcpp/Makefile.am
src/glsl/glcpp/glcpp-lex.l
src/glsl/glcpp/glcpp-parse.y
src/glsl/glcpp/glcpp.h
src/glsl/glcpp/xtalloc.c [deleted file]

index f98b772a2fbcd5edf28c32fca934ae3841527b7f..3102947494cc4379d55b69e050070f4a184e2a4b 100644 (file)
@@ -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) \
index 00c6c5610ebed3dcaaa7375dc5b6b78763b7c2c5..81147e6e12c4ea8d63d45d97da3275948950092e 100644 (file)
@@ -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)
index 17a097e633a523cf93c6a72419d0bb083d1df264..1a0052d689a30dac4587af9e593bb32ca3a18413 100644 (file)
@@ -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;
 }
 
index 855448ff20d91d446965b887f783b49e9a44779b..55a8d1761e6f863558af8678cf1756760262f72a 100644 (file)
@@ -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) {
index 0ccd957eda3c7207f79afcfbda14964c98d20d7f..0bebdb9ae8c00f918dcd00218cf1a911612e48f4 100644 (file)
@@ -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 (file)
index a20ea8b..0000000
+++ /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;
-}