From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id q7WJO2FGV2CxewAAWB0awg (envelope-from ) for ; Sun, 21 Mar 2021 09:13:05 -0400 Received: by simark.ca (Postfix, from userid 112) id E7F161EF78; Sun, 21 Mar 2021 09:13:05 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id BFC851E54D for ; Sun, 21 Mar 2021 09:13:04 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E7B5A3857C74; Sun, 21 Mar 2021 13:13:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E7B5A3857C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616332383; bh=UNqtter0C9zTDQzFqzXJ369pF6auHgfCJGCe/yHxxrg=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=XY5hLTFtTWu7IrPAeLq/n0jfZvtOo5SYvNB+PEwkEbWyFJmtsmp0j/rP0kiiMYR+1 tMTsQpe4HgzmRrZ35d9jcfdvTnmnDGWuqHvK8ddG5HDA2nqxg3oe0NSOKb/rkP3Qdz D5522owTqyb9gntA7i8e/FmzYHn2ufSwTDZvQukY= Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id C711A3858C27; Sun, 21 Mar 2021 13:13:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C711A3858C27 Received: by mail-pl1-x632.google.com with SMTP id h20so5171729plr.4; Sun, 21 Mar 2021 06:13:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=UNqtter0C9zTDQzFqzXJ369pF6auHgfCJGCe/yHxxrg=; b=rpQNlgZ048ExiF4T8zohTmQlFJhSHN3tMBZ9ysMO2UWOVRreslC8AzcQOi67ShUvrb ntWw37Pro7uEgmzm9Hiy9KSVn1aJk3sw17z/Fr7G312cEv+aj/fSYkuVKjrEH/EPuDJn 0VhGo/VxI6ZZl/ugnr4rc5f4ALAq2J8nLlEm/b2vZK917w8zZoBoqWfLMR/teY6hvIDt juH2S10uHfMGiP844gEDE6dS0ZHm0hupEbOqGt+Ci3Ij4mxJwe+LCcPCGpmdzKmqkiJ9 uydS/GjeCoba5654QV+/aDjwTBMsRzXahRYR2OPguzC1mb/o1woyhqkvJP0zaOpGheQW 01Yw== X-Gm-Message-State: AOAM530RHL6tLIwHPSw08uwV+QmbtfWAh5vTMunyiCaBr2l8VpfQ8mgA ayL66Xl5KmZ2h16Uk2ad1cWckLmAsFAp8g== X-Google-Smtp-Source: ABdhPJzrsWQqjE25ag8Y1BE7ijuXQEGdVh02yixgQM1WL+oGwm0UTlAfmdQ+Etl6h9Mkv0+tNBVhHg== X-Received: by 2002:a17:90a:c201:: with SMTP id e1mr8317823pjt.30.1616332379562; Sun, 21 Mar 2021 06:12:59 -0700 (PDT) Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:29b4:33ae:84c:e378]) by smtp.gmail.com with ESMTPSA id u84sm11756805pfc.90.2021.03.21.06.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 06:12:58 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id C906B41972; Sun, 21 Mar 2021 23:42:54 +1030 (ACDT) Date: Sun, 21 Mar 2021 23:42:54 +1030 To: Tom Tromey Subject: Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ. Message-ID: <20210321131254.GS6791@bubble.grove.modra.org> References: <4d8880dd-4a83-f0fc-dafd-2079493d4093@suse.cz> <20210319063759.GM6791@bubble.grove.modra.org> <20210320070037.GR6791@bubble.grove.modra.org> <87wnu1k5z1.fsf@tromey.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87wnu1k5z1.fsf@tromey.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Alan Modra via Gdb-patches Reply-To: Alan Modra Cc: Alan Modra via Binutils , gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On Sat, Mar 20, 2021 at 12:58:10PM -0600, Tom Tromey wrote: > >>>>> "Alan" == Alan Modra via Binutils writes: > > Alan> Forcing gdb to remove their startswith is a bit rude. > > FWIW I think it would be fine, assuming it compiles, considering that > the functions have identical intended semantics. Yes, the following compiles. Fortunately all gdb files that include gdbsupport/common-utils.h also include bfd.h by one means or another. Committed. bfd/ * bfd-in.h (startswith): New inline. (CONST_STRNEQ): Use startswith. * bfd-in2.h: Regenerate. gdbsupport/ * common-utils.h (startswith): Delete version now supplied by bfd.h. libctf/ * ctf-impl.h: Include string.h. diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index c9a7673147..453ac48e26 100644 --- a/bfd/bfd-in.h +++ b/bfd/bfd-in.h @@ -65,7 +65,6 @@ extern "C" { definition of strncmp is provided here. Note - these macros do NOT work if STR2 is not a constant string. */ -#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0) /* strcpy() can have a similar problem, but since we know we are copying a constant string, we can use memcpy which will be faster since there is no need to check for a NUL byte inside STR. We @@ -564,3 +563,12 @@ struct ecoff_debug_swap; struct ecoff_extr; struct bfd_link_info; struct bfd_link_hash_entry; + +/* Return TRUE if the start of STR matches PREFIX, FALSE otherwise. */ + +static inline bfd_boolean +startswith (const char *str, const char *prefix) +{ + return strncmp (str, prefix, strlen (prefix)) == 0; +} +#define CONST_STRNEQ(STR1,STR2) startswith (STR1, STR2) diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h index 28c08ee976..1de747f186 100644 --- a/gdbsupport/common-utils.h +++ b/gdbsupport/common-utils.h @@ -116,16 +116,8 @@ std::string extract_string_maybe_quoted (const char **arg); extern const char *safe_strerror (int); -/* Return true if the start of STRING matches PATTERN, false otherwise. */ - -static inline bool -startswith (const char *string, const char *pattern) -{ - return strncmp (string, pattern, strlen (pattern)) == 0; -} - -/* Version of startswith that takes string_view arguments. See comment - above. */ +/* Version of startswith that takes string_view arguments. Return + true if the start of STRING matches PATTERN, false otherwise. */ static inline bool startswith (gdb::string_view string, gdb::string_view pattern) diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h index ad4af32e7e..342d2ff23e 100644 --- a/libctf/ctf-impl.h +++ b/libctf/ctf-impl.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include -- Alan Modra Australia Development Lab, IBM