aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-09-17 11:47:50 -0600
committerTom Tromey <tom@tromey.com>2020-09-17 11:58:56 -0600
commit32580f6d2eccfe32ee72b17f63c9e70cf867c09e (patch)
treec1f2849459cea4527e3de30f0327bb98d294a23f
parentc1fb98360cf47485a5f943b657fe8d56244da7e7 (diff)
downloadgdb-32580f6d2eccfe32ee72b17f63c9e70cf867c09e.zip
gdb-32580f6d2eccfe32ee72b17f63c9e70cf867c09e.tar.gz
gdb-32580f6d2eccfe32ee72b17f63c9e70cf867c09e.tar.bz2
Use htab_up in completion_tracker
This changes completion_tracker to use htab_up, rather than explicit calls to htab_delete. gdb/ChangeLog 2020-09-17 Tom Tromey <tom@tromey.com> * completer.c (completion_tracker::discard_completions) (completion_tracker::~completion_tracker) (completion_tracker::maybe_add_completion) (completion_tracker::remove_completion) (completion_tracker::recompute_lowest_common_denominator) (completion_tracker::build_completion_result): Update. * completer.h (class completion_tracker) <have_completions>: Update. <m_entries_hash>: Now htab_up.
-rw-r--r--gdb/ChangeLog12
-rw-r--r--gdb/completer.c29
-rw-r--r--gdb/completer.h4
3 files changed, 27 insertions, 18 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index cd0a180..8f8f7a9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,17 @@
2020-09-17 Tom Tromey <tom@tromey.com>
+ * completer.c (completion_tracker::discard_completions)
+ (completion_tracker::~completion_tracker)
+ (completion_tracker::maybe_add_completion)
+ (completion_tracker::remove_completion)
+ (completion_tracker::recompute_lowest_common_denominator)
+ (completion_tracker::build_completion_result): Update.
+ * completer.h (class completion_tracker) <have_completions>:
+ Update.
+ <m_entries_hash>: Now htab_up.
+
+2020-09-17 Tom Tromey <tom@tromey.com>
+
* breakpoint.c (ambiguous_names_p): Use htab_up.
2020-09-17 Tom Tromey <tom@tromey.com>
diff --git a/gdb/completer.c b/gdb/completer.c
index 7d26774..e75b8b4 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -1587,10 +1587,7 @@ completion_tracker::discard_completions ()
m_lowest_common_denominator_unique = false;
m_lowest_common_denominator_valid = false;
- /* A null check here allows this function to be used from the
- constructor. */
- if (m_entries_hash != NULL)
- htab_delete (m_entries_hash);
+ m_entries_hash.reset (nullptr);
/* A callback used by the hash table to compare new entries with existing
entries. We can't use the standard streq_hash function here as the
@@ -1618,10 +1615,10 @@ completion_tracker::discard_completions ()
return entry->hash_name ();
};
- m_entries_hash = 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,
+ completion_hash_entry::deleter,
+ xcalloc, xfree));
}
/* See completer.h. */
@@ -1629,7 +1626,6 @@ completion_tracker::discard_completions ()
completion_tracker::~completion_tracker ()
{
xfree (m_lowest_common_denominator);
- htab_delete (m_entries_hash);
}
/* See completer.h. */
@@ -1645,11 +1641,12 @@ completion_tracker::maybe_add_completion
if (max_completions == 0)
return false;
- if (htab_elements (m_entries_hash) >= max_completions)
+ if (htab_elements (m_entries_hash.get ()) >= max_completions)
return false;
hashval_t hash = htab_hash_string (name.get ());
- slot = htab_find_slot_with_hash (m_entries_hash, name.get (), hash, INSERT);
+ slot = htab_find_slot_with_hash (m_entries_hash.get (), name.get (),
+ hash, INSERT);
if (*slot == HTAB_EMPTY_ENTRY)
{
const char *match_for_lcd_str = NULL;
@@ -1700,10 +1697,10 @@ void
completion_tracker::remove_completion (const char *name)
{
hashval_t hash = htab_hash_string (name);
- if (htab_find_slot_with_hash (m_entries_hash, name, hash, NO_INSERT)
+ if (htab_find_slot_with_hash (m_entries_hash.get (), name, hash, NO_INSERT)
!= NULL)
{
- htab_remove_elt_with_hash (m_entries_hash, name, hash);
+ htab_remove_elt_with_hash (m_entries_hash.get (), name, hash);
m_lowest_common_denominator_valid = false;
}
}
@@ -2144,7 +2141,7 @@ completion_tracker::recompute_lowest_common_denominator ()
return 1;
};
- htab_traverse (m_entries_hash, visitor_func, this);
+ htab_traverse (m_entries_hash.get (), visitor_func, this);
m_lowest_common_denominator_valid = true;
}
@@ -2227,7 +2224,7 @@ completion_result
completion_tracker::build_completion_result (const char *text,
int start, int end)
{
- size_t element_count = htab_elements (m_entries_hash);
+ size_t element_count = htab_elements (m_entries_hash.get ());
if (element_count == 0)
return {};
@@ -2294,7 +2291,7 @@ completion_tracker::build_completion_result (const char *text,
};
/* Build the completion list and add a null at the end. */
- htab_traverse_noresize (m_entries_hash, func, &builder);
+ htab_traverse_noresize (m_entries_hash.get (), func, &builder);
match_list[builder.index] = NULL;
return completion_result (match_list, builder.index - 1, false);
diff --git a/gdb/completer.h b/gdb/completer.h
index d3afa5f..60b3800 100644
--- a/gdb/completer.h
+++ b/gdb/completer.h
@@ -393,7 +393,7 @@ public:
/* True if we have any completion match recorded. */
bool have_completions () const
- { return htab_elements (m_entries_hash) > 0; }
+ { return htab_elements (m_entries_hash.get ()) > 0; }
/* Discard the current completion match list and the current
LCD. */
@@ -440,7 +440,7 @@ private:
will remove duplicates, and if removal of duplicates there brings
the total under max_completions the user may think gdb quit
searching too early. */
- htab_t m_entries_hash = NULL;
+ htab_up m_entries_hash;
/* If non-zero, then this is the quote char that needs to be
appended after completion (iff we have a unique completion). We