[RFA,2/4] Remove last cleanups from d-exp.y

Message ID 20170906051306.6092-3-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Sept. 6, 2017, 5:13 a.m. UTC
  This removes the last remaining cleanups from d-exp.y.

ChangeLog
2017-09-05  Tom Tromey  <tom@tromey.com>

	* d-exp.y (PrimaryExpression): Use std::string.
	(d_parse): Don't create a cleanup.
---
 gdb/ChangeLog |  5 +++++
 gdb/d-exp.y   | 28 ++++++++++------------------
 2 files changed, 15 insertions(+), 18 deletions(-)
  

Comments

Pedro Alves Sept. 6, 2017, 7:31 p.m. UTC | #1
On 09/06/2017 06:13 AM, Tom Tromey wrote:

> --- a/gdb/d-exp.y
> +++ b/gdb/d-exp.y
> @@ -470,15 +470,15 @@ PrimaryExpression:
>  			      struct block_symbol sym;
>  			      const char *type_name = TYPE_SAFE_NAME (type);
>  			      int type_name_len = strlen (type_name);
> -			      char *name;
> +			      std::string name;
>  
> -			      name = xstrprintf ("%.*s.%.*s",
> -						 type_name_len, type_name,
> -						 $3.length, $3.ptr);
> -			      make_cleanup (xfree, name);
> +			      name = string_printf ("%.*s.%.*s",

You can merge the declaration + initialization here in a single
statement to avoid running the default std::string ctor.  I.e.,:

		      std::string name = string_printf ("%.*s.%.*s",

Otherwise looks fine to me.  Thanks!

Pedro Alves
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c332de3..d158b6e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@ 
 2017-09-05  Tom Tromey  <tom@tromey.com>
 
+	* d-exp.y (PrimaryExpression): Use std::string.
+	(d_parse): Don't create a cleanup.
+
+2017-09-05  Tom Tromey  <tom@tromey.com>
+
 	* utils.c (do_clear_parser_state): Remove.
 	(make_cleanup_clear_parser_state): Remove.
 	* p-exp.y (pascal_parse): Use scoped_restore.
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index 9b773c6..c5e6590 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -470,15 +470,15 @@  PrimaryExpression:
 			      struct block_symbol sym;
 			      const char *type_name = TYPE_SAFE_NAME (type);
 			      int type_name_len = strlen (type_name);
-			      char *name;
+			      std::string name;
 
-			      name = xstrprintf ("%.*s.%.*s",
-						 type_name_len, type_name,
-						 $3.length, $3.ptr);
-			      make_cleanup (xfree, name);
+			      name = string_printf ("%.*s.%.*s",
+						    type_name_len, type_name,
+						    $3.length, $3.ptr);
 
 			      sym =
-				lookup_symbol (name, (const struct block *) NULL,
+				lookup_symbol (name.c_str (),
+					       (const struct block *) NULL,
 					       VAR_DOMAIN, NULL);
 			      if (sym.symbol)
 				{
@@ -489,13 +489,14 @@  PrimaryExpression:
 				  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 ());
 			    }
 
 			  /* Check if the qualified name resolves as a member
@@ -1620,18 +1621,11 @@  yylex (void)
 int
 d_parse (struct parser_state *par_state)
 {
-  int result;
-  struct cleanup *back_to;
-
   /* Setting up the parser state.  */
   scoped_restore pstate_restore = make_scoped_restore (&pstate);
   gdb_assert (par_state != NULL);
   pstate = par_state;
 
-  /* Note that parsing (within yyparse) freely installs cleanups
-     assuming they're run here (below).  */
-  back_to = make_cleanup (null_cleanup, NULL);
-
   scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
 							parser_debug);
 
@@ -1643,9 +1637,7 @@  d_parse (struct parser_state *par_state)
   popping = 0;
   name_obstack.clear ();
 
-  result = yyparse ();
-  do_cleanups (back_to);
-  return result;
+  return yyparse ();
 }
 
 void