diff options
author | Tom Tromey <tom@tromey.com> | 2018-04-01 09:33:13 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-04-05 07:39:36 -0600 |
commit | 459a2e4ccf9aadfba9819facba1c9be5297c1625 (patch) | |
tree | 2209376112b15dd814aa718a0d3b1247fecc7fe9 | |
parent | 9be2c17a900178df75a2208fd112ceb4325a70c1 (diff) | |
download | gdb-459a2e4ccf9aadfba9819facba1c9be5297c1625.zip gdb-459a2e4ccf9aadfba9819facba1c9be5297c1625.tar.gz gdb-459a2e4ccf9aadfba9819facba1c9be5297c1625.tar.bz2 |
Change streq to return bool
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.)
ChangeLog
2018-04-05 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.
-rw-r--r-- | gdb/ChangeLog | 12 | ||||
-rw-r--r-- | gdb/ada-lang.c | 5 | ||||
-rw-r--r-- | gdb/breakpoint.c | 6 | ||||
-rw-r--r-- | gdb/completer.c | 4 | ||||
-rw-r--r-- | gdb/utils.c | 13 | ||||
-rw-r--r-- | gdb/utils.h | 9 |
6 files changed, 37 insertions, 12 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b88f503..f670b9d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,17 @@ 2018-04-05 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. + +2018-04-05 Tom Tromey <tom@tromey.com> + * linespec.c (event_location_to_sals) <case ADDRESS_LOCATION>: Remove a string copy. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 11939d7..de20c43 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 991c29c..f84fef2 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 4de1bcf..769dcf0 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 ee19fed..bd7553e 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); +} + /* diff --git a/gdb/utils.h b/gdb/utils.h index 0de0fe2..d3b8871 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 *); |