Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Christian Biesinger <cbiesinger@google.com>
Cc: gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Change some arguments to gdb::string_view instead of name+len
Date: Wed, 02 Oct 2019 14:45:00 -0000	[thread overview]
Message-ID: <b034f2ae-f36a-5652-9782-b3cdf71e9a39@redhat.com> (raw)
In-Reply-To: <CAPTJ0XFhQb2XZOf_rFHp1A0bF62uks3Ld4B14+LOwuoPS1q_jw@mail.gmail.com>

On 10/1/19 8:29 PM, Christian Biesinger wrote:
> On Tue, Oct 1, 2019 at 2:10 PM Pedro Alves <palves@redhat.com> wrote:

>> I wonder then, I assume that the caller up the stack should know whether
>> the string was originally null terminated?  I wonder about tweaking the
>> interface to pass that info down somehow.
> 
> Actually, let me come at this from a different direction...
> 
> I looked at all the callers. In every case, they either passed a
> nullterminated string or a substring of an existing string. In other
> words, accessing name[length] was always valid, even if the
> string_view wasn't nullterminated.
> 
> In light of that, how do you feel about just documenting that callers
> have to pass a string view where accessing [length] is guaranteed not
> to be an invalid memory access?

My feeling is that one of the points of vocabulary types like string_view is
that you replace documentation with rules or contracts enforced by, or
encoded in the types.  To me, it feels like a bit of a hack or design issue that
we switch to string_view while at the same time, find that we need to step
outside its contract.  A char * pointer is low level and as such forces
you into a "what exactly am I allowed to pass here?" mind state, while
a string_view has a contract that people should just be able to
assume.

OTOH, I don't feel that strongly about this case, there are
certainly bigger fish to fry!

So I guess I'll be happy with just documenting.  But
please don't take that as approval.  I'd rather defer to Tromey,
since he had started the review, and I haven't even looked at the
whole patch in detail.

Thanks,
Pedro Alves


  reply	other threads:[~2019-10-02 14:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-29  5:34 Christian Biesinger via gdb-patches
2019-09-30 14:28 ` Tom Tromey
2019-09-30 14:38   ` Pedro Alves
2019-09-30 16:23     ` Tom Tromey
2019-09-30 19:33       ` Christian Biesinger via gdb-patches
2019-09-30 19:33         ` [PATCH v2] " Christian Biesinger via gdb-patches
2019-09-30 19:46           ` [PATCH v3] " Christian Biesinger via gdb-patches
2019-09-30 20:02             ` [PATCH v4] " Christian Biesinger via gdb-patches
2019-10-01 17:18               ` Tom Tromey
2019-10-01 17:26                 ` Christian Biesinger via gdb-patches
2019-10-01 17:26                   ` [PATCH] " Christian Biesinger via gdb-patches
2019-10-01 17:33                   ` Christian Biesinger via gdb-patches
2019-10-01 18:23                     ` Pedro Alves
2019-10-01 18:27                       ` Christian Biesinger via gdb-patches
2019-10-01 18:31                         ` Christian Biesinger via gdb-patches
2019-10-01 19:10                         ` Pedro Alves
2019-10-01 19:30                           ` Christian Biesinger via gdb-patches
2019-10-02 14:45                             ` Pedro Alves [this message]
2019-10-02 18:44                               ` Christian Biesinger 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=b034f2ae-f36a-5652-9782-b3cdf71e9a39@redhat.com \
    --to=palves@redhat.com \
    --cc=cbiesinger@google.com \
    --cc=gdb-patches@sourceware.org \
    /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