diff mbox

Make copy_name return std::string

Message ID 20190407231556.8240-1-tom@tromey.com
State New
Headers show

Commit Message

Tom Tromey April 7, 2019, 11:15 p.m. UTC
This changes copy_name to return a std::string, updating all the
callers.  In some cases, an extra copy was removed.  This also
required a little bit of constification.

Tested by the buildbot.

gdb/ChangeLog
2019-04-07  Tom Tromey  <tom@tromey.com>

	* type-stack.h (struct type_stack) <insert>: Constify string.
	* type-stack.c (type_stack::insert): Constify string.
	* gdbtypes.h (lookup_template_type): Update.
	(address_space_name_to_int): Update.
	* gdbtypes.c (address_space_name_to_int): Make space_identifier
	const.
	(lookup_template_type): Make name const.
	* c-exp.y: Update rules.
	(lex_one_token, classify_name, classify_inner_name)
	(c_print_token): Update.
	* p-exp.y: Update rules.
	(yylex): Update.
	* f-exp.y: Update rules.
	(yylex): Update.
	* d-exp.y: Update rules.
	(lex_one_token, classify_name, classify_inner_name): Update.
	* parse.c (write_dollar_variable, copy_name): Return std::string.
	* parser-defs.h (copy_name): Change return type.
	* m2-exp.y: Update rules.
	(yylex): Update.
	* go-exp.y (lex_one_token): Update.
	Update rules.
	(classify_unsafe_function, classify_packaged_name)
	(classify_name, yylex): Update.
---
 gdb/ChangeLog     |  27 ++++++++++++
 gdb/c-exp.y       | 104 +++++++++++++++++++++++++---------------------
 gdb/d-exp.y       |  31 +++++++-------
 gdb/f-exp.y       |  12 +++---
 gdb/gdbtypes.c    |   5 ++-
 gdb/gdbtypes.h    |   4 +-
 gdb/go-exp.y      |  45 +++++++++-----------
 gdb/m2-exp.y      |  31 +++++++-------
 gdb/p-exp.y       |  69 +++++++++++++++++-------------
 gdb/parse.c       |  37 ++++-------------
 gdb/parser-defs.h |   2 +-
 gdb/type-stack.c  |   2 +-
 gdb/type-stack.h  |   2 +-
 13 files changed, 195 insertions(+), 176 deletions(-)

Comments

Tom Tromey April 19, 2019, 8:11 p.m. UTC | #1
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> This changes copy_name to return a std::string, updating all the
Tom> callers.  In some cases, an extra copy was removed.  This also
Tom> required a little bit of constification.

Tom> Tested by the buildbot.

I'm going to check this in now.

Tom
diff mbox

Patch

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index e1a17b5628a..47e82b698b4 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -474,14 +474,15 @@  exp	: 	OBJC_LBRAC TYPENAME
 			{
 			  CORE_ADDR theclass;
 
+			  std::string copy = copy_name ($2.stoken);
 			  theclass = lookup_objc_class (pstate->gdbarch (),
-						     copy_name ($2.stoken));
+							copy.c_str ());
 			  if (theclass == 0)
 			    error (_("%s is not an ObjC Class"),
-				   copy_name ($2.stoken));
+				   copy.c_str ());
 			  write_exp_elt_opcode (pstate, OP_LONG);
 			  write_exp_elt_type (pstate,
-					    parse_type (pstate)->builtin_int);
+					      parse_type (pstate)->builtin_int);
 			  write_exp_elt_longcst (pstate, (LONGEST) theclass);
 			  write_exp_elt_opcode (pstate, OP_LONG);
 			  start_msglist();
@@ -959,7 +960,7 @@  block	:	BLOCKNAME
 			    $$ = SYMBOL_BLOCK_VALUE ($1.sym.symbol);
 			  else
 			    error (_("No file or function \"%s\"."),
-				   copy_name ($1.stoken));
+				   copy_name ($1.stoken).c_str ());
 			}
 	|	FILENAME
 			{
@@ -968,13 +969,15 @@  block	:	BLOCKNAME
 	;
 
 block	:	block COLONCOLON name
-			{ struct symbol *tem
-			    = lookup_symbol (copy_name ($3), $1,
+			{
+			  std::string copy = copy_name ($3);
+			  struct symbol *tem
+			    = lookup_symbol (copy.c_str (), $1,
 					     VAR_DOMAIN, NULL).symbol;
 
 			  if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
 			    error (_("No function \"%s\" in specified context."),
-				   copy_name ($3));
+				   copy.c_str ());
 			  $$ = SYMBOL_BLOCK_VALUE (tem); }
 	;
 
@@ -985,7 +988,7 @@  variable:	name_not_typename ENTRY
 			      || !symbol_read_needs_frame (sym))
 			    error (_("@entry can be used only for function "
 				     "parameters, not for \"%s\""),
-				   copy_name ($1.stoken));
+				   copy_name ($1.stoken).c_str ());
 
 			  write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE);
 			  write_exp_elt_sym (pstate, sym);
@@ -994,13 +997,15 @@  variable:	name_not_typename ENTRY
 	;
 
 variable:	block COLONCOLON name
-			{ struct block_symbol sym
-			    = lookup_symbol (copy_name ($3), $1,
+			{
+			  std::string copy = copy_name ($3);
+			  struct block_symbol sym
+			    = lookup_symbol (copy.c_str (), $1,
 					     VAR_DOMAIN, NULL);
 
 			  if (sym.symbol == 0)
 			    error (_("No symbol \"%s\" in specified context."),
-				   copy_name ($3));
+				   copy.c_str ());
 			  if (symbol_read_needs_frame (sym.symbol))
 			    pstate->block_tracker->update (sym);
 
@@ -1049,22 +1054,23 @@  qualified_name:	TYPENAME COLONCOLON name
 			}
 	|	TYPENAME COLONCOLON name COLONCOLON name
 			{
-			  char *copy = copy_name ($3);
+			  std::string copy = copy_name ($3);
 			  error (_("No type \"%s\" within class "
 				   "or namespace \"%s\"."),
-				 copy, TYPE_SAFE_NAME ($1.type));
+				 copy.c_str (), TYPE_SAFE_NAME ($1.type));
 			}
 	;
 
 variable:	qualified_name
 	|	COLONCOLON name_not_typename
 			{
-			  char *name = copy_name ($2.stoken);
+			  std::string name = copy_name ($2.stoken);
 			  struct symbol *sym;
 			  struct bound_minimal_symbol msymbol;
 
 			  sym
-			    = lookup_symbol (name, (const struct block *) NULL,
+			    = lookup_symbol (name.c_str (),
+					     (const struct block *) NULL,
 					     VAR_DOMAIN, NULL).symbol;
 			  if (sym)
 			    {
@@ -1075,13 +1081,14 @@  variable:	qualified_name
 			      break;
 			    }
 
-			  msymbol = lookup_bound_minimal_symbol (name);
+			  msymbol = lookup_bound_minimal_symbol (name.c_str ());
 			  if (msymbol.minsym != NULL)
 			    write_exp_msymbol (pstate, msymbol);
 			  else if (!have_full_symbols () && !have_partial_symbols ())
 			    error (_("No symbol table is loaded.  Use the \"file\" command."));
 			  else
-			    error (_("No symbol \"%s\" in current context."), name);
+			    error (_("No symbol \"%s\" in current context."),
+				   name.c_str ());
 			}
 	;
 
@@ -1124,17 +1131,17 @@  variable:	name_not_typename
 			    }
 			  else
 			    {
-			      char *arg = copy_name ($1.stoken);
+			      std::string arg = copy_name ($1.stoken);
 
 			      bound_minimal_symbol msymbol
-				= lookup_bound_minimal_symbol (arg);
+				= lookup_bound_minimal_symbol (arg.c_str ());
 			      if (msymbol.minsym == NULL)
 				{
 				  if (!have_full_symbols () && !have_partial_symbols ())
 				    error (_("No symbol table is loaded.  Use the \"file\" command."));
 				  else
 				    error (_("No symbol \"%s\" in current context."),
-					   copy_name ($1.stoken));
+					   arg.c_str ());
 				}
 
 			      /* This minsym might be an alias for
@@ -1165,7 +1172,8 @@  variable:	name_not_typename
 
 space_identifier : '@' NAME
 		{
-		  cpstate->type_stack.insert (pstate, copy_name ($2.stoken));
+		  cpstate->type_stack.insert (pstate,
+					      copy_name ($2.stoken).c_str ());
 		}
 	;
 
@@ -1409,7 +1417,7 @@  typebase
 						0); }
 	|	STRUCT name
 			{ $$
-			    = lookup_struct (copy_name ($2),
+			    = lookup_struct (copy_name ($2).c_str (),
 					     pstate->expression_context_block);
 			}
 	|	STRUCT COMPLETE
@@ -1426,7 +1434,8 @@  typebase
 			}
 	|	CLASS name
 			{ $$ = lookup_struct
-			    (copy_name ($2), pstate->expression_context_block);
+			    (copy_name ($2).c_str (),
+			     pstate->expression_context_block);
 			}
 	|	CLASS COMPLETE
 			{
@@ -1442,7 +1451,7 @@  typebase
 			}
 	|	UNION name
 			{ $$
-			    = lookup_union (copy_name ($2),
+			    = lookup_union (copy_name ($2).c_str (),
 					    pstate->expression_context_block);
 			}
 	|	UNION COMPLETE
@@ -1458,7 +1467,7 @@  typebase
 			  $$ = NULL;
 			}
 	|	ENUM name
-			{ $$ = lookup_enum (copy_name ($2),
+			{ $$ = lookup_enum (copy_name ($2).c_str (),
 					    pstate->expression_context_block);
 			}
 	|	ENUM COMPLETE
@@ -1493,7 +1502,7 @@  typebase
                    in the token processing code in yylex. */
 	|	TEMPLATE name '<' type '>'
 			{ $$ = lookup_template_type
-			    (copy_name($2), $4,
+			    (copy_name($2).c_str (), $4,
 			     pstate->expression_context_block);
 			}
 	| const_or_volatile_or_space_identifier_noopt typebase
@@ -2551,7 +2560,6 @@  lex_one_token (struct parser_state *par_state, bool *is_quoted_name)
   unsigned int i;
   const char *tokstart;
   bool saw_structop = last_was_structop;
-  char *copy;
 
   last_was_structop = false;
   *is_quoted_name = false;
@@ -2879,9 +2887,9 @@  lex_one_token (struct parser_state *par_state, bool *is_quoted_name)
   yylval.sval.length = namelen;
 
   /* Catch specific keywords.  */
-  copy = copy_name (yylval.sval);
+  std::string copy = copy_name (yylval.sval);
   for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
-    if (strcmp (copy, ident_tokens[i].oper) == 0)
+    if (copy == ident_tokens[i].oper)
       {
 	if ((ident_tokens[i].flags & FLAG_CXX) != 0
 	    && par_state->language ()->la_language != language_cplus)
@@ -2891,7 +2899,7 @@  lex_one_token (struct parser_state *par_state, bool *is_quoted_name)
 	  {
 	    struct field_of_this_result is_a_field_of_this;
 
-	    if (lookup_symbol (copy,
+	    if (lookup_symbol (copy.c_str (),
 			       pstate->expression_context_block,
 			       VAR_DOMAIN,
 			       (par_state->language ()->la_language
@@ -2953,16 +2961,15 @@  classify_name (struct parser_state *par_state, const struct block *block,
 	       bool is_quoted_name, bool is_after_structop)
 {
   struct block_symbol bsym;
-  char *copy;
   struct field_of_this_result is_a_field_of_this;
 
-  copy = copy_name (yylval.sval);
+  std::string copy = copy_name (yylval.sval);
 
   /* Initialize this in case we *don't* use it in this call; that way
      we can refer to it unconditionally below.  */
   memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
 
-  bsym = lookup_symbol (copy, block, VAR_DOMAIN,
+  bsym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN,
 			par_state->language ()->la_name_of_this
 			? &is_a_field_of_this : NULL);
 
@@ -2985,7 +2992,7 @@  classify_name (struct parser_state *par_state, const struct block *block,
 	{
 	  struct field_of_this_result inner_is_a_field_of_this;
 
-	  bsym = lookup_symbol (copy, block, STRUCT_DOMAIN,
+	  bsym = lookup_symbol (copy.c_str (), block, STRUCT_DOMAIN,
 				&inner_is_a_field_of_this);
 	  if (bsym.symbol != NULL)
 	    {
@@ -3005,7 +3012,7 @@  classify_name (struct parser_state *par_state, const struct block *block,
 	  /* See if it's a file name. */
 	  struct symtab *symtab;
 
-	  symtab = lookup_symtab (copy);
+	  symtab = lookup_symtab (copy.c_str ());
 	  if (symtab)
 	    {
 	      yylval.bval = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab),
@@ -3024,13 +3031,14 @@  classify_name (struct parser_state *par_state, const struct block *block,
   /* See if it's an ObjC classname.  */
   if (par_state->language ()->la_language == language_objc && !bsym.symbol)
     {
-      CORE_ADDR Class = lookup_objc_class (par_state->gdbarch (), copy);
+      CORE_ADDR Class = lookup_objc_class (par_state->gdbarch (),
+					   copy.c_str ());
       if (Class)
 	{
 	  struct symbol *sym;
 
 	  yylval.theclass.theclass = Class;
-	  sym = lookup_struct_typedef (copy,
+	  sym = lookup_struct_typedef (copy.c_str (),
 				       par_state->expression_context_block, 1);
 	  if (sym)
 	    yylval.theclass.type = SYMBOL_TYPE (sym);
@@ -3046,7 +3054,7 @@  classify_name (struct parser_state *par_state, const struct block *block,
 	  || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10)))
     {
       YYSTYPE newlval;	/* Its value is ignored.  */
-      int hextype = parse_number (par_state, copy, yylval.sval.length,
+      int hextype = parse_number (par_state, copy.c_str (), yylval.sval.length,
 				  0, &newlval);
 
       if (hextype == INT)
@@ -3064,7 +3072,7 @@  classify_name (struct parser_state *par_state, const struct block *block,
   if (bsym.symbol == NULL
       && par_state->language ()->la_language == language_cplus
       && is_a_field_of_this.type == NULL
-      && lookup_minimal_symbol (copy, NULL, NULL).minsym == NULL)
+      && lookup_minimal_symbol (copy.c_str (), NULL, NULL).minsym == NULL)
     return UNKNOWN_CPP_NAME;
 
   return NAME;
@@ -3079,7 +3087,6 @@  classify_inner_name (struct parser_state *par_state,
 		     const struct block *block, struct type *context)
 {
   struct type *type;
-  char *copy;
 
   if (context == NULL)
     return classify_name (par_state, block, false, false);
@@ -3088,16 +3095,18 @@  classify_inner_name (struct parser_state *par_state,
   if (!type_aggregate_p (type))
     return ERROR;
 
-  copy = copy_name (yylval.ssym.stoken);
+  std::string copy = copy_name (yylval.ssym.stoken);
   /* N.B. We assume the symbol can only be in VAR_DOMAIN.  */
-  yylval.ssym.sym = cp_lookup_nested_symbol (type, copy, block, VAR_DOMAIN);
+  yylval.ssym.sym = cp_lookup_nested_symbol (type, copy.c_str (), block,
+					     VAR_DOMAIN);
 
   /* If no symbol was found, search for a matching base class named
      COPY.  This will allow users to enter qualified names of class members
      relative to the `this' pointer.  */
   if (yylval.ssym.sym.symbol == NULL)
     {
-      struct type *base_type = cp_find_type_baseclass_by_name (type, copy);
+      struct type *base_type = cp_find_type_baseclass_by_name (type,
+							       copy.c_str ());
 
       if (base_type != NULL)
 	{
@@ -3116,7 +3125,8 @@  classify_inner_name (struct parser_state *par_state,
 	 named COPY when we really wanted a base class of the same name.
 	 Double-check this case by looking for a base class.  */
       {
-	struct type *base_type = cp_find_type_baseclass_by_name (type, copy);
+	struct type *base_type
+	  = cp_find_type_baseclass_by_name (type, copy.c_str ());
 
 	if (base_type != NULL)
 	  {
@@ -3368,13 +3378,13 @@  c_print_token (FILE *file, int type, YYSTYPE value)
 
     case NSSTRING:
     case DOLLAR_VARIABLE:
-      parser_fprintf (file, "sval<%s>", copy_name (value.sval));
+      parser_fprintf (file, "sval<%s>", copy_name (value.sval).c_str ());
       break;
 
     case TYPENAME:
       parser_fprintf (file, "tsym<type=%s, name=%s>",
 		      TYPE_SAFE_NAME (value.tsym.type),
-		      copy_name (value.tsym.stoken));
+		      copy_name (value.tsym.stoken).c_str ());
       break;
 
     case NAME:
@@ -3382,7 +3392,7 @@  c_print_token (FILE *file, int type, YYSTYPE value)
     case NAME_OR_INT:
     case BLOCKNAME:
       parser_fprintf (file, "ssym<name=%s, sym=%s, field_of_this=%d>",
-		       copy_name (value.ssym.stoken),
+		       copy_name (value.ssym.stoken).c_str (),
 		       (value.ssym.sym.symbol == NULL
 			? "(null)" : SYMBOL_PRINT_NAME (value.ssym.sym.symbol)),
 		       value.ssym.is_a_field_of_this);
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index 8f04e93bb8f..6b25ee298d4 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -415,12 +415,13 @@  PrimaryExpression:
 		{ /* Do nothing.  */ }
 |	IdentifierExp
 		{ struct bound_minimal_symbol msymbol;
-		  char *copy = copy_name ($1);
+		  std::string copy = copy_name ($1);
 		  struct field_of_this_result is_a_field_of_this;
 		  struct block_symbol sym;
 
 		  /* Handle VAR, which could be local or global.  */
-		  sym = lookup_symbol (copy, pstate->expression_context_block,
+		  sym = lookup_symbol (copy.c_str (),
+				       pstate->expression_context_block,
 				       VAR_DOMAIN, &is_a_field_of_this);
 		  if (sym.symbol && SYMBOL_CLASS (sym.symbol) != LOC_TYPEDEF)
 		    {
@@ -445,13 +446,14 @@  PrimaryExpression:
 		  else
 		    {
 		      /* Lookup foreign name in global static symbols.  */
-		      msymbol = lookup_bound_minimal_symbol (copy);
+		      msymbol = lookup_bound_minimal_symbol (copy.c_str ());
 		      if (msymbol.minsym != NULL)
 			write_exp_msymbol (pstate, msymbol);
 		      else if (!have_full_symbols () && !have_partial_symbols ())
 			error (_("No symbol table is loaded.  Use the \"file\" command"));
 		      else
-			error (_("No symbol \"%s\" in current context."), copy);
+			error (_("No symbol \"%s\" in current context."),
+			       copy.c_str ());
 		    }
 		  }
 |	TypeExp '.' IdentifierExp
@@ -1037,7 +1039,6 @@  lex_one_token (struct parser_state *par_state)
   unsigned int i;
   const char *tokstart;
   int saw_structop = last_was_structop;
-  char *copy;
 
   last_was_structop = 0;
 
@@ -1281,9 +1282,9 @@  lex_one_token (struct parser_state *par_state)
   yylval.sval.length = namelen;
 
   /* Catch specific keywords.  */
-  copy = copy_name (yylval.sval);
+  std::string copy = copy_name (yylval.sval);
   for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
-    if (strcmp (copy, ident_tokens[i].oper) == 0)
+    if (copy == ident_tokens[i].oper)
       {
 	/* It is ok to always set this, even though we don't always
 	   strictly need to.  */
@@ -1296,7 +1297,7 @@  lex_one_token (struct parser_state *par_state)
 
   yylval.tsym.type
     = language_lookup_primitive_type (par_state->language (),
-				      par_state->gdbarch (), copy);
+				      par_state->gdbarch (), copy.c_str ());
   if (yylval.tsym.type != NULL)
     return TYPENAME;
 
@@ -1345,12 +1346,11 @@  static int
 classify_name (struct parser_state *par_state, const struct block *block)
 {
   struct block_symbol sym;
-  char *copy;
   struct field_of_this_result is_a_field_of_this;
 
-  copy = copy_name (yylval.sval);
+  std::string copy = copy_name (yylval.sval);
 
-  sym = lookup_symbol (copy, block, VAR_DOMAIN, &is_a_field_of_this);
+  sym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN, &is_a_field_of_this);
   if (sym.symbol && SYMBOL_CLASS (sym.symbol) == LOC_TYPEDEF)
     {
       yylval.tsym.type = SYMBOL_TYPE (sym.symbol);
@@ -1359,9 +1359,9 @@  classify_name (struct parser_state *par_state, const struct block *block)
   else if (sym.symbol == NULL)
     {
       /* Look-up first for a module name, then a type.  */
-      sym = lookup_symbol (copy, block, MODULE_DOMAIN, NULL);
+      sym = lookup_symbol (copy.c_str (), block, MODULE_DOMAIN, NULL);
       if (sym.symbol == NULL)
-	sym = lookup_symbol (copy, block, STRUCT_DOMAIN, NULL);
+	sym = lookup_symbol (copy.c_str (), block, STRUCT_DOMAIN, NULL);
 
       if (sym.symbol != NULL)
 	{
@@ -1384,7 +1384,6 @@  classify_inner_name (struct parser_state *par_state,
 		     const struct block *block, struct type *context)
 {
   struct type *type;
-  char *copy;
 
   if (context == NULL)
     return classify_name (par_state, block);
@@ -1393,8 +1392,8 @@  classify_inner_name (struct parser_state *par_state,
   if (!type_aggregate_p (type))
     return ERROR;
 
-  copy = copy_name (yylval.ssym.stoken);
-  yylval.ssym.sym = d_lookup_nested_symbol (type, copy, block);
+  std::string copy = copy_name (yylval.ssym.stoken);
+  yylval.ssym.sym = d_lookup_nested_symbol (type, copy.c_str (), block);
 
   if (yylval.ssym.sym.symbol == NULL)
     return ERROR;
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 9ee5316470f..b326d09c44e 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -490,17 +490,17 @@  variable:	name_not_typename
 			  else
 			    {
 			      struct bound_minimal_symbol msymbol;
-			      char *arg = copy_name ($1.stoken);
+			      std::string arg = copy_name ($1.stoken);
 
 			      msymbol =
-				lookup_bound_minimal_symbol (arg);
+				lookup_bound_minimal_symbol (arg.c_str ());
 			      if (msymbol.minsym != NULL)
 				write_exp_msymbol (pstate, msymbol);
 			      else if (!have_full_symbols () && !have_partial_symbols ())
 				error (_("No symbol table is loaded.  Use the \"file\" command."));
 			      else
 				error (_("No symbol \"%s\" in current context."),
-				       copy_name ($1.stoken));
+				       arg.c_str ());
 			    }
 			}
 	;
@@ -1264,7 +1264,7 @@  yylex (void)
      currently as names of types; NAME for other symbols.
      The caller is not constrained to care about the distinction.  */
   {
-    char *tmp = copy_name (yylval.sval);
+    std::string tmp = copy_name (yylval.sval);
     struct block_symbol result;
     struct field_of_this_result is_a_field_of_this;
     enum domain_enum_tag lookup_domains[] =
@@ -1281,7 +1281,7 @@  yylex (void)
 	   way we can refer to it unconditionally below.  */
 	memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
 
-	result = lookup_symbol (tmp, pstate->expression_context_block,
+	result = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
 				lookup_domains[i],
 				pstate->language ()->la_language
 				== language_cplus
@@ -1298,7 +1298,7 @@  yylex (void)
 
     yylval.tsym.type
       = language_lookup_primitive_type (pstate->language (),
-					pstate->gdbarch (), tmp);
+					pstate->gdbarch (), tmp.c_str ());
     if (yylval.tsym.type != NULL)
       return TYPENAME;
     
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index b1a51374d96..d9759601ee0 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -574,7 +574,8 @@  lookup_function_type_with_arguments (struct type *type,
    return the integer flag defined in gdbtypes.h.  */
 
 int
-address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier)
+address_space_name_to_int (struct gdbarch *gdbarch,
+			   const char *space_identifier)
 {
   int type_flags;
 
@@ -1618,7 +1619,7 @@  lookup_enum (const char *name, const struct block *block)
    visible in lexical block BLOCK.  */
 
 struct type *
-lookup_template_type (char *name, struct type *type, 
+lookup_template_type (const char *name, struct type *type, 
 		      const struct block *block)
 {
   struct symbol *sym;
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 2125ed991d0..157b36d45e0 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1849,7 +1849,7 @@  extern struct type *make_atomic_type (struct type *);
 
 extern void replace_type (struct type *, struct type *);
 
-extern int address_space_name_to_int (struct gdbarch *, char *);
+extern int address_space_name_to_int (struct gdbarch *, const char *);
 
 extern const char *address_space_int_to_name (struct gdbarch *, int);
 
@@ -1995,7 +1995,7 @@  extern struct type *lookup_typename (const struct language_defn *,
 				     struct gdbarch *, const char *,
 				     const struct block *, int);
 
-extern struct type *lookup_template_type (char *, struct type *,
+extern struct type *lookup_template_type (const char *, struct type *,
 					  const struct block *);
 
 extern int get_vptr_fieldno (struct type *, struct type **);
diff --git a/gdb/go-exp.y b/gdb/go-exp.y
index 0084b2f7eb6..ad174119abb 100644
--- a/gdb/go-exp.y
+++ b/gdb/go-exp.y
@@ -538,7 +538,7 @@  variable:	name_not_typename ENTRY
 			      || !symbol_read_needs_frame (sym))
 			    error (_("@entry can be used only for function "
 				     "parameters, not for \"%s\""),
-				   copy_name ($1.stoken));
+				   copy_name ($1.stoken).c_str ());
 
 			  write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE);
 			  write_exp_elt_sym (pstate, sym);
@@ -568,10 +568,10 @@  variable:	name_not_typename
 			  else
 			    {
 			      struct bound_minimal_symbol msymbol;
-			      char *arg = copy_name ($1.stoken);
+			      std::string arg = copy_name ($1.stoken);
 
 			      msymbol =
-				lookup_bound_minimal_symbol (arg);
+				lookup_bound_minimal_symbol (arg.c_str ());
 			      if (msymbol.minsym != NULL)
 				write_exp_msymbol (pstate, msymbol);
 			      else if (!have_full_symbols ()
@@ -580,7 +580,7 @@  variable:	name_not_typename
 				       "Use the \"file\" command."));
 			      else
 				error (_("No symbol \"%s\" in current context."),
-				       copy_name ($1.stoken));
+				       arg.c_str ());
 			    }
 			}
 	;
@@ -1014,7 +1014,6 @@  lex_one_token (struct parser_state *par_state)
   unsigned int i;
   const char *tokstart;
   int saw_structop = last_was_structop;
-  char *copy;
 
   last_was_structop = 0;
 
@@ -1263,9 +1262,9 @@  lex_one_token (struct parser_state *par_state)
   yylval.sval.length = namelen;
 
   /* Catch specific keywords.  */
-  copy = copy_name (yylval.sval);
+  std::string copy = copy_name (yylval.sval);
   for (i = 0; i < sizeof (ident_tokens) / sizeof (ident_tokens[0]); i++)
-    if (strcmp (copy, ident_tokens[i].oper) == 0)
+    if (copy == ident_tokens[i].oper)
       {
 	/* It is ok to always set this, even though we don't always
 	   strictly need to.  */
@@ -1347,15 +1346,15 @@  package_name_p (const char *name, const struct block *block)
 static int
 classify_unsafe_function (struct stoken function_name)
 {
-  char *copy = copy_name (function_name);
+  std::string copy = copy_name (function_name);
 
-  if (strcmp (copy, "Sizeof") == 0)
+  if (copy == "Sizeof")
     {
       yylval.sval = function_name;
       return SIZEOF_KEYWORD;
     }
 
-  error (_("Unknown function in `unsafe' package: %s"), copy);
+  error (_("Unknown function in `unsafe' package: %s"), copy.c_str ());
 }
 
 /* Classify token(s) "name1.name2" where name1 is known to be a package.
@@ -1367,13 +1366,12 @@  classify_unsafe_function (struct stoken function_name)
 static int
 classify_packaged_name (const struct block *block)
 {
-  char *copy;
   struct block_symbol sym;
   struct field_of_this_result is_a_field_of_this;
 
-  copy = copy_name (yylval.sval);
+  std::string copy = copy_name (yylval.sval);
 
-  sym = lookup_symbol (copy, block, VAR_DOMAIN, &is_a_field_of_this);
+  sym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN, &is_a_field_of_this);
 
   if (sym.symbol)
     {
@@ -1397,15 +1395,14 @@  classify_name (struct parser_state *par_state, const struct block *block)
 {
   struct type *type;
   struct block_symbol sym;
-  char *copy;
   struct field_of_this_result is_a_field_of_this;
 
-  copy = copy_name (yylval.sval);
+  std::string copy = copy_name (yylval.sval);
 
   /* Try primitive types first so they win over bad/weird debug info.  */
   type = language_lookup_primitive_type (par_state->language (),
 					 par_state->gdbarch (),
-					 copy);
+					 copy.c_str ());
   if (type != NULL)
     {
       /* NOTE: We take advantage of the fact that yylval coming in was a
@@ -1417,7 +1414,7 @@  classify_name (struct parser_state *par_state, const struct block *block)
 
   /* TODO: What about other types?  */
 
-  sym = lookup_symbol (copy, block, VAR_DOMAIN, &is_a_field_of_this);
+  sym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN, &is_a_field_of_this);
 
   if (sym.symbol)
     {
@@ -1439,7 +1436,7 @@  classify_name (struct parser_state *par_state, const struct block *block)
 	struct stoken sval =
 	  build_packaged_name (current_package_name,
 			       strlen (current_package_name),
-			       copy, strlen (copy));
+			       copy.c_str (), copy.size ());
 
 	xfree (current_package_name);
 	sym = lookup_symbol (sval.ptr, block, VAR_DOMAIN,
@@ -1461,8 +1458,8 @@  classify_name (struct parser_state *par_state, const struct block *block)
       || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10))
     {
       YYSTYPE newlval;	/* Its value is ignored.  */
-      int hextype = parse_number (par_state, copy, yylval.sval.length,
-				  0, &newlval);
+      int hextype = parse_number (par_state, copy.c_str (),
+				  yylval.sval.length, 0, &newlval);
       if (hextype == INT)
 	{
 	  yylval.ssym.sym.symbol = NULL;
@@ -1521,17 +1518,15 @@  yylex (void)
       if (name2.token == NAME)
 	{
 	  /* Ok, we have "name1 . name2".  */
-	  char *copy;
+	  std::string copy = copy_name (current.value.sval);
 
-	  copy = copy_name (current.value.sval);
-
-	  if (strcmp (copy, "unsafe") == 0)
+	  if (copy == "unsafe")
 	    {
 	      popping = 1;
 	      return classify_unsafe_function (name2.value.sval);
 	    }
 
-	  if (package_name_p (copy, pstate->expression_context_block))
+	  if (package_name_p (copy.c_str (), pstate->expression_context_block))
 	    {
 	      popping = 1;
 	      yylval.sval = build_packaged_name (current.value.sval.ptr,
diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index 1ea462ec719..6a0173b251d 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -507,7 +507,7 @@  block	:	fblock
 
 fblock	:	BLOCKNAME
 			{ struct symbol *sym
-			    = lookup_symbol (copy_name ($1),
+			    = lookup_symbol (copy_name ($1).c_str (),
 					     pstate->expression_context_block,
 					     VAR_DOMAIN, 0).symbol;
 			  $$ = sym;}
@@ -517,11 +517,11 @@  fblock	:	BLOCKNAME
 /* GDB scope operator */
 fblock	:	block COLONCOLON BLOCKNAME
 			{ struct symbol *tem
-			    = lookup_symbol (copy_name ($3), $1,
+			    = lookup_symbol (copy_name ($3).c_str (), $1,
 					     VAR_DOMAIN, 0).symbol;
 			  if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
 			    error (_("No function \"%s\" in specified context."),
-				   copy_name ($3));
+				   copy_name ($3).c_str ());
 			  $$ = tem;
 			}
 	;
@@ -541,12 +541,12 @@  variable:	DOLLAR_VARIABLE
 /* GDB scope operator */
 variable:	block COLONCOLON NAME
 			{ struct block_symbol sym
-			    = lookup_symbol (copy_name ($3), $1,
+			    = lookup_symbol (copy_name ($3).c_str (), $1,
 					     VAR_DOMAIN, 0);
 
 			  if (sym.symbol == 0)
 			    error (_("No symbol \"%s\" in specified context."),
-				   copy_name ($3));
+				   copy_name ($3).c_str ());
 			  if (symbol_read_needs_frame (sym.symbol))
 			    pstate->block_tracker->update (sym);
 
@@ -562,7 +562,7 @@  variable:	NAME
 			  struct field_of_this_result is_a_field_of_this;
 
 			  sym
-			    = lookup_symbol (copy_name ($1),
+			    = lookup_symbol (copy_name ($1).c_str (),
 					     pstate->expression_context_block,
 					     VAR_DOMAIN,
 					     &is_a_field_of_this);
@@ -580,17 +580,17 @@  variable:	NAME
 			  else
 			    {
 			      struct bound_minimal_symbol msymbol;
-			      char *arg = copy_name ($1);
+			      std::string arg = copy_name ($1);
 
 			      msymbol =
-				lookup_bound_minimal_symbol (arg);
+				lookup_bound_minimal_symbol (arg.c_str ());
 			      if (msymbol.minsym != NULL)
 				write_exp_msymbol (pstate, msymbol);
 			      else if (!have_full_symbols () && !have_partial_symbols ())
 				error (_("No symbol table is loaded.  Use the \"symbol-file\" command."));
 			      else
 				error (_("No symbol \"%s\" in current context."),
-				       copy_name ($1));
+				       arg.c_str ());
 			    }
 			}
 	;
@@ -600,7 +600,7 @@  type
 			{ $$
 			    = lookup_typename (pstate->language (),
 					       pstate->gdbarch (),
-					       copy_name ($1),
+					       copy_name ($1).c_str (),
 					       pstate->expression_context_block,
 					       0);
 			}
@@ -965,20 +965,17 @@  yylex (void)
      currently as names of types; NAME for other symbols.
      The caller is not constrained to care about the distinction.  */
  {
-
-
-    char *tmp = copy_name (yylval.sval);
+    std::string tmp = copy_name (yylval.sval);
     struct symbol *sym;
 
-    if (lookup_symtab (tmp))
+    if (lookup_symtab (tmp.c_str ()))
       return BLOCKNAME;
-    sym = lookup_symbol (tmp, pstate->expression_context_block,
+    sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
 			 VAR_DOMAIN, 0).symbol;
     if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
       return BLOCKNAME;
     if (lookup_typename (pstate->language (), pstate->gdbarch (),
-			 copy_name (yylval.sval),
-			 pstate->expression_context_block, 1))
+			 tmp.c_str (), pstate->expression_context_block, 1))
       return TYPENAME;
 
     if(sym)
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index da25ae42af6..2d11ff077ac 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -620,37 +620,41 @@  block	:	BLOCKNAME
 			      $$ = SYMBOL_BLOCK_VALUE ($1.sym.symbol);
 			  else
 			    {
+			      std::string copy = copy_name ($1.stoken);
 			      struct symtab *tem =
-				  lookup_symtab (copy_name ($1.stoken));
+				  lookup_symtab (copy.c_str ());
 			      if (tem)
 				$$ = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (tem),
 							STATIC_BLOCK);
 			      else
 				error (_("No file or function \"%s\"."),
-				       copy_name ($1.stoken));
+				       copy.c_str ());
 			    }
 			}
 	;
 
 block	:	block COLONCOLON name
-			{ struct symbol *tem
-			    = lookup_symbol (copy_name ($3), $1,
+			{
+			  std::string copy = copy_name ($3);
+			  struct symbol *tem
+			    = lookup_symbol (copy.c_str (), $1,
 					     VAR_DOMAIN, NULL).symbol;
 
 			  if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
 			    error (_("No function \"%s\" in specified context."),
-				   copy_name ($3));
+				   copy.c_str ());
 			  $$ = SYMBOL_BLOCK_VALUE (tem); }
 	;
 
 variable:	block COLONCOLON name
 			{ struct block_symbol sym;
 
-			  sym = lookup_symbol (copy_name ($3), $1,
+			  std::string copy = copy_name ($3);
+			  sym = lookup_symbol (copy.c_str (), $1,
 					       VAR_DOMAIN, NULL);
 			  if (sym.symbol == 0)
 			    error (_("No symbol \"%s\" in specified context."),
-				   copy_name ($3));
+				   copy.c_str ());
 
 			  write_exp_elt_opcode (pstate, OP_VAR_VALUE);
 			  write_exp_elt_block (pstate, sym.block);
@@ -677,12 +681,13 @@  qualified_name:	typebase COLONCOLON name
 variable:	qualified_name
 	|	COLONCOLON name
 			{
-			  char *name = copy_name ($2);
+			  std::string name = copy_name ($2);
 			  struct symbol *sym;
 			  struct bound_minimal_symbol msymbol;
 
 			  sym =
-			    lookup_symbol (name, (const struct block *) NULL,
+			    lookup_symbol (name.c_str (),
+					   (const struct block *) NULL,
 					   VAR_DOMAIN, NULL).symbol;
 			  if (sym)
 			    {
@@ -693,7 +698,8 @@  variable:	qualified_name
 			      break;
 			    }
 
-			  msymbol = lookup_bound_minimal_symbol (name);
+			  msymbol
+			    = lookup_bound_minimal_symbol (name.c_str ());
 			  if (msymbol.minsym != NULL)
 			    write_exp_msymbol (pstate, msymbol);
 			  else if (!have_full_symbols ()
@@ -702,7 +708,7 @@  variable:	qualified_name
 				   "Use the \"file\" command."));
 			  else
 			    error (_("No symbol \"%s\" in current context."),
-				   name);
+				   name.c_str ());
 			}
 	;
 
@@ -742,17 +748,17 @@  variable:	name_not_typename
 			      if (this_type)
 				current_type = lookup_struct_elt_type (
 				  this_type,
-				  copy_name ($1.stoken), 0);
+				  copy_name ($1.stoken).c_str (), 0);
 			      else
 				current_type = NULL;
 			    }
 			  else
 			    {
 			      struct bound_minimal_symbol msymbol;
-			      char *arg = copy_name ($1.stoken);
+			      std::string arg = copy_name ($1.stoken);
 
 			      msymbol =
-				lookup_bound_minimal_symbol (arg);
+				lookup_bound_minimal_symbol (arg.c_str ());
 			      if (msymbol.minsym != NULL)
 				write_exp_msymbol (pstate, msymbol);
 			      else if (!have_full_symbols ()
@@ -761,7 +767,7 @@  variable:	name_not_typename
 				       "Use the \"file\" command."));
 			      else
 				error (_("No symbol \"%s\" in current context."),
-				       copy_name ($1.stoken));
+				       arg.c_str ());
 			    }
 			}
 	;
@@ -788,12 +794,12 @@  typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 			{ $$ = $1.type; }
 	|	STRUCT name
 			{ $$
-			    = lookup_struct (copy_name ($2),
+			    = lookup_struct (copy_name ($2).c_str (),
 					     pstate->expression_context_block);
 			}
 	|	CLASS name
 			{ $$
-			    = lookup_struct (copy_name ($2),
+			    = lookup_struct (copy_name ($2).c_str (),
 					     pstate->expression_context_block);
 			}
 	/* "const" and "volatile" are curently ignored.  A type qualifier
@@ -1508,7 +1514,7 @@  yylex (void)
      currently as names of types; NAME for other symbols.
      The caller is not constrained to care about the distinction.  */
   {
-    char *tmp = copy_name (yylval.sval);
+    std::string tmp = copy_name (yylval.sval);
     struct symbol *sym;
     struct field_of_this_result is_a_field_of_this;
     int is_a_field = 0;
@@ -1516,11 +1522,12 @@  yylex (void)
 
     is_a_field_of_this.type = NULL;
     if (search_field && current_type)
-      is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
+      is_a_field = (lookup_struct_elt_type (current_type,
+					    tmp.c_str (), 1) != NULL);
     if (is_a_field)
       sym = NULL;
     else
-      sym = lookup_symbol (tmp, pstate->expression_context_block,
+      sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
 			   VAR_DOMAIN, &is_a_field_of_this).symbol;
     /* second chance uppercased (as Free Pascal does).  */
     if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
@@ -1531,11 +1538,12 @@  yylex (void)
              tmp[i] -= ('a'-'A');
          }
        if (search_field && current_type)
-	 is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
+	 is_a_field = (lookup_struct_elt_type (current_type,
+					       tmp.c_str (), 1) != NULL);
        if (is_a_field)
 	 sym = NULL;
        else
-	 sym = lookup_symbol (tmp, pstate->expression_context_block,
+	 sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
 			      VAR_DOMAIN, &is_a_field_of_this).symbol;
       }
     /* Third chance Capitalized (as GPC does).  */
@@ -1553,18 +1561,19 @@  yylex (void)
              tmp[i] -= ('A'-'a');
           }
        if (search_field && current_type)
-	 is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
+	 is_a_field = (lookup_struct_elt_type (current_type,
+					       tmp.c_str (), 1) != NULL);
        if (is_a_field)
 	 sym = NULL;
        else
-	 sym = lookup_symbol (tmp, pstate->expression_context_block,
+	 sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
 			      VAR_DOMAIN, &is_a_field_of_this).symbol;
       }
 
     if (is_a_field || (is_a_field_of_this.type != NULL))
       {
 	tempbuf = (char *) realloc (tempbuf, namelen + 1);
-	strncpy (tempbuf, tmp, namelen);
+	strncpy (tempbuf, tmp.c_str (), namelen);
 	tempbuf [namelen] = 0;
 	yylval.sval.ptr = tempbuf;
 	yylval.sval.length = namelen;
@@ -1581,7 +1590,7 @@  yylex (void)
        no psymtabs (coff, xcoff, or some future change to blow away the
        psymtabs once once symbols are read).  */
     if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
-        || lookup_symtab (tmp))
+        || lookup_symtab (tmp.c_str ()))
       {
 	yylval.ssym.sym.symbol = sym;
 	yylval.ssym.sym.block = NULL;
@@ -1641,13 +1650,13 @@  yylex (void)
 		      /* As big as the whole rest of the expression, which is
 			 at least big enough.  */
 		      char *ncopy
-			= (char *) alloca (strlen (tmp) + strlen (namestart)
+			= (char *) alloca (tmp.size () + strlen (namestart)
 					   + 3);
 		      char *tmp1;
 
 		      tmp1 = ncopy;
-		      memcpy (tmp1, tmp, strlen (tmp));
-		      tmp1 += strlen (tmp);
+		      memcpy (tmp1, tmp.c_str (), tmp.size ());
+		      tmp1 += tmp.size ();
 		      memcpy (tmp1, "::", 2);
 		      tmp1 += 2;
 		      memcpy (tmp1, namestart, p - namestart);
@@ -1685,7 +1694,7 @@  yylex (void)
         }
     yylval.tsym.type
       = language_lookup_primitive_type (pstate->language (),
-					pstate->gdbarch (), tmp);
+					pstate->gdbarch (), tmp.c_str ());
     if (yylval.tsym.type != NULL)
       {
 	free (uptokstart);
diff --git a/gdb/parse.c b/gdb/parse.c
index 359f6f89321..38cc69d54be 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -548,6 +548,7 @@  write_dollar_variable (struct parser_state *ps, struct stoken str)
   struct block_symbol sym;
   struct bound_minimal_symbol msym;
   struct internalvar *isym = NULL;
+  std::string copy;
 
   /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
      and $$digits (equivalent to $<-digits> if you could type that).  */
@@ -588,7 +589,8 @@  write_dollar_variable (struct parser_state *ps, struct stoken str)
 
   /* Any names starting with $ are probably debugger internal variables.  */
 
-  isym = lookup_only_internalvar (copy_name (str) + 1);
+  copy = copy_name (str);
+  isym = lookup_only_internalvar (copy.c_str () + 1);
   if (isym)
     {
       write_exp_elt_opcode (ps, OP_INTERNALVAR);
@@ -600,7 +602,7 @@  write_dollar_variable (struct parser_state *ps, struct stoken str)
   /* On some systems, such as HP-UX and hppa-linux, certain system routines 
      have names beginning with $ or $$.  Check for those, first.  */
 
-  sym = lookup_symbol (copy_name (str), NULL, VAR_DOMAIN, NULL);
+  sym = lookup_symbol (copy.c_str (), NULL, VAR_DOMAIN, NULL);
   if (sym.symbol)
     {
       write_exp_elt_opcode (ps, OP_VAR_VALUE);
@@ -609,7 +611,7 @@  write_dollar_variable (struct parser_state *ps, struct stoken str)
       write_exp_elt_opcode (ps, OP_VAR_VALUE);
       return;
     }
-  msym = lookup_bound_minimal_symbol (copy_name (str));
+  msym = lookup_bound_minimal_symbol (copy.c_str ());
   if (msym.minsym)
     {
       write_exp_msymbol (ps, msym);
@@ -619,7 +621,7 @@  write_dollar_variable (struct parser_state *ps, struct stoken str)
   /* Any other names are assumed to be debugger internal variables.  */
 
   write_exp_elt_opcode (ps, OP_INTERNALVAR);
-  write_exp_elt_intern (ps, create_internalvar (copy_name (str) + 1));
+  write_exp_elt_intern (ps, create_internalvar (copy.c_str () + 1));
   write_exp_elt_opcode (ps, OP_INTERNALVAR);
   return;
 handle_last:
@@ -706,33 +708,12 @@  find_template_name_end (const char *p)
    so they can share the storage that lexptr is parsing.
    When it is necessary to pass a name to a function that expects
    a null-terminated string, the substring is copied out
-   into a separate block of storage.
+   into a separate block of storage.  */
 
-   N.B. A single buffer is reused on each call.  */
-
-char *
+std::string
 copy_name (struct stoken token)
 {
-  /* A temporary buffer for identifiers, so we can null-terminate them.
-     We allocate this with xrealloc.  parse_exp_1 used to allocate with
-     alloca, using the size of the whole expression as a conservative
-     estimate of the space needed.  However, macro expansion can
-     introduce names longer than the original expression; there's no
-     practical way to know beforehand how large that might be.  */
-  static char *namecopy;
-  static size_t namecopy_size;
-
-  /* Make sure there's enough space for the token.  */
-  if (namecopy_size < token.length + 1)
-    {
-      namecopy_size = token.length + 1;
-      namecopy = (char *) xrealloc (namecopy, token.length + 1);
-    }
-      
-  memcpy (namecopy, token.ptr, token.length);
-  namecopy[token.length] = 0;
-
-  return namecopy;
+  return std::string (token.ptr, token.length);
 }
 
 
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
index 5244842e58d..4254ef60e62 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -331,7 +331,7 @@  extern void write_dollar_variable (struct parser_state *, struct stoken str);
 
 extern const char *find_template_name_end (const char *);
 
-extern char *copy_name (struct stoken);
+extern std::string copy_name (struct stoken);
 
 extern int dump_subexp (struct expression *, struct ui_file *, int);
 
diff --git a/gdb/type-stack.c b/gdb/type-stack.c
index cb0c147d307..7c2a7046ca2 100644
--- a/gdb/type-stack.c
+++ b/gdb/type-stack.c
@@ -50,7 +50,7 @@  type_stack::insert (enum type_pieces tp)
 /* See type-stack.h.  */
 
 void
-type_stack::insert (struct expr_builder *pstate, char *string)
+type_stack::insert (struct expr_builder *pstate, const char *string)
 {
   union type_stack_elt element;
   int slot;
diff --git a/gdb/type-stack.h b/gdb/type-stack.h
index 672ad054837..762afde0bf7 100644
--- a/gdb/type-stack.h
+++ b/gdb/type-stack.h
@@ -160,7 +160,7 @@  public:
      tp_pointer, and the new values are inserted above the first
      item.  */
 
-  void insert (struct expr_builder *pstate, char *string);
+  void insert (struct expr_builder *pstate, const char *string);
 
   /* Append the elements of the type stack FROM to the type stack
      THIS.  Always returns THIS.  */