Message ID | gerrit.1571229547000.I5389855de2fd70e7065a789a79374b0693651b71@gnutoolchain-gerrit.osci.io |
---|---|
State | New, archived |
Headers |
Received: (qmail 6570 invoked by alias); 16 Oct 2019 12:39:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 6511 invoked by uid 89); 16 Oct 2019 12:39:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Oct 2019 12:39:16 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id C0EC2208FF; Wed, 16 Oct 2019 08:39:13 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id 5CFA9208B6; Wed, 16 Oct 2019 08:39:08 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 3EB8021926; Wed, 16 Oct 2019 08:39:08 -0400 (EDT) X-Gerrit-PatchSet: 1 Date: Wed, 16 Oct 2019 08:39:08 -0400 From: "Christian Biesinger (Code Review)" <gerrit@gnutoolchain-gerrit.osci.io> To: gdb-patches@sourceware.org Cc: Christian Biesinger <cbiesinger@google.com> Message-ID: <gerrit.1571229547000.I5389855de2fd70e7065a789a79374b0693651b71@gnutoolchain-gerrit.osci.io> Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange Subject: [review] Add a string_view version of startswith X-Gerrit-Change-Id: I5389855de2fd70e7065a789a79374b0693651b71 X-Gerrit-Change-Number: 126 X-Gerrit-ChangeURL: <https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/126> X-Gerrit-Commit: 4f19efa87b8c6a33090da56fd122bfaae9731f12 References: <gerrit.1571229547000.I5389855de2fd70e7065a789a79374b0693651b71@gnutoolchain-gerrit.osci.io> Reply-To: cbiesinger@google.com, cbiesinger@google.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline User-Agent: Gerrit/3.0.3 Content-Type: text/plain; charset=UTF-8 |
Commit Message
Simon Marchi (Code Review)
Oct. 16, 2019, 12:39 p.m. UTC
Christian Biesinger has uploaded a new change for review. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/126 ...................................................................... Add a string_view version of startswith Makes sure that the string is longer than prefix, so that strncmp will do the right thing even if the string is not null-terminated. For use in my string_view conversion patch: https://sourceware.org/ml/gdb-patches/2019-10/msg00030.html gdb/ChangeLog: 2019-10-01 Christian Biesinger <cbiesinger@google.com> * gdbsupport/common-utils.h (startswith): Add an overloaded version that takes gdb::string_view arguments. Change-Id: I5389855de2fd70e7065a789a79374b0693651b71 --- M gdb/gdbsupport/common-utils.h 1 file changed, 13 insertions(+), 2 deletions(-)
Comments
Christian Biesinger has posted comments on this change. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/126 ...................................................................... Patch Set 2: (this has been reviewed at https://sourceware.org/ml/gdb-patches/2019-10/msg00035.html, but I'm waiting to land this until https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/125 is reviewed)
Tom Tromey has posted comments on this change. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/126 ...................................................................... Patch Set 3: Code-Review+2 This was already approved elsewhere, but I'm marking it as such in gerrit FAOD.
Tom Tromey has posted comments on this change. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/126 ...................................................................... Patch Set 3: Today I was working in a completely unrelated area, and it turned out I needed this function... I wonder what would happen if I submitted your patch to gerrit as part of another series? Maybe it's best not to find out. Would you mind checking this one in?
On 2019-10-26 7:10 p.m., Tom Tromey (Code Review) wrote: > Tom Tromey has posted comments on this change. > > Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/126 > ...................................................................... > > > Patch Set 3: > > Today I was working in a completely unrelated area, and it turned out I needed > this function... I wonder what would happen if I submitted your patch to gerrit > as part of another series? > > Maybe it's best not to find out. Would you mind checking this one in? If you base your patch on top of Christian's commit (d441ce34f4d2) and push for review, nothing will happen to this patch. Your new patch will just happen to have this one as a parent. If you rebase Christian's patch on master, add yours on top and push for review, then it will add a new revision to Christian's patch (assuming the permissions allow it), and create yours with this one as a parent. And Christian will be grateful to you for rebasing his patch :). I think that you should try it. For science. > -- > Gerrit-Project: binutils-gdb > Gerrit-Branch: master > Gerrit-Change-Id: I5389855de2fd70e7065a789a79374b0693651b71 > Gerrit-Change-Number: 126 > Gerrit-PatchSet: 3 > Gerrit-Owner: Christian Biesinger <cbiesinger@google.com> > Gerrit-Reviewer: Christian Biesinger <cbiesinger@google.com> > Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org> > Gerrit-Comment-Date: Sat, 26 Oct 2019 23:10:58 +0000 > Gerrit-HasComments: No > Gerrit-Has-Labels: No > Gerrit-MessageType: comment >
Simon Marchi (2) has posted comments on this change. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/126 ...................................................................... Patch Set 3: On 2019-10-26 7:10 p.m., Tom Tromey (Code Review) wrote: If you base your patch on top of Christian's commit (d441ce34f4d2) and push for review, nothing will happen to this patch. Your new patch will just happen to have this one as a parent. If you rebase Christian's patch on master, add yours on top and push for review, then it will add a new revision to Christian's patch (assuming the permissions allow it), and create yours with this one as a parent. And Christian will be grateful to you for rebasing his patch :). I think that you should try it. For science.
Simon Marchi has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/126
......................................................................
Patch Set 3:
That part of my previous comment is misleading:
> On 2019-10-26 7:10 p.m., Tom Tromey (Code Review) wrote:
I replied by email, so that's the header my email client added when replying to Tom's comment, and Gerrit interpreted it as part of my comment.
Christian Biesinger has posted comments on this change. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/126 ...................................................................... Patch Set 3: > Patch Set 3: > > If you base your patch on top of Christian's commit (d441ce34f4d2) and push for review, > nothing will happen to this patch. Your new patch will just happen to have this one > as a parent. Interestingly that was not *quite* my experience when I did something very similar: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/307 that should have tromey's https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/176 as parent, but it doesn't show up that way in Gerrit. However the diff itself shows up correctly, relative to tromey's change. > If you rebase Christian's patch on master, add yours on top and push for review, then > it will add a new revision to Christian's patch (assuming the permissions allow it), > and create yours with this one as a parent. And Christian will be grateful to you for > rebasing his patch :). > > I think that you should try it. For science. I'm happy to push this, but I'll hold off for now in case you want to try this first. Let me know.
Simon Marchi has posted comments on this change. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/126 ...................................................................... Patch Set 4: FWIW, I now see Tom's patches in the relation chain on the right, on top of this patch.
Christian Biesinger has posted comments on this change. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/126 ...................................................................... Patch Set 4: > > If you rebase Christian's patch on master, add yours on top and push for review, then > > it will add a new revision to Christian's patch (assuming the permissions allow it), > > and create yours with this one as a parent. And Christian will be grateful to you for > > rebasing his patch :). > > > > I think that you should try it. For science. > > I'm happy to push this, but I'll hold off for now in case you want to try this first. Let me know. OK, now that we have the science results :) I am going to push this as requested.
diff --git a/gdb/gdbsupport/common-utils.h b/gdb/gdbsupport/common-utils.h index a5312cb..e76b5b8 100644 --- a/gdb/gdbsupport/common-utils.h +++ b/gdb/gdbsupport/common-utils.h @@ -23,6 +23,7 @@ #include <string> #include <vector> +#include "gdb_string_view.h" #include "poison.h" /* If possible, define FUNCTION_NAME, a macro containing the name of @@ -110,15 +111,25 @@ extern char *safe_strerror (int); -/* Return non-zero if the start of STRING matches PATTERN, zero +/* Return true if the start of STRING matches PATTERN, false otherwise. */ -static inline int +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. */ + +static inline bool +startswith (gdb::string_view string, gdb::string_view pattern) +{ + return (string.length () >= pattern.length () + && strncmp (string.data (), pattern.data (), pattern.length ()) == 0); +} + ULONGEST strtoulst (const char *num, const char **trailer, int base); /* Skip leading whitespace characters in INP, returning an updated