From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id xAc8GKSdVWACUgAAWB0awg (envelope-from ) for ; Sat, 20 Mar 2021 03:00:52 -0400 Received: by simark.ca (Postfix, from userid 112) id 43CCB1EF78; Sat, 20 Mar 2021 03:00:52 -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 6E7A01E54D for ; Sat, 20 Mar 2021 03:00:48 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 14EC5386F810; Sat, 20 Mar 2021 07:00:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14EC5386F810 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616223647; bh=hPrUt7kV//RdyEIoa7qt9pK7ABnBD8GVMM8mv1e2WKk=; 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=lkLaZ4GVkLyHP2EeSXjp5BiLJXN3N20tL4eYyUpkps4Ts3PGPbwsvkmtAt0+zlUNq HWMTk7bJ5UEVSbn7XKC8rXuk8EAUkG5R1YIqsf9eXudDPiI+NAW8JIsZIuPg7nh0oN 9MttPt1axQDrQsSR/5Iny8kIatasUcxrLRl4oOsI= Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id CC1893842427; Sat, 20 Mar 2021 07:00:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CC1893842427 Received: by mail-pf1-x429.google.com with SMTP id y5so7414223pfn.1; Sat, 20 Mar 2021 00:00:43 -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:content-transfer-encoding :in-reply-to:user-agent; bh=hPrUt7kV//RdyEIoa7qt9pK7ABnBD8GVMM8mv1e2WKk=; b=LvgHd2ExaXSY9m7ZI6nONmuSTdYIuFkmlvU1nDvKsV912LKdvrsn0SLdd71BCd49PV TtWGjNkqIQB4Jru1Z/WoqL59RjkPzgLTVr7wP8vdiPde9dbTFOz6gH4hIoXlj+HFy/cl QOFhGpfwkm2CNqED6OxEZyXhuEMEAusQL5DoCOmjXDFTwg/VQ3sXYgHqt2FDp44rcMul BHjNdQsEr9UoB5O+H/qGKMKFVAy3EciMHtjyA2v2XGcwRPwIaUdipxZSZfsZ5e+JU4mq dsNDb6CGRIaUphQ7zUFUzOVXxltIfyGHLWLMI85dPjrAPbJMcd77WwbDi4226hOdosd/ qjZw== X-Gm-Message-State: AOAM533l9NKitRaNdeTGRf9dZ7n1yb8xswZ4znphw1JOSdchXi/X45iP MBEIfdxk/1ryw/p+5KCyNWG34ZYNMuZZdA== X-Google-Smtp-Source: ABdhPJz1QC6b4LgaUg0JHMk3K7DrYBZl98JfTy1lrtYm37MPzbFk6aWO6kx8G5fz/N6yPaT0Wxdbbg== X-Received: by 2002:a63:c90a:: with SMTP id o10mr14800876pgg.172.1616223642437; Sat, 20 Mar 2021 00:00:42 -0700 (PDT) Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:48ff:b7c9:ad56:bfe2]) by smtp.gmail.com with ESMTPSA id 133sm7779663pfa.130.2021.03.20.00.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 00:00:41 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id B8988418B7; Sat, 20 Mar 2021 17:30:37 +1030 (ACDT) Date: Sat, 20 Mar 2021 17:30:37 +1030 To: Martin =?utf-8?B?TGnFoWth?= Subject: Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ. Message-ID: <20210320070037.GR6791@bubble.grove.modra.org> References: <4d8880dd-4a83-f0fc-dafd-2079493d4093@suse.cz> <20210319063759.GM6791@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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: binutils@sourceware.org, gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On Fri, Mar 19, 2021 at 01:44:38PM +0100, Martin Liška wrote: > @@ -73,6 +64,13 @@ extern "C" { > #define LITMEMCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2) - 1) > #define LITSTRCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2)) > > +/* Return 1 if STR string starts with PREFIX. */ > + > +static inline int > +startswith (const char *str, const char *prefix) > +{ > + return __builtin_strncmp (str, prefix, __builtin_strlen (prefix)) == 0; > +} > > #define BFD_SUPPORTS_PLUGINS @supports_plugins@ > In binutils, we haven't yet made a policy that the project requires gcc, so builtins can't be used without a fallback. I tried building with the following but it runs into a compilation failure in gdb. I expect your patch would do the same.. In file included from /home/alan/src/binutils-gdb/gdb/defs.h:37, from /home/alan/src/binutils-gdb/gdb/gdb.c:19: ../bfd/bfd.h:85:1: error: ambiguating new declaration of ‘int startswith(const char*, const char*)’ startswith (const char *str, const char *prefix) ^~~~~~~~~~ In file included from /home/alan/src/binutils-gdb/gdb/../gdbsupport/common-defs.h:125, from /home/alan/src/binutils-gdb/gdb/defs.h:28, from /home/alan/src/binutils-gdb/gdb/gdb.c:19: /home/alan/src/binutils-gdb/gdb/../gdbsupport/common-utils.h:122:1: note: old declaration ‘bool startswith(const char*, const char*)’ startswith (const char *string, const char *pattern) ^~~~~~~~~~ Forcing gdb to remove their startswith is a bit rude. Should I use #ifndef __cplusplus or #ifndef gdb_assert around the bfd version? bfd/ * bfd-in.h (startswith): New inline. (CONST_STRNEQ): Use startswith. * bfd-in2.h: Regenerate. libctf/ * ctf-impl.h: Include string.h. diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index c9a7673147..4d99c21d3e 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 @@ -73,6 +72,15 @@ extern "C" { #define LITMEMCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2) - 1) #define LITSTRCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2)) +/* Return 1 if STR string starts with PREFIX. */ + +static inline int +startswith (const char *str, const char *prefix) +{ + return strncmp (str, prefix, strlen (prefix)) == 0; +} +#define CONST_STRNEQ(STR1,STR2) startswith (STR1, STR2) + #define BFD_SUPPORTS_PLUGINS @supports_plugins@ 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