]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Introduce htab_delete_entry
authorTom Tromey <tom@tromey.com>
Wed, 26 May 2021 13:02:51 +0000 (07:02 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 26 May 2021 13:02:51 +0000 (07:02 -0600)
In a bigger series I'm working on, it is convenient to have a
libiberty hash table that manages objects allocated with 'new'.  To
make this simpler, I wrote a small template function to serve as a
concise wrapper.  Then I realized that this could be reused in a few
other places.

gdb/ChangeLog
2021-05-26  Tom Tromey  <tom@tromey.com>

* dwarf2/read.c (allocate_type_unit_groups_table)
(handle_DW_AT_stmt_list, allocate_dwo_file_hash_table): Use
htab_delete_entry.
(free_line_header_voidp): Remove.
* completer.c
(completion_tracker::completion_hash_entry::deleter): Remove.
(completion_tracker::discard_completions): Use htab_delete_entry.
* utils.h (htab_delete_entry): New template function.

gdb/ChangeLog
gdb/completer.c
gdb/dwarf2/read.c
gdb/utils.h

index b24a24be267d48df3500654085c3200d4f7db032..3efdb5d05e8ff620d24805c901836ca2e8ffb196 100644 (file)
@@ -1,3 +1,14 @@
+2021-05-26  Tom Tromey  <tom@tromey.com>
+
+       * dwarf2/read.c (allocate_type_unit_groups_table)
+       (handle_DW_AT_stmt_list, allocate_dwo_file_hash_table): Use
+       htab_delete_entry.
+       (free_line_header_voidp): Remove.
+       * completer.c
+       (completion_tracker::completion_hash_entry::deleter): Remove.
+       (completion_tracker::discard_completions): Use htab_delete_entry.
+       * utils.h (htab_delete_entry): New template function.
+
 2021-05-24  Hannes Domani  <ssbssa@yahoo.de>
 
        * python/py-tui.c (tui_py_window::refresh_window):
index 6ad788b4344cb3b5085a820ed52720dbc1d6cef6..060160f17faed5028386978fed6fc597e34841a6 100644 (file)
@@ -88,14 +88,6 @@ public:
     return htab_hash_string (m_name.get ());
   }
 
-  /* A static function that can be passed to the htab hash system to be
-     used as a callback that deletes an item from the hash.  */
-  static void deleter (void *arg)
-  {
-    completion_hash_entry *entry = (completion_hash_entry *) arg;
-    delete entry;
-  }
-
 private:
 
   /* The symbol name stored in this hash entry.  */
@@ -1618,10 +1610,11 @@ completion_tracker::discard_completions ()
        return entry->hash_name ();
       };
 
-  m_entries_hash.reset (htab_create_alloc (INITIAL_COMPLETION_HTAB_SIZE,
-                                          entry_hash_func, entry_eq_func,
-                                          completion_hash_entry::deleter,
-                                          xcalloc, xfree));
+  m_entries_hash.reset
+    (htab_create_alloc (INITIAL_COMPLETION_HTAB_SIZE,
+                       entry_hash_func, entry_eq_func,
+                       htab_delete_entry<completion_hash_entry>,
+                       xcalloc, xfree));
 }
 
 /* See completer.h.  */
index 2cd8a95658a9bf8b315af83b9533cd5d22770791..d3b5b89c1c3282a967e27d46d9b6b4259aefd5f6 100644 (file)
@@ -1571,8 +1571,6 @@ typedef std::unique_ptr<struct dwo_file> dwo_file_up;
 static void process_cu_includes (dwarf2_per_objfile *per_objfile);
 
 static void check_producer (struct dwarf2_cu *cu);
-
-static void free_line_header_voidp (void *arg);
 \f
 /* Various complaints about symbol reading that don't abort the process.  */
 
@@ -6739,12 +6737,7 @@ allocate_type_unit_groups_table ()
   return htab_up (htab_create_alloc (3,
                                     hash_type_unit_group,
                                     eq_type_unit_group,
-                                    [] (void *arg)
-                                    {
-                                      type_unit_group *grp
-                                        = (type_unit_group *) arg;
-                                      delete grp;
-                                    },
+                                    htab_delete_entry<type_unit_group>,
                                     xcalloc, xfree));
 }
 
@@ -10431,7 +10424,7 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
       per_objfile->line_header_hash
        .reset (htab_create_alloc (127, line_header_hash_voidp,
                                   line_header_eq_voidp,
-                                  free_line_header_voidp,
+                                  htab_delete_entry<line_header>,
                                   xcalloc, xfree));
     }
 
@@ -10762,17 +10755,10 @@ eq_dwo_file (const void *item_lhs, const void *item_rhs)
 static htab_up
 allocate_dwo_file_hash_table ()
 {
-  auto delete_dwo_file = [] (void *item)
-    {
-      struct dwo_file *dwo_file = (struct dwo_file *) item;
-
-      delete dwo_file;
-    };
-
   return htab_up (htab_create_alloc (41,
                                     hash_dwo_file,
                                     eq_dwo_file,
-                                    delete_dwo_file,
+                                    htab_delete_entry<dwo_file>,
                                     xcalloc, xfree));
 }
 
@@ -20513,16 +20499,6 @@ die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
     return follow_die_ref (die, spec_attr, spec_cu);
 }
 
-/* Stub for free_line_header to match void * callback types.  */
-
-static void
-free_line_header_voidp (void *arg)
-{
-  struct line_header *lh = (struct line_header *) arg;
-
-  delete lh;
-}
-
 /* A convenience function to find the proper .debug_line section for a CU.  */
 
 static struct dwarf2_section_info *
index 94d37c5a8b1a8b2baa65209805aa893f23e76ee9..f05e6627dcaa39dca88a76b461ace926f20d2fd8 100644 (file)
@@ -306,6 +306,15 @@ struct htab_deleter
 /* A unique_ptr wrapper for htab_t.  */
 typedef std::unique_ptr<htab, htab_deleter> htab_up;
 
+/* A wrapper for 'delete' that can used as a hash table entry deletion
+   function.  */
+template<typename T>
+void
+htab_delete_entry (void *ptr)
+{
+  delete (T *) ptr;
+}
+
 extern void init_page_info (void);
 
 /* Temporarily set BATCH_FLAG and the associated unlimited terminal size.