[RFA] Remove symbolp vector

Message ID 20171104161015.16757-1-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Nov. 4, 2017, 4:10 p.m. UTC
  This removes the symbolp typedef from dwarf2read.c and converts the
associated VEC uses to std::vector.  This fixes a latent possible
memory leak if an exception were thrown, because there were no
cleanups installed for these VECs.

Regression tested on the buildbot.

gdb/ChangeLog
2017-11-04  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (symbolp): Remove typedef.
	(read_func_scope): Use std::vector.
	(process_structure_scope): Use std::vector.
---
 gdb/ChangeLog    |  6 ++++++
 gdb/dwarf2read.c | 26 ++++++++++----------------
 2 files changed, 16 insertions(+), 16 deletions(-)
  

Comments

Pedro Alves Nov. 8, 2017, 10:22 a.m. UTC | #1
On 11/04/2017 04:10 PM, Tom Tromey wrote:
> This removes the symbolp typedef from dwarf2read.c and converts the
> associated VEC uses to std::vector.  This fixes a latent possible
> memory leak if an exception were thrown, because there were no
> cleanups installed for these VECs.
> 
> Regression tested on the buildbot.
> 
> gdb/ChangeLog
> 2017-11-04  Tom Tromey  <tom@tromey.com>
> 
> 	* dwarf2read.c (symbolp): Remove typedef.
> 	(read_func_scope): Use std::vector.
> 	(process_structure_scope): Use std::vector.

OK.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 686fa3f3d3..d6513281e1 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -82,9 +82,6 @@ 
 #include <unordered_set>
 #include <unordered_map>
 
-typedef struct symbol *symbolp;
-DEF_VEC_P (symbolp);
-
 /* When == 1, print basic high level tracing messages.
    When > 1, be more verbose.
    This is in contrast to the low level DIE reading of dwarf_die_debug.  */
@@ -11614,7 +11611,7 @@  read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
   CORE_ADDR baseaddr;
   struct block *block;
   int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
-  VEC (symbolp) *template_args = NULL;
+  std::vector<struct symbol *> template_args;
   struct template_symbol *templ_func = NULL;
 
   if (inlined_func)
@@ -11707,7 +11704,7 @@  read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
 	      struct symbol *arg = new_symbol (child_die, NULL, cu);
 
 	      if (arg != NULL)
-		VEC_safe_push (symbolp, template_args, arg);
+		template_args.push_back (arg);
 	    }
 	  else
 	    process_die (child_die, cu);
@@ -11762,18 +11759,17 @@  read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
   gdbarch_make_symbol_special (gdbarch, newobj->name, objfile);
 
   /* Attach template arguments to function.  */
-  if (! VEC_empty (symbolp, template_args))
+  if (!template_args.empty ())
     {
       gdb_assert (templ_func != NULL);
 
-      templ_func->n_template_arguments = VEC_length (symbolp, template_args);
+      templ_func->n_template_arguments = template_args.size ();
       templ_func->template_arguments
         = XOBNEWVEC (&objfile->objfile_obstack, struct symbol *,
 		     templ_func->n_template_arguments);
       memcpy (templ_func->template_arguments,
-	      VEC_address (symbolp, template_args),
+	      template_args.data (),
 	      (templ_func->n_template_arguments * sizeof (struct symbol *)));
-      VEC_free (symbolp, template_args);
     }
 
   /* In C++, we can have functions nested inside functions (e.g., when
@@ -13724,7 +13720,7 @@  process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
   if (die->child != NULL && ! die_is_declaration (die, cu))
     {
       struct field_info fi;
-      VEC (symbolp) *template_args = NULL;
+      std::vector<struct symbol *> template_args;
       struct cleanup *back_to = make_cleanup (null_cleanup, 0);
 
       memset (&fi, 0, sizeof (struct field_info));
@@ -13769,27 +13765,25 @@  process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
 	      struct symbol *arg = new_symbol (child_die, NULL, cu);
 
 	      if (arg != NULL)
-		VEC_safe_push (symbolp, template_args, arg);
+		template_args.push_back (arg);
 	    }
 
 	  child_die = sibling_die (child_die);
 	}
 
       /* Attach template arguments to type.  */
-      if (! VEC_empty (symbolp, template_args))
+      if (!template_args.empty ())
 	{
 	  ALLOCATE_CPLUS_STRUCT_TYPE (type);
-	  TYPE_N_TEMPLATE_ARGUMENTS (type)
-	    = VEC_length (symbolp, template_args);
+	  TYPE_N_TEMPLATE_ARGUMENTS (type) = template_args.size ();
 	  TYPE_TEMPLATE_ARGUMENTS (type)
 	    = XOBNEWVEC (&objfile->objfile_obstack,
 			 struct symbol *,
 			 TYPE_N_TEMPLATE_ARGUMENTS (type));
 	  memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
-		  VEC_address (symbolp, template_args),
+		  template_args.data (),
 		  (TYPE_N_TEMPLATE_ARGUMENTS (type)
 		   * sizeof (struct symbol *)));
-	  VEC_free (symbolp, template_args);
 	}
 
       /* Attach fields and member functions to the type.  */