From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA v2 07/10] Change streq to return bool
Date: Wed, 04 Apr 2018 04:40:00 -0000 [thread overview]
Message-ID: <20180404044049.31481-8-tom@tromey.com> (raw)
In-Reply-To: <20180404044049.31481-1-tom@tromey.com>
I wanted to use streq with std::unique in another (upcoming) patch in
this seres, so I changed it to return bool. To my surprise, this lead
to regressions. The cause turned out to be that streq was used as an
htab callback -- by casting it to the correct function type. This
sort of cast is invalid, so this patch adds a variant which is
directly suitable for use by htab. (Note that I did not add an
overload, as I could not get that to work with template deduction in
the other patch.)
gdb/ChangeLog
2018-04-03 Tom Tromey <tom@tromey.com>
* completer.c (completion_tracker::completion_tracker): Remove
cast.
(completion_tracker::discard_completions): Likewise.
* breakpoint.c (ambiguous_names_p): Remove cast.
* ada-lang.c (_initialize_ada_language): Remove cast.
* utils.h (streq): Update.
(streq_hash): Add new declaration.
* utils.c (streq): Return bool.
(streq_hash): New function.
---
gdb/ChangeLog | 12 ++++++++++++
gdb/ada-lang.c | 5 ++---
gdb/breakpoint.c | 6 ++----
gdb/completer.c | 4 ++--
gdb/utils.c | 13 +++++++++++--
gdb/utils.h | 9 ++++++++-
6 files changed, 37 insertions(+), 12 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 11939d7798..de20c43bed 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -14722,9 +14722,8 @@ When enabled, the debugger will stop using the DW_AT_GNAT_descriptive_type\n\
DWARF attribute."),
NULL, NULL, &maint_set_ada_cmdlist, &maint_show_ada_cmdlist);
- decoded_names_store = htab_create_alloc
- (256, htab_hash_string, (int (*)(const void *, const void *)) streq,
- NULL, xcalloc, xfree);
+ decoded_names_store = htab_create_alloc (256, htab_hash_string, streq_hash,
+ NULL, xcalloc, xfree);
/* The ada-lang observers. */
gdb::observers::new_objfile.attach (ada_new_objfile_observer);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 991c29c1e2..f84fef2bea 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -13384,10 +13384,8 @@ static int
ambiguous_names_p (struct bp_location *loc)
{
struct bp_location *l;
- htab_t htab = htab_create_alloc (13, htab_hash_string,
- (int (*) (const void *,
- const void *)) streq,
- NULL, xcalloc, xfree);
+ htab_t htab = htab_create_alloc (13, htab_hash_string, streq_hash, NULL,
+ xcalloc, xfree);
for (l = loc; l != NULL; l = l->next)
{
diff --git a/gdb/completer.c b/gdb/completer.c
index 4de1bcff32..769dcf0eb6 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -1469,7 +1469,7 @@ int max_completions = 200;
completion_tracker::completion_tracker ()
{
m_entries_hash = htab_create_alloc (INITIAL_COMPLETION_HTAB_SIZE,
- htab_hash_string, (htab_eq) streq,
+ htab_hash_string, streq_hash,
NULL, xcalloc, xfree);
}
@@ -1487,7 +1487,7 @@ completion_tracker::discard_completions ()
htab_delete (m_entries_hash);
m_entries_hash = htab_create_alloc (INITIAL_COMPLETION_HTAB_SIZE,
- htab_hash_string, (htab_eq) streq,
+ htab_hash_string, streq_hash,
NULL, xcalloc, xfree);
}
diff --git a/gdb/utils.c b/gdb/utils.c
index ee19fed172..bd7553e5f4 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -2601,13 +2601,22 @@ strcmp_iw_ordered (const char *string1, const char *string2)
}
}
-/* A simple comparison function with opposite semantics to strcmp. */
+/* See utils.h. */
-int
+bool
streq (const char *lhs, const char *rhs)
{
return !strcmp (lhs, rhs);
}
+
+/* See utils.h. */
+
+int
+streq_hash (const void *lhs, const void *rhs)
+{
+ return streq ((const char *) lhs, (const char *) rhs);
+}
+
\f
/*
diff --git a/gdb/utils.h b/gdb/utils.h
index 0de0fe2baa..d3b8871b58 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -89,7 +89,14 @@ extern int strcmp_iw (const char *string1, const char *string2);
extern int strcmp_iw_ordered (const char *, const char *);
-extern int streq (const char *, const char *);
+/* Return true if the strings are equal. */
+
+extern bool streq (const char *, const char *);
+
+/* A variant of streq that is suitable for use as an htab
+ callback. */
+
+extern int streq_hash (const void *, const void *);
extern int subset_compare (const char *, const char *);
--
2.13.6
next prev parent reply other threads:[~2018-04-04 4:40 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-04 4:40 [RFA v2 00/10] Remove some cleanups from linespec.c Tom Tromey
2018-04-04 4:40 ` Tom Tromey [this message]
2018-04-04 4:40 ` [RFA v2 02/10] Fix some indentation in linespec.c Tom Tromey
2018-04-04 4:41 ` [RFA v2 04/10] Return std::string from canonical_to_fullform Tom Tromey
2018-04-04 4:41 ` [RFA v2 03/10] Make copy_token_string return unique_xmalloc_ptr Tom Tromey
2018-04-04 4:41 ` [RFA v2 01/10] Remove some cleanups from search_minsyms_for_name Tom Tromey
2018-04-04 4:41 ` [RFA v2 05/10] Have filter_results take a std::vector Tom Tromey
2018-04-04 4:41 ` [RFA v2 08/10] More use of std::vector in linespec.c Tom Tromey
2018-04-04 4:41 ` [RFA v2 09/10] Remove typep and VEC(typep) from linespec.c Tom Tromey
2018-04-04 4:41 ` [RFA v2 10/10] Remove unnecessary include from linespec.h Tom Tromey
2018-04-04 4:41 ` [RFA v2 06/10] Remove a string copy from event_location_to_sals Tom Tromey
2018-04-05 3:08 ` [RFA v2 00/10] Remove some cleanups from linespec.c Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180404044049.31481-8-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).