From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 134533851C34 for ; Thu, 25 Jun 2020 18:39:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 134533851C34 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [172.16.0.95] (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 0FC971E5F9; Thu, 25 Jun 2020 14:39:23 -0400 (EDT) Subject: Re: [PATCH] gdb: make inferior::terminal a unique ptr To: Pedro Alves , Luis Machado , Christian Biesinger , Simon Marchi Cc: gdb-patches References: <20200625155517.32173-1-simon.marchi@efficios.com> <5b6a39ca-b29e-262b-1f0c-04fbd21a0c31@palves.net> <7ae6c907-4507-e0c3-3a52-6416a8203987@linaro.org> <04581d9f-2d9b-304c-e223-657f312c4549@palves.net> From: Simon Marchi Message-ID: <139027e2-4991-cd04-cdcd-416ba5a48c05@simark.ca> Date: Thu, 25 Jun 2020 14:39:22 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <04581d9f-2d9b-304c-e223-657f312c4549@palves.net> Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Jun 2020 18:39:25 -0000 On 2020-06-25 2:09 p.m., Pedro Alves wrote: > On 6/25/20 6:59 PM, Luis Machado wrote: >> On 6/25/20 2:28 PM, Pedro Alves wrote: >>> On 6/25/20 6:18 PM, Christian Biesinger via Gdb-patches wrote: >>>> On Thu, Jun 25, 2020 at 10:55 AM Simon Marchi via Gdb-patches >>>> wrote: >>>>> -    current_inferior ()->terminal = xstrdup (terminal_name); >>>>> +    current_inferior ()->terminal.reset (xstrdup (terminal_name)); >>>> >>>> Perhaps it really should be a std::string? >>> >>> I think there's no good reason for that.  It's a string that doesn't >>> ever need to grow/shrink.  And then its use is to pass down to >>> a syscall that accepts C-style null-terminated strings: >> >> I tend to agree with Christian. I suppose one positive outcome is to make the code less cumbersome. It's not like xstrdup is great to read anyway. >> >> Are we worried about performance implications of passing std::string's around like this? > > It's more like -- why store a fat 32 bytes object in the inferior when > a pointer does just as well. There's no code that would benefit from > making this a string, like, there's no strlen call that that would avoid. > The code that wants to consume this wants a pointer. A method-based > interface like I pointed at in that github commit exposes a pointer. > So it would just be implementation detail. > > Thanks, > Pedro Alves > Heh, that's more noise than I expected for this patch :) I tend to agree with Pedro on this. I initially tried to replace it with a gdb::optional, then making get_inferior_io_terminal return a reference to that... in the end it required changing a bunch of code in a way that didn't really make it better. The intent of this patch is just to get rid of the manual free-ing, which is a concrete improvement. Simon