From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id higpFjEwWWBjLAAAWB0awg (envelope-from ) for ; Mon, 22 Mar 2021 20:02:57 -0400 Received: by simark.ca (Postfix, from userid 112) id 4D00B1EF78; Mon, 22 Mar 2021 20:02:57 -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 EE8B21E789 for ; Mon, 22 Mar 2021 20:02:55 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F219B3854835; Tue, 23 Mar 2021 00:02:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F219B3854835 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616457775; bh=fLcvpzNezM9KDCVIBnSvC39OEWvh76hR+Kyz0qrTNL8=; 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=JF04tbWQXs9tnz+Ba/hxmcxwyayH9wWq3WxLZT4/OjG6rFH9jckWR2phWxYlh2H9t hKM5MsXUoUsRddt3oVmPyw+1sWW/j7V6EK69mSgMgZTianuEUU7t2UegHcgGGg0azK l1Ig2pbqPDHf4WHlhMImUy5nm4a4bVO9m5HkfkfE= Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id 90F3C3858D29; Tue, 23 Mar 2021 00:02:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 90F3C3858D29 Received: by mail-pj1-x102d.google.com with SMTP id ot17-20020a17090b3b51b0290109c9ac3c34so9116507pjb.4; Mon, 22 Mar 2021 17:02:50 -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=fLcvpzNezM9KDCVIBnSvC39OEWvh76hR+Kyz0qrTNL8=; b=VKCTG/2Ga7fZs6r5PAgjlGtCA1DsS4IabMTgmcOdFP84AJcjSmaufJhocPyV6CNrQW TS2+aeP7TpnKyoyBfxgCNFAhGaAjdaOS/IWghyorsQbdW/fA+jwLlrqPSDXreeU8sg2I Vq++enaJuIqar0zQJYBz/gsJB9rWTxrfeIVJ9HacCJaB1tTwLCkNv6QK7zGv3UhbDK4f 33rFX6wNqGu083XaLgM+/KXjFHRa7dTV6vaK87XxMLvkF46NQCiaGTDJniCH8FmsznWS c1gdVT/8IpVhfYU1HFBtgssNThxOfI0tYLerzxFjOqtjSJcKGPVVIHAaePeecnUMkAbD tUig== X-Gm-Message-State: AOAM530vYJMyRH/prIodiprq7ANU1r6KUDk412FDZgctr+U2kHH1jBsi 1Q10kkyEMsmSo9Hf/LkzvT8JoTVFXTfzyA== X-Google-Smtp-Source: ABdhPJzOZ2WxbAbwwbcdCWrSjOJPm1hbEuccSft1cacfJPXDzualqnpDe1fPmIi6XmGFrAlBcA2Ggw== X-Received: by 2002:a17:90a:8505:: with SMTP id l5mr1553510pjn.100.1616457769629; Mon, 22 Mar 2021 17:02:49 -0700 (PDT) Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:785e:1d9c:e838:f11f]) by smtp.gmail.com with ESMTPSA id x2sm13915815pga.60.2021.03.22.17.02.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 17:02:49 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 5D6D9400B4; Tue, 23 Mar 2021 10:32:45 +1030 (ACDT) Date: Tue, 23 Mar 2021 10:32:45 +1030 To: Martin =?utf-8?B?TGnFoWth?= Subject: Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ. Message-ID: <20210323000245.GZ6791@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> <20210321131254.GS6791@bubble.grove.modra.org> <87k0q0j5ql.fsf@tromey.com> <20210322120652.GV6791@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: Tom Tromey , Alan Modra via Binutils , gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On Mon, Mar 22, 2021 at 05:42:50PM +0100, Martin Liška wrote: > Anyway for the sim failures. What about directly including in bfd-in.h? That would be OK if we didn't care about really old systems. See for example the way bfd/sysdep.h includes string.h. But all of this horrible old code that likely hasn't been tested is eons should simply disappear. Instead binutils should be using the gnulib import already available in the binutils-gdb repository to support old systems. I've had that project on my todo list for quite a while. We'd be able to include stdint.h and stdbool.h for example, throwing away bfd_stdint.h and replacing bfd_boolean with bool. Meanwhile, this is a tidied version of the patch I sent you last night, Tom. If you already have one of your own then please ignore this. --- Subject: str-util.h Defining startswith in bfd.h breaks sim targets that don't happen to include string.h before bfd.h, and since bfd.h is exported, might break other projects that use bfd.h. include/ * str-util.h: New file. bfd/ * sysdep.h: Include str-util.h. * bfd-in.h (startswith): Delete. * bfd-in2.h: Regenerate. binutils/ * sysdep.h: Include str-util.h. gas/ * as.h: Include str-util.h. gdbsupport/ * common-utils.h: Include str-util.h. ld/ * sysdep.h: Include str-util.h. opcodes/ * sysdep.h: Include str-util.h. diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index fda9fe0198..92391bb6a3 100644 --- a/bfd/bfd-in.h +++ b/bfd/bfd-in.h @@ -554,11 +554,3 @@ 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; -} diff --git a/bfd/sysdep.h b/bfd/sysdep.h index 338d731112..b04847ffc3 100644 --- a/bfd/sysdep.h +++ b/bfd/sysdep.h @@ -119,6 +119,8 @@ extern char *strrchr (); #include "filenames.h" +#include "str-util.h" + #if !HAVE_DECL_FFS extern int ffs (int); #endif diff --git a/binutils/sysdep.h b/binutils/sysdep.h index 183bb01653..022029a3f9 100644 --- a/binutils/sysdep.h +++ b/binutils/sysdep.h @@ -78,6 +78,8 @@ extern char *strrchr (); #include "binary-io.h" +#include "str-util.h" + #if !HAVE_DECL_STPCPY extern char *stpcpy (char *, const char *); #endif diff --git a/gas/as.h b/gas/as.h index d6ac208289..a0346ad062 100644 --- a/gas/as.h +++ b/gas/as.h @@ -97,6 +97,8 @@ /* Define the standard progress macros. */ #include "progress.h" +#include "str-util.h" + /* Other stuff from config.h. */ #ifdef NEED_DECLARATION_ENVIRON extern char **environ; diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h index 1de747f186..65569ffe78 100644 --- a/gdbsupport/common-utils.h +++ b/gdbsupport/common-utils.h @@ -45,6 +45,8 @@ #include "gdb_string_view.h" +#include "str-util.h" + /* xmalloc(), xrealloc() and xcalloc() have already been declared in "libiberty.h". */ diff --git a/include/str-util.h b/include/str-util.h new file mode 100644 index 0000000000..24aba56563 --- /dev/null +++ b/include/str-util.h @@ -0,0 +1,27 @@ +/* String utility functions used by GDB and binutils. + Copyright (C) 2021 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef STR_UTIL_H +#define STR_UTIL_H + +/* Return 1 if the start of STR matches PREFIX, 0 otherwise. */ + +static inline int +startswith (const char *str, const char *prefix) +{ + return strncmp (str, prefix, strlen (prefix)) == 0; +} +#endif diff --git a/ld/sysdep.h b/ld/sysdep.h index 206c02c8c5..9e97d2d95b 100644 --- a/ld/sysdep.h +++ b/ld/sysdep.h @@ -68,6 +68,8 @@ extern char *strrchr (); #include "fopen-same.h" #endif +#include "str-util.h" + #ifdef HAVE_FCNTL_H #include #else diff --git a/opcodes/sysdep.h b/opcodes/sysdep.h index bcac6d851c..a0732861b7 100644 --- a/opcodes/sysdep.h +++ b/opcodes/sysdep.h @@ -52,6 +52,8 @@ #endif #endif +#include "str-util.h" + #if !HAVE_DECL_STPCPY extern char *stpcpy (char *__dest, const char *__src); #endif -- Alan Modra Australia Development Lab, IBM