From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id /ZM7DS8dqmHVfQAAWB0awg (envelope-from ) for ; Fri, 03 Dec 2021 08:35:43 -0500 Received: by simark.ca (Postfix, from userid 112) id 2BFD51F0CE; Fri, 3 Dec 2021 08:35:42 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 433F71ECEB for ; Fri, 3 Dec 2021 08:35:42 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B0E23385840B for ; Fri, 3 Dec 2021 13:35:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0E23385840B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1638538541; bh=nM509HAJRnYpYdUghURcjchAo/P2mYLwOkyG2JBLTbU=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=kSGTmLnJB3jIIxTvO50/QlGiO4YOFXMY9+I/jj+Q++4vWevSSszh0ywpNhO6cmDGl 3loqVbEwhBLMUhr80+bZS+tKCKwE3XvjqUicGc8pSydUoUWF8fCpHzg4hj7FpuF0H8 Vl2aDK07spBtqkyHsP/N0hQHgXnyaXEj+ousWXtY= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 027953858D28 for ; Fri, 3 Dec 2021 13:35:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 027953858D28 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 1B3DZDnU029632 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 3 Dec 2021 08:35:18 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 1B3DZDnU029632 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id B7BCC1ECEB; Fri, 3 Dec 2021 08:35:13 -0500 (EST) Message-ID: Date: Fri, 3 Dec 2021 08:35:13 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: [PATCH 1/2] gdb: return *this in target_waitstatus setters Content-Language: en-US To: Pedro Alves , gdb-patches@sourceware.org References: <20211202014002.796783-1-simon.marchi@polymtl.ca> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 3 Dec 2021 13:35:13 +0000 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: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Cc: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 2021-12-03 08:10, Pedro Alves wrote: > On 2021-12-02 01:40, Simon Marchi via Gdb-patches wrote: >> From: Simon Marchi >> >> While playing with some code creating target_waitstatus objects, I was >> mildly annoyed by the fact that we can't just return a new >> target_waitstatus object. We have to do: >> >> target_waitstatus ws; >> ws.set_exited (123); >> return ws; >> >> Make the setters return the "this" object as a reference, such that it's >> possible to do: >> >> return target_waitstatus ().set_exited (123); >> >> I initially thought of adding static creation functions, which you would >> use like: >> >> return target_waitstatus::make_exited (123); >> >> However, making the setters return a reference to the object achieves >> pretty much the same thing, with less new code. > > I think the static methods would be nicer (I'd maybe drop the "make_" to keep > it short), but I'm fine with this too, it doesn't seem mutually exclusive. I started with this idea to add static methods and remove the setters, making target_waitstatus essentially immutable, except through the assignment operator. So to change an existing target_waitstatus object, you would do use static method + assignment operator: lp->waitstatus = target_waitstatus::make_stopped (...); instead of today: lp->waitstatus.set_stopped (); But that would have needed a lot of unnecessary churn again, updating all existing calls (which I did when introducing the setters). And having two ways of setting a target_waitstatus seems redundant, I prefer if there's just one way. It makes the code more consistent, easier to grep for (you can grep for `set_exited`, for example), etc. So I went for the solution presented in this patch, but if someone wants to convert to static methods later, I will be fine with it. > Series LGTM. Thanks, pushed. Simon