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 B50403858C62 for ; Mon, 28 Nov 2022 19:18:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B50403858C62 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [10.0.0.11] (unknown [217.28.27.60]) (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 59F311E0CB; Mon, 28 Nov 2022 14:18:29 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1669663109; bh=/0r2aUhsg5J1QV5NI5LH7CjuB5ucg/ZyTvE/+SDNXQQ=; h=Date:Subject:To:References:From:In-Reply-To:From; b=X2YtwpRF2M/7CI9vDtGEs8YNBxMGE7QzbhLkrmgcGlp3mCMKfRoxFE+yRQLqrxtAp iuzBBoLiulUHa29h9i/GrDrqNlONV4c7ACghyEnxJcOVsnlwBvBtKHDW3RzSoZGcVO gjBKP/szNtzl8GyYWYzDe6/F0N2SwlfZiA3tn2kw= Message-ID: Date: Mon, 28 Nov 2022 14:18:28 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH 2/3] Don't let tee_file own a stream Content-Language: en-US To: Tom Tromey , gdb-patches@sourceware.org References: <20221117182904.1291713-1-tromey@adacore.com> <20221117182904.1291713-3-tromey@adacore.com> From: Simon Marchi In-Reply-To: <20221117182904.1291713-3-tromey@adacore.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 11/17/22 13:29, Tom Tromey via Gdb-patches wrote: > Right now, tee_file owns the second stream it writes to. This is done > for the convenience of the users. In a subsequent patch, this will no > longer be convenient, so this patch moves the responsibility for > ownership to the users of tee_file. I think the idea makes sense, from a software design / decoupling point of view. > diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c > index af242208a0b..482166ea3a5 100644 > --- a/gdb/mi/mi-interp.c > +++ b/gdb/mi/mi-interp.c > @@ -1275,21 +1275,16 @@ mi_interp::set_logging (ui_file_up logfile, bool logging_redirect, > { > mi->saved_raw_stdout = mi->raw_stdout; > > - /* If something is being redirected, then grab logfile. */ > - ui_file *logfile_p = nullptr; > - if (logging_redirect || debug_redirect) > - { > - logfile_p = logfile.get (); > - mi->saved_raw_file_to_delete = logfile_p; > - } > + ui_file *logfile_p = logfile.get (); > + mi->saved_raw_file_to_delete = logfile.release (); > > /* If something is not being redirected, then a tee containing both the > logfile and stdout. */ > ui_file *tee = nullptr; > if (!logging_redirect || !debug_redirect) > { > - tee = new tee_file (mi->raw_stdout, std::move (logfile)); > - mi->saved_raw_file_to_delete = tee; > + tee = new tee_file (mi->raw_stdout, logfile_p); > + mi->saved_tee_to_delete = tee; > } > > mi->raw_stdout = logging_redirect ? logfile_p : tee; > @@ -1297,9 +1292,11 @@ mi_interp::set_logging (ui_file_up logfile, bool logging_redirect, > else > { > delete mi->saved_raw_file_to_delete; > + delete mi->saved_tee_to_delete; > mi->raw_stdout = mi->saved_raw_stdout; > mi->saved_raw_stdout = nullptr; > mi->saved_raw_file_to_delete = nullptr; > + mi->saved_tee_to_delete = nullptr; Should the two _to_delete ones be ui_file_ups? Otherwise, everything related to logging / redirection confuse me, so I can't really comment on the change itself. Simon