Mesa (thalloc): glcpp: Remove use of talloc reference counting

Jakob Bornecrantz wallbraker at kemper.freedesktop.org
Wed Jan 19 01:30:39 UTC 2011


Module: Mesa
Branch: thalloc
Commit: 0540d8d4df1c681dc03a3fd77ef10cd5c2ca8859
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0540d8d4df1c681dc03a3fd77ef10cd5c2ca8859

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Jan 19 02:28:49 2011 +0100

glcpp: Remove use of talloc reference counting

We almost always want to simply steal; we only need to copy when copying
a token list (in which case we're already cloning stuff anyway).

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Signed-off-by: Jakob Bornecrantz <jakob at vmware.com>

---

 src/glsl/glcpp/glcpp-parse.y |   20 +++++++-------------
 1 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 558ad0a..efd890f 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -89,10 +89,7 @@ _token_create_ival (void *ctx, int type, int ival);
 static token_list_t *
 _token_list_create (void *ctx);
 
-/* Note: This function adds a talloc_reference() to token.
- *
- * You may want to talloc_unlink any current reference if you no
- * longer need it. */
+/* Note: This function calls talloc_steal on token. */
 static void
 _token_list_append (token_list_t *list, token_t *token);
 
@@ -474,12 +471,10 @@ conditional_tokens:
 	conditional_token {
 		$$ = _token_list_create (parser);
 		_token_list_append ($$, $1);
-		talloc_unlink (parser, $1);
 	}
 |	conditional_tokens conditional_token {
 		$$ = $1;
 		_token_list_append ($$, $2);
-		talloc_unlink (parser, $2);
 	}
 ;
 
@@ -488,12 +483,10 @@ pp_tokens:
 		parser->space_tokens = 1;
 		$$ = _token_list_create (parser);
 		_token_list_append ($$, $1);
-		talloc_unlink (parser, $1);
 	}
 |	pp_tokens preprocessing_token {
 		$$ = $1;
 		_token_list_append ($$, $2);
-		talloc_unlink (parser, $2);
 	}
 ;
 
@@ -759,7 +752,7 @@ _token_list_append (token_list_t *list, token_t *token)
 	token_node_t *node;
 
 	node = talloc (list, token_node_t);
-	node->token = talloc_reference (list, token);
+	node->token = talloc_steal (list, token);
 
 	node->next = NULL;
 
@@ -800,8 +793,11 @@ _token_list_copy (void *ctx, token_list_t *other)
 		return NULL;
 
 	copy = _token_list_create (ctx);
-	for (node = other->head; node; node = node->next)
-		_token_list_append (copy, node->token);
+	for (node = other->head; node; node = node->next) {
+		token_t *new_token = talloc (copy, token_t);
+		*new_token = *node->token;
+		_token_list_append (copy, new_token);
+	}
 
 	return copy;
 }
@@ -1055,8 +1051,6 @@ static void add_builtin_define(glcpp_parser_t *parser,
    list = _token_list_create(parser);
    _token_list_append(list, tok);
    _define_object_macro(parser, NULL, name, list);
-
-   talloc_unlink(parser, tok);
 }
 
 glcpp_parser_t *




More information about the mesa-commit mailing list