From patchwork Wed Apr 4 04:40:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26591 Received: (qmail 85983 invoked by alias); 4 Apr 2018 04:40:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 85666 invoked by uid 89); 4 Apr 2018 04:40:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway24.websitewelcome.com Received: from gateway24.websitewelcome.com (HELO gateway24.websitewelcome.com) (192.185.51.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Apr 2018 04:40:54 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 3A0B019B37 for ; Tue, 3 Apr 2018 23:40:53 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 3aE9fMWGkcGlp3aE9f8Hec; Tue, 03 Apr 2018 23:40:53 -0500 Received: from 75-166-37-45.hlrn.qwest.net ([75.166.37.45]:43166 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1f3aE9-000hxu-0J; Tue, 03 Apr 2018 23:40:53 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 07/10] Change streq to return bool Date: Tue, 3 Apr 2018 22:40:46 -0600 Message-Id: <20180404044049.31481-8-tom@tromey.com> In-Reply-To: <20180404044049.31481-1-tom@tromey.com> References: <20180404044049.31481-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1f3aE9-000hxu-0J X-Source-Sender: 75-166-37-45.hlrn.qwest.net (bapiya.Home) [75.166.37.45]:43166 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes 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 * 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); +} + /* 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 *);