From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28954 invoked by alias); 2 Oct 2019 14:45:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 28945 invoked by uid 89); 2 Oct 2019 14:45:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS autolearn=ham version=3.3.1 spammy=contracts X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Oct 2019 14:45:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1570027542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dVYXwjjQxpN/fLzUgZUpU9TOkB1AOR3/iPEDbZIRetM=; b=Te0Ot36RZ/FSL2FrM3cc1cXfGxDF2NCEbCvWD8yK8FGyKrrjTqAqeAgMEdWvPmfL1VnoCQ yIFlGAofb3JLRBtB379rqb3RED9TKkON2vX4B+lHCp27EneAH8HZUL744LUCTiX+WytfMc 7n17frmeQI8mRdm+gkH08NoLNDBTlW0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-67-nmkkzOLfMAWelOXk1C-euA-1; Wed, 02 Oct 2019 10:45:39 -0400 Received: by mail-wr1-f72.google.com with SMTP id w8so7618493wrm.3 for ; Wed, 02 Oct 2019 07:45:38 -0700 (PDT) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:56ee:75ff:fe8d:232b? ([2001:8a0:f913:f700:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id x129sm9488031wmg.8.2019.10.02.07.45.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Oct 2019 07:45:36 -0700 (PDT) Subject: Re: [PATCH] Change some arguments to gdb::string_view instead of name+len To: Christian Biesinger References: <20191001173345.48753-1-cbiesinger@google.com> Cc: gdb-patches From: Pedro Alves Message-ID: Date: Wed, 02 Oct 2019 14:45:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2019-10/txt/msg00061.txt.bz2 On 10/1/19 8:29 PM, Christian Biesinger wrote: > On Tue, Oct 1, 2019 at 2:10 PM Pedro Alves 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. >=20 > Actually, let me come at this from a different direction... >=20 > 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. >=20 > 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