Remove cleanup from build_type_psymtabs_1
authorTom Tromey <tom@tromey.com>
Sun, 25 Feb 2018 18:11:59 +0000 (11:11 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 12 Mar 2018 03:06:41 +0000 (21:06 -0600)
This removes a cleanup from build_type_psymtabs_1, by using
std::vector rather than manual memory management.

gdb/ChangeLog
2018-03-11  Tom Tromey  <tom@tromey.com>

* dwarf2read.c (sort_tu_by_abbrev_offset): Change to be suitable
for use by std::sort.
(build_type_psymtabs_1): Use std::vector.

gdb/ChangeLog
gdb/dwarf2read.c

index 8234b6d..2842b7b 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-11  Tom Tromey  <tom@tromey.com>
+
+       * dwarf2read.c (sort_tu_by_abbrev_offset): Change to be suitable
+       for use by std::sort.
+       (build_type_psymtabs_1): Use std::vector.
+
 2018-03-09  Eli Zaretskii  <eliz@gnu.org>
 
        * top.c (print_gdb_configuration): Reflect LIBIPT, LIBMEMCHECK,
index 5827ab4..bbeb76c 100644 (file)
@@ -8610,19 +8610,13 @@ struct tu_abbrev_offset
   sect_offset abbrev_offset;
 };
 
-/* Helper routine for build_type_psymtabs_1, passed to qsort.  */
+/* Helper routine for build_type_psymtabs_1, passed to std::sort.  */
 
-static int
-sort_tu_by_abbrev_offset (const void *ap, const void *bp)
+static bool
+sort_tu_by_abbrev_offset (const struct tu_abbrev_offset &a,
+                         const struct tu_abbrev_offset &b)
 {
-  const struct tu_abbrev_offset * const *a
-    = (const struct tu_abbrev_offset * const*) ap;
-  const struct tu_abbrev_offset * const *b
-    = (const struct tu_abbrev_offset * const*) bp;
-  sect_offset aoff = (*a)->abbrev_offset;
-  sect_offset boff = (*b)->abbrev_offset;
-
-  return (aoff > boff) - (aoff < boff);
+  return a.abbrev_offset < b.abbrev_offset;
 }
 
 /* Efficiently read all the type units.
@@ -8647,10 +8641,8 @@ static void
 build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
 {
   struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats;
-  struct cleanup *cleanups;
   abbrev_table_up abbrev_table;
   sect_offset abbrev_offset;
-  struct tu_abbrev_offset *sorted_by_abbrev;
   int i;
 
   /* It's up to the caller to not call us multiple times.  */
@@ -8683,8 +8675,8 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   /* Sort in a separate table to maintain the order of all_type_units
      for .gdb_index: TU indices directly index all_type_units.  */
-  sorted_by_abbrev = XNEWVEC (struct tu_abbrev_offset,
-                             dwarf2_per_objfile->n_type_units);
+  std::vector<struct tu_abbrev_offset> sorted_by_abbrev
+    (dwarf2_per_objfile->n_type_units);
   for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
     {
       struct signatured_type *sig_type = dwarf2_per_objfile->all_type_units[i];
@@ -8695,9 +8687,8 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
                            sig_type->per_cu.section,
                            sig_type->per_cu.sect_off);
     }
-  cleanups = make_cleanup (xfree, sorted_by_abbrev);
-  qsort (sorted_by_abbrev, dwarf2_per_objfile->n_type_units,
-        sizeof (struct tu_abbrev_offset), sort_tu_by_abbrev_offset);
+  std::sort (sorted_by_abbrev.begin (), sorted_by_abbrev.end (),
+            sort_tu_by_abbrev_offset);
 
   abbrev_offset = (sect_offset) ~(unsigned) 0;
 
@@ -8720,8 +8711,6 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
       init_cutu_and_read_dies (&tu->sig_type->per_cu, abbrev_table.get (),
                               0, 0, build_type_psymtabs_reader, NULL);
     }
-
-  do_cleanups (cleanups);
 }
 
 /* Print collected type unit statistics.  */