From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GWb0BTmwfGl6rx0AWB0awg (envelope-from ) for ; Fri, 30 Jan 2026 08:20:57 -0500 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=PLLCGBr/; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 13DFC1E0DD; Fri, 30 Jan 2026 08:20:57 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 8D54F1E08D for ; Fri, 30 Jan 2026 08:20:56 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 2F1614BA9000 for ; Fri, 30 Jan 2026 13:20:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F1614BA9000 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=PLLCGBr/ Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by sourceware.org (Postfix) with ESMTPS id 27F954BA2E2F for ; Fri, 30 Jan 2026 13:17:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 27F954BA2E2F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 27F954BA2E2F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769779043; cv=none; b=Do/oaKKMXobwW6O7B3oWabgdUqn/kKIHTNUbvWm/aHRc8hhSydcLIo3xh8tDxH7uBCZZbYAUIsdRgtsBTSWQK8gbZvDNm7KqwqAaUIhnoKeWhFXmUGaslpOXfIf6RcJXpaog+913Wfv1cnMqXbe5UjPkNA9wWdxOWjfRQuPHvdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769779043; c=relaxed/simple; bh=JGlRqdllCggb59ISeWAfDtP82H3UMWXsLFwH2AinnbM=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=RzpfExAOl9zMde8fnpOzHWnBiF054769YR6jWJv9RjsGeGr7tPGtod2KRr9V2zah7HuTto5XqSEbdPo8iDcu+1WJORBc6iqND/pZg42YC1uQ5OEmuCl8iQ0JXerOideewYporw1M5rRkwqdUQEn3qz9vDy8CRZl1cLRH7x0zJBM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27F954BA2E2F Received: from eig-obgw-6001b.ext.cloudfilter.net ([10.0.30.143]) by cmsmtp with ESMTPS id ldWevnFsKCxrGloNGvRQQs; Fri, 30 Jan 2026 13:17:22 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id loNFvIN4hcu11loNGvyrLj; Fri, 30 Jan 2026 13:17:22 +0000 X-Authority-Analysis: v=2.4 cv=bKYWIO+Z c=1 sm=1 tr=0 ts=697caf62 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=vUbySO9Y5rIA:10 a=ItBw4LHWJt0A:10 a=MVro_xmFbW9f-YABggIA:9 a=QEXdDO2ut3YA:10 a=DCx65vhANUyCzuf5D8fC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=uYckEITh6RcRqdq3vb5h0gtOiyYtdsCtJzMX3zSKX+E=; b=PLLCGBr/1CCAeYp0W1TCR+Hf/W C0094iUulkE+bnpJ3SPJ3dwoW10ewFQZP0Ex7ZoN1/eAbLM5aeVdldZM8mWHTc/N9w/hzxB+T9G1I ZNSeznEYaOdFFMTU56no/A3CT; Received: from 97-122-114-32.hlrn.qwest.net ([97.122.114.32]:33716 helo=[192.168.122.1]) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vloNF-00000001JjQ-2zVb; Fri, 30 Jan 2026 06:17:21 -0700 From: Tom Tromey Date: Fri, 30 Jan 2026 06:17:17 -0700 Subject: [PATCH v3 03/21] Turn wrapped_file into a template MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260130-pr-28948-logging-5-v3-3-3eec47ef3cba@tromey.com> References: <20260130-pr-28948-logging-5-v3-0-3eec47ef3cba@tromey.com> In-Reply-To: <20260130-pr-28948-logging-5-v3-0-3eec47ef3cba@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.114.32 X-Source-L: No X-Exim-ID: 1vloNF-00000001JjQ-2zVb X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-114-32.hlrn.qwest.net ([192.168.122.1]) [97.122.114.32]:33716 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfGcQ/z9UoKjtjEM2rU27nvMqyASqmzi4MGRPVneiVZEwhBV5ceQm74IoT96O4iYZCnURVnrmVnpZn6bShjEC9zrBfo2ALpTockCm87khzpq5Dh4VJ5zM ApnRXq+Qsg8uAtXZEKRL4FIVjDkWAAe8WD89efZOijzldcq+Ah7/T0tyiHTtIJcyZ72gJf8TMnVhQdEdUJzKmeiZhuYTi+UB/00= X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This turns wrapped_file into a template, specialized by the type of pointer it holds. This makes it cleaner to have it own the stream it points to. --- gdb/pager.h | 11 +++-------- gdb/tui/tui-io.c | 2 +- gdb/ui-file.h | 18 +++++++++--------- gdb/ui.c | 2 +- gdb/utils.c | 2 +- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/gdb/pager.h b/gdb/pager.h index 5d64ffcf16c..697134be805 100644 --- a/gdb/pager.h +++ b/gdb/pager.h @@ -23,21 +23,16 @@ /* A ui_file that implements output paging and unfiltered output. */ -class pager_file : public wrapped_file +class pager_file : public wrapped_file { public: /* Create a new pager_file. The new object takes ownership of STREAM. */ - explicit pager_file (ui_file *stream) - : wrapped_file (stream) + explicit pager_file (ui_file_up stream) + : wrapped_file (std::move (stream)) { } - ~pager_file () - { - delete m_stream; - } - DISABLE_COPY_AND_ASSIGN (pager_file); void write (const char *buf, long length_buf) override; diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index bf212da92d0..7abe4fa3e81 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -933,7 +933,7 @@ tui_initialize_io (void) #endif /* Create tui output streams. */ - tui_stdout = new pager_file (new tui_file (stdout, true)); + tui_stdout = new pager_file (std::make_unique (stdout, true)); tui_stderr = new tui_file (stderr, false); tui_stdlog = new timestamped_file (tui_stderr); tui_out = new cli_ui_out (tui_stdout, 0); diff --git a/gdb/ui-file.h b/gdb/ui-file.h index 22badec4abe..231c32deafc 100644 --- a/gdb/ui-file.h +++ b/gdb/ui-file.h @@ -416,8 +416,11 @@ class no_terminal_escape_file : public escape_buffering_file void do_write (const char *buf, long len) override; }; -/* A base class for ui_file types that wrap another ui_file. */ +/* A base class for ui_file types that wrap another ui_file. The + precise underlying ui_file type is a template parameter, so that + either owning or non-owning wrappers can be made. */ +template class wrapped_file : public ui_file { public: @@ -451,22 +454,19 @@ class wrapped_file : public ui_file protected: - /* Note that this class does not assume ownership of the stream. - However, a subclass may choose to, by adding a 'delete' to its - destructor. */ - explicit wrapped_file (ui_file *stream) - : m_stream (stream) + explicit wrapped_file (T stream) + : m_stream (std::move (stream)) { } /* The underlying stream. */ - ui_file *m_stream; + T m_stream; }; /* A ui_file that optionally puts a timestamp at the start of each line of output. */ -class timestamped_file : public wrapped_file +class timestamped_file : public wrapped_file { public: explicit timestamped_file (ui_file *stream) @@ -490,7 +490,7 @@ class timestamped_file : public wrapped_file Note that this only really handles ASCII output correctly. */ -class tab_expansion_file : public wrapped_file +class tab_expansion_file : public wrapped_file { public: diff --git a/gdb/ui.c b/gdb/ui.c index 6d29026117e..647e63d1bde 100644 --- a/gdb/ui.c +++ b/gdb/ui.c @@ -48,7 +48,7 @@ ui::ui (FILE *instream_, FILE *outstream_, FILE *errstream_) errstream (errstream_), input_fd (fileno (instream)), m_input_interactive_p (ISATTY (instream)), - m_gdb_stdout (new pager_file (new stdio_file (outstream))), + m_gdb_stdout (new pager_file (std::make_unique (outstream))), m_gdb_stdin (new stdio_file (instream)), m_gdb_stderr (new stderr_file (errstream)), m_gdb_stdlog (new timestamped_file (m_gdb_stderr)), diff --git a/gdb/utils.c b/gdb/utils.c index ceea8317dc5..ef2d0fa0c41 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1838,7 +1838,7 @@ static void test_pager () { string_file *strfile = new string_file (); - pager_file pager (strfile); + pager_file pager { ui_file_up (strfile) }; /* Make sure the pager is disabled. */ scoped_restore save_enabled -- 2.49.0