Change streq to return bool
authorTom Tromey <tom@tromey.com>
Sun, 1 Apr 2018 15:33:13 +0000 (09:33 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 5 Apr 2018 13:39:36 +0000 (07:39 -0600)
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.

gdb/ChangeLog
gdb/ada-lang.c
gdb/breakpoint.c
gdb/completer.c
gdb/utils.c
gdb/utils.h

index b88f503b0c0192b2565bb481e46f22e156ea3446..f670b9daffdaa695114a4d276c8b1bc8f5fa42a3 100644 (file)
@@ -1,3 +1,15 @@
+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>:
index 11939d77986b4ba035e028cad4351011535d07f8..de20c43beddc749ff6f81d74349be80fe58b458e 100644 (file)
@@ -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);
index 991c29c1e2d951e5ad90519a54fe27a4f6a850f6..f84fef2beaaf6e6d8fcd7b61a6be289190a4fdf0 100644 (file)
@@ -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)
     {
index 4de1bcff3295dac81266b0b8176cf8362b19f96c..769dcf0eb635d23255ded4cd4349fc210fd1c885 100644 (file)
@@ -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);
 }
 
index ee19fed172cb69d8b342d77a90795304a0997d2a..bd7553e5f4660f4397d38bbb29b3b19029d5e5e8 100644 (file)
@@ -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
 
 /*
index 0de0fe2baa7e043ac45756f245b29131b327ce12..d3b8871b58220286d2148ff2f1fa6a0144fb24e4 100644 (file)
@@ -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 *);
 
This page took 0.04438 seconds and 4 git commands to generate.