[PATCH 5/9] Use htab_up in linespec.c
Tom Tromey
tom@tromey.com
Sat Jul 18 17:29:11 GMT 2020
This changes linespec.c to use htab_up rather than explicit calls to
htab_delete. Note that a use still exists in this file, because
linespec_state hasn't been converted to have a real destructor.
gdb/ChangeLog
2020-07-18 Tom Tromey <tom@tromey.com>
* linespec.c (class decode_compound_collector)
<~decode_compound_collector>: Default.
<m_unique_syms>: Now htab_up.
(decode_compound_collector::operator ()): Update.
(class symtab_collector) <~symtab_collector>: Default.
<m_symtab_table>: Now htab_up.
(symtab_collector::operator ()): Update.
---
gdb/ChangeLog | 10 ++++++++++
gdb/linespec.c | 30 +++++++++++-------------------
2 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 4a634e3aff9..57a6283a2d6 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3449,17 +3449,13 @@ class decode_compound_collector
{
public:
decode_compound_collector ()
+ : m_unique_syms (htab_create_alloc (1, htab_hash_pointer,
+ htab_eq_pointer, NULL,
+ xcalloc, xfree))
{
- m_unique_syms = htab_create_alloc (1, htab_hash_pointer,
- htab_eq_pointer, NULL,
- xcalloc, xfree);
}
- ~decode_compound_collector ()
- {
- if (m_unique_syms != NULL)
- htab_delete (m_unique_syms);
- }
+ ~decode_compound_collector () = default;
/* Return all symbols collected. */
std::vector<block_symbol> release_symbols ()
@@ -3473,7 +3469,7 @@ class decode_compound_collector
private:
/* A hash table of all symbols we found. We use this to avoid
adding any symbol more than once. */
- htab_t m_unique_syms;
+ htab_up m_unique_syms;
/* The result vector. */
std::vector<block_symbol> m_symbols;
@@ -3496,7 +3492,7 @@ decode_compound_collector::operator () (block_symbol *bsym)
&& t->code () != TYPE_CODE_NAMESPACE)
return true; /* Continue iterating. */
- slot = htab_find_slot (m_unique_syms, sym, INSERT);
+ slot = htab_find_slot (m_unique_syms.get (), sym, INSERT);
if (!*slot)
{
*slot = sym;
@@ -3726,16 +3722,12 @@ class symtab_collector
{
public:
symtab_collector ()
+ : m_symtab_table (htab_create (1, htab_hash_pointer, htab_eq_pointer,
+ NULL))
{
- m_symtab_table = htab_create (1, htab_hash_pointer, htab_eq_pointer,
- NULL);
}
- ~symtab_collector ()
- {
- if (m_symtab_table != NULL)
- htab_delete (m_symtab_table);
- }
+ ~symtab_collector () = default;
/* Callable as a symbol_found_callback_ftype callback. */
bool operator () (symtab *sym);
@@ -3751,7 +3743,7 @@ class symtab_collector
std::vector<symtab *> m_symtabs;
/* This is used to ensure the symtabs are unique. */
- htab_t m_symtab_table;
+ htab_up m_symtab_table;
};
bool
@@ -3759,7 +3751,7 @@ symtab_collector::operator () (struct symtab *symtab)
{
void **slot;
- slot = htab_find_slot (m_symtab_table, symtab, INSERT);
+ slot = htab_find_slot (m_symtab_table.get (), symtab, INSERT);
if (!*slot)
{
*slot = symtab;
--
2.17.2
More information about the Gdb-patches
mailing list