Remove symbolp vector
authorTom Tromey <tom@tromey.com>
Fri, 3 Nov 2017 20:55:39 +0000 (14:55 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 8 Nov 2017 18:20:14 +0000 (11:20 -0700)
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-08  Tom Tromey  <tom@tromey.com>

* dwarf2read.c (symbolp): Remove typedef.
(read_func_scope): Use std::vector.
(process_structure_scope): Use std::vector.

gdb/ChangeLog
gdb/dwarf2read.c

index a26afa421737649ebec158d49daeb8f9a7ea93b7..cf9ccfc58f8852fe84aed7a7cb31302f0ff336e0 100644 (file)
@@ -1,3 +1,9 @@
+2017-11-08  Tom Tromey  <tom@tromey.com>
+
+       * dwarf2read.c (symbolp): Remove typedef.
+       (read_func_scope): Use std::vector.
+       (process_structure_scope): Use std::vector.
+
 2017-11-08  Pedro Alves  <palves@redhat.com>
 
        * ada-lang.c (ada_make_symbol_completion_list): Use
index 389d8f70b2bc71cb1e86d71e3323269da3c09448..b6bd2917e35f378e983cf959d1273399ab8ccf65 100644 (file)
@@ -83,9 +83,6 @@
 #include <unordered_map>
 #include "selftest.h"
 
-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.  */
@@ -12204,7 +12201,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)
@@ -12297,7 +12294,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);
@@ -12352,18 +12349,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
@@ -14314,7 +14310,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));
@@ -14359,27 +14355,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.  */
This page took 0.04404 seconds and 4 git commands to generate.