Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [review] Add a string_view version of startswith
@ 2019-10-16 12:39 Christian Biesinger (Code Review)
  2019-10-22 19:12 ` [review v2] " Christian Biesinger (Code Review)
                   ` (11 more replies)
  0 siblings, 12 replies; 14+ messages in thread
From: Christian Biesinger (Code Review) @ 2019-10-16 12:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Christian Biesinger

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(-)



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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [review v2] Add a string_view version of startswith
  2019-10-16 12:39 [review] Add a string_view version of startswith Christian Biesinger (Code Review)
@ 2019-10-22 19:12 ` Christian Biesinger (Code Review)
  2019-10-22 22:14 ` [review v3] " Christian Biesinger (Code Review)
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Christian Biesinger (Code Review) @ 2019-10-22 19:12 UTC (permalink / raw)
  To: Christian Biesinger, gdb-patches

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)



^ permalink raw reply	[flat|nested] 14+ messages in thread

* [review v3] Add a string_view version of startswith
  2019-10-16 12:39 [review] Add a string_view version of startswith Christian Biesinger (Code Review)
  2019-10-22 19:12 ` [review v2] " Christian Biesinger (Code Review)
@ 2019-10-22 22:14 ` Christian Biesinger (Code Review)
  2019-10-25 17:35 ` Tom Tromey (Code Review)
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Christian Biesinger (Code Review) @ 2019-10-22 22:14 UTC (permalink / raw)
  To: Christian Biesinger, gdb-patches

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, 12 insertions(+), 0 deletions(-)



diff --git a/gdb/gdbsupport/common-utils.h b/gdb/gdbsupport/common-utils.h
index e96fc21..23bf354 100644
--- a/gdb/gdbsupport/common-utils.h
+++ b/gdb/gdbsupport/common-utils.h
@@ -43,6 +43,8 @@
 #endif
 #endif
 
+#include "gdb_string_view.h"
+
 /* xmalloc(), xrealloc() and xcalloc() have already been declared in
    "libiberty.h". */
 
@@ -118,6 +120,16 @@
   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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [review v3] Add a string_view version of startswith
  2019-10-16 12:39 [review] Add a string_view version of startswith Christian Biesinger (Code Review)
  2019-10-22 19:12 ` [review v2] " Christian Biesinger (Code Review)
  2019-10-22 22:14 ` [review v3] " Christian Biesinger (Code Review)
@ 2019-10-25 17:35 ` Tom Tromey (Code Review)
  2019-10-26 23:11 ` Tom Tromey (Code Review)
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey (Code Review) @ 2019-10-25 17:35 UTC (permalink / raw)
  To: Christian Biesinger, gdb-patches

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.


-- 
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: Fri, 25 Oct 2019 17:35:20 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [review v3] Add a string_view version of startswith
  2019-10-16 12:39 [review] Add a string_view version of startswith Christian Biesinger (Code Review)
                   ` (2 preceding siblings ...)
  2019-10-25 17:35 ` Tom Tromey (Code Review)
@ 2019-10-26 23:11 ` Tom Tromey (Code Review)
  2019-10-27  1:46   ` Simon Marchi
  2019-10-27  1:46 ` Simon Marchi (2) (Code Review)
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 14+ messages in thread
From: Tom Tromey (Code Review) @ 2019-10-26 23:11 UTC (permalink / raw)
  To: Christian Biesinger, gdb-patches

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?


-- 
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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [review v3] Add a string_view version of startswith
  2019-10-26 23:11 ` Tom Tromey (Code Review)
@ 2019-10-27  1:46   ` Simon Marchi
  0 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2019-10-27  1:46 UTC (permalink / raw)
  To: gnutoolchain-gerrit, Christian Biesinger, gdb-patches

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
> 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [review v3] Add a string_view version of startswith
  2019-10-16 12:39 [review] Add a string_view version of startswith Christian Biesinger (Code Review)
                   ` (3 preceding siblings ...)
  2019-10-26 23:11 ` Tom Tromey (Code Review)
@ 2019-10-27  1:46 ` Simon Marchi (2) (Code Review)
  2019-10-27  1:49 ` Simon Marchi (Code Review)
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi (2) (Code Review) @ 2019-10-27  1:46 UTC (permalink / raw)
  To: Christian Biesinger, gdb-patches; +Cc: Tom Tromey

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.


-- 
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: Sun, 27 Oct 2019 01:46:17 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [review v3] Add a string_view version of startswith
  2019-10-16 12:39 [review] Add a string_view version of startswith Christian Biesinger (Code Review)
                   ` (4 preceding siblings ...)
  2019-10-27  1:46 ` Simon Marchi (2) (Code Review)
@ 2019-10-27  1:49 ` Simon Marchi (Code Review)
  2019-10-27 18:23 ` Christian Biesinger (Code Review)
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi (Code Review) @ 2019-10-27  1:49 UTC (permalink / raw)
  To: Christian Biesinger, gdb-patches; +Cc: Tom Tromey

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.


-- 
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-CC: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-Comment-Date: Sun, 27 Oct 2019 01:48:32 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [review v3] Add a string_view version of startswith
  2019-10-16 12:39 [review] Add a string_view version of startswith Christian Biesinger (Code Review)
                   ` (5 preceding siblings ...)
  2019-10-27  1:49 ` Simon Marchi (Code Review)
@ 2019-10-27 18:23 ` Christian Biesinger (Code Review)
  2019-10-27 21:44 ` [review v4] " Tom Tromey (Code Review)
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Christian Biesinger (Code Review) @ 2019-10-27 18:23 UTC (permalink / raw)
  To: Christian Biesinger, gdb-patches; +Cc: Simon Marchi, Tom Tromey

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.


-- 
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-CC: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-Comment-Date: Sun, 27 Oct 2019 18:22:58 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [review v4] Add a string_view version of startswith
  2019-10-16 12:39 [review] Add a string_view version of startswith Christian Biesinger (Code Review)
                   ` (6 preceding siblings ...)
  2019-10-27 18:23 ` Christian Biesinger (Code Review)
@ 2019-10-27 21:44 ` Tom Tromey (Code Review)
  2019-10-27 22:10 ` Simon Marchi (Code Review)
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey (Code Review) @ 2019-10-27 21:44 UTC (permalink / raw)
  To: Christian Biesinger, gdb-patches; +Cc: Simon Marchi

The original change was created by Christian Biesinger.

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, 12 insertions(+), 0 deletions(-)



diff --git a/gdb/gdbsupport/common-utils.h b/gdb/gdbsupport/common-utils.h
index e96fc21..23bf354 100644
--- a/gdb/gdbsupport/common-utils.h
+++ b/gdb/gdbsupport/common-utils.h
@@ -43,6 +43,8 @@
 #endif
 #endif
 
+#include "gdb_string_view.h"
+
 /* xmalloc(), xrealloc() and xcalloc() have already been declared in
    "libiberty.h". */
 
@@ -118,6 +120,16 @@
   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

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I5389855de2fd70e7065a789a79374b0693651b71
Gerrit-Change-Number: 126
Gerrit-PatchSet: 4
Gerrit-Owner: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-MessageType: newpatchset


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [review v4] Add a string_view version of startswith
  2019-10-16 12:39 [review] Add a string_view version of startswith Christian Biesinger (Code Review)
                   ` (7 preceding siblings ...)
  2019-10-27 21:44 ` [review v4] " Tom Tromey (Code Review)
@ 2019-10-27 22:10 ` Simon Marchi (Code Review)
  2019-10-28 17:20 ` Christian Biesinger (Code Review)
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi (Code Review) @ 2019-10-27 22:10 UTC (permalink / raw)
  To: Christian Biesinger, Tom Tromey, gdb-patches

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.


-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I5389855de2fd70e7065a789a79374b0693651b71
Gerrit-Change-Number: 126
Gerrit-PatchSet: 4
Gerrit-Owner: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-Comment-Date: Sun, 27 Oct 2019 22:10:42 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [review v4] Add a string_view version of startswith
  2019-10-16 12:39 [review] Add a string_view version of startswith Christian Biesinger (Code Review)
                   ` (8 preceding siblings ...)
  2019-10-27 22:10 ` Simon Marchi (Code Review)
@ 2019-10-28 17:20 ` Christian Biesinger (Code Review)
  2019-10-28 17:22 ` [pushed] " Sourceware to Gerrit sync (Code Review)
  2019-10-28 17:22 ` Sourceware to Gerrit sync (Code Review)
  11 siblings, 0 replies; 14+ messages in thread
From: Christian Biesinger (Code Review) @ 2019-10-28 17:20 UTC (permalink / raw)
  To: Christian Biesinger, Tom Tromey, gdb-patches; +Cc: Simon Marchi

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.


-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I5389855de2fd70e7065a789a79374b0693651b71
Gerrit-Change-Number: 126
Gerrit-PatchSet: 4
Gerrit-Owner: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-Comment-Date: Mon, 28 Oct 2019 17:20:47 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [pushed] Add a string_view version of startswith
  2019-10-16 12:39 [review] Add a string_view version of startswith Christian Biesinger (Code Review)
                   ` (10 preceding siblings ...)
  2019-10-28 17:22 ` [pushed] " Sourceware to Gerrit sync (Code Review)
@ 2019-10-28 17:22 ` Sourceware to Gerrit sync (Code Review)
  11 siblings, 0 replies; 14+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-10-28 17:22 UTC (permalink / raw)
  To: Christian Biesinger, gdb-patches; +Cc: Simon Marchi, Tom Tromey

Sourceware to Gerrit sync has submitted this change.

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
https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/125

gdb/ChangeLog:

2019-10-28  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/ChangeLog
M gdb/gdbsupport/common-utils.h
2 files changed, 17 insertions(+), 0 deletions(-)


diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index edf7c34..7059623 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-10-28  Christian Biesinger  <cbiesinger@google.com>
+
+	* gdbsupport/common-utils.h (startswith): Add an overloaded version
+	that takes gdb::string_view arguments.
+
 2019-10-26  Tom de Vries  <tdevries@suse.de>
 
 	* aarch64-linux-tdep.c: Fix typos in comments.
diff --git a/gdb/gdbsupport/common-utils.h b/gdb/gdbsupport/common-utils.h
index e96fc21..23bf354 100644
--- a/gdb/gdbsupport/common-utils.h
+++ b/gdb/gdbsupport/common-utils.h
@@ -43,6 +43,8 @@
 #endif
 #endif
 
+#include "gdb_string_view.h"
+
 /* xmalloc(), xrealloc() and xcalloc() have already been declared in
    "libiberty.h". */
 
@@ -118,6 +120,16 @@
   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

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I5389855de2fd70e7065a789a79374b0693651b71
Gerrit-Change-Number: 126
Gerrit-PatchSet: 5
Gerrit-Owner: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-MessageType: merged


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [pushed] Add a string_view version of startswith
  2019-10-16 12:39 [review] Add a string_view version of startswith Christian Biesinger (Code Review)
                   ` (9 preceding siblings ...)
  2019-10-28 17:20 ` Christian Biesinger (Code Review)
@ 2019-10-28 17:22 ` Sourceware to Gerrit sync (Code Review)
  2019-10-28 17:22 ` Sourceware to Gerrit sync (Code Review)
  11 siblings, 0 replies; 14+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-10-28 17:22 UTC (permalink / raw)
  To: Christian Biesinger, Tom Tromey, gdb-patches; +Cc: Simon Marchi

The original change was created by Christian Biesinger.

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
https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/125

gdb/ChangeLog:

2019-10-28  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/ChangeLog
M gdb/gdbsupport/common-utils.h
2 files changed, 17 insertions(+), 0 deletions(-)



diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index edf7c34..7059623 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-10-28  Christian Biesinger  <cbiesinger@google.com>
+
+	* gdbsupport/common-utils.h (startswith): Add an overloaded version
+	that takes gdb::string_view arguments.
+
 2019-10-26  Tom de Vries  <tdevries@suse.de>
 
 	* aarch64-linux-tdep.c: Fix typos in comments.
diff --git a/gdb/gdbsupport/common-utils.h b/gdb/gdbsupport/common-utils.h
index e96fc21..23bf354 100644
--- a/gdb/gdbsupport/common-utils.h
+++ b/gdb/gdbsupport/common-utils.h
@@ -43,6 +43,8 @@
 #endif
 #endif
 
+#include "gdb_string_view.h"
+
 /* xmalloc(), xrealloc() and xcalloc() have already been declared in
    "libiberty.h". */
 
@@ -118,6 +120,16 @@
   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

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I5389855de2fd70e7065a789a79374b0693651b71
Gerrit-Change-Number: 126
Gerrit-PatchSet: 5
Gerrit-Owner: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-MessageType: newpatchset


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2019-10-28 17:22 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-16 12:39 [review] Add a string_view version of startswith Christian Biesinger (Code Review)
2019-10-22 19:12 ` [review v2] " Christian Biesinger (Code Review)
2019-10-22 22:14 ` [review v3] " Christian Biesinger (Code Review)
2019-10-25 17:35 ` Tom Tromey (Code Review)
2019-10-26 23:11 ` Tom Tromey (Code Review)
2019-10-27  1:46   ` Simon Marchi
2019-10-27  1:46 ` Simon Marchi (2) (Code Review)
2019-10-27  1:49 ` Simon Marchi (Code Review)
2019-10-27 18:23 ` Christian Biesinger (Code Review)
2019-10-27 21:44 ` [review v4] " Tom Tromey (Code Review)
2019-10-27 22:10 ` Simon Marchi (Code Review)
2019-10-28 17:20 ` Christian Biesinger (Code Review)
2019-10-28 17:22 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-10-28 17:22 ` Sourceware to Gerrit sync (Code Review)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox