mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-23 18:14:13 +08:00
Introduce htab_delete_entry
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.
This commit is contained in:
parent
fe1f847d9a
commit
ef5f598ca6
@ -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):
|
||||
|
@ -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. */
|
||||
|
@ -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);
|
||||
|
||||
/* 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 *
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user