From: Alan Modra via Gdb-patches <gdb-patches@sourceware.org>
To: Tom Tromey <tom@tromey.com>
Cc: Alan Modra via Binutils <binutils@sourceware.org>,
gdb-patches@sourceware.org
Subject: Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
Date: Sun, 21 Mar 2021 23:42:54 +1030 [thread overview]
Message-ID: <20210321131254.GS6791@bubble.grove.modra.org> (raw)
In-Reply-To: <87wnu1k5z1.fsf@tromey.com>
On Sat, Mar 20, 2021 at 12:58:10PM -0600, Tom Tromey wrote:
> >>>>> "Alan" == Alan Modra via Binutils <binutils@sourceware.org> 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 <stddef.h>
#include <stdio.h>
#include <stdint.h>
+#include <string.h>
#include <limits.h>
#include <ctype.h>
#include <elf.h>
--
Alan Modra
Australia Development Lab, IBM
next prev parent reply other threads:[~2021-03-21 13:13 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4d8880dd-4a83-f0fc-dafd-2079493d4093@suse.cz>
[not found] ` <alpine.BSF.2.20.16.2103181426260.908@arjuna.pair.com>
[not found] ` <20210319063759.GM6791@bubble.grove.modra.org>
[not found] ` <b0e46fde-465a-8884-d3e7-2c441a4a62c1@suse.cz>
2021-03-20 7:00 ` Alan Modra via Gdb-patches
2021-03-20 18:58 ` Tom Tromey
2021-03-21 13:12 ` Alan Modra via Gdb-patches [this message]
2021-03-22 2:13 ` Tom Tromey
2021-03-22 12:06 ` Alan Modra via Gdb-patches
2021-03-22 16:13 ` Luis Machado via Gdb-patches
2021-03-22 22:56 ` Alan Modra via Gdb-patches
2021-03-25 10:53 ` Luis Machado via Gdb-patches
2021-03-25 11:54 ` Alan Modra via Gdb-patches
2021-03-25 12:05 ` Luis Machado via Gdb-patches
2021-03-25 19:47 ` Luis Machado via Gdb-patches
2021-03-25 22:31 ` Mike Frysinger via Gdb-patches
2021-03-26 11:44 ` Luis Machado via Gdb-patches
2021-03-30 11:58 ` Luis Machado via Gdb-patches
2021-03-31 13:12 ` Martin Liška
2021-03-31 13:44 ` Luis Machado via Gdb-patches
2021-03-22 16:42 ` Martin Liška
2021-03-23 0:02 ` Alan Modra via Gdb-patches
2021-03-23 4:49 ` Mike Frysinger via Gdb-patches
2021-03-31 20:18 ` Tom Tromey
2021-03-22 6:57 ` Mike Frysinger via Gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210321131254.GS6791@bubble.grove.modra.org \
--to=gdb-patches@sourceware.org \
--cc=amodra@gmail.com \
--cc=binutils@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox