From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 124963 invoked by alias); 1 Feb 2017 23:24:00 -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 124941 invoked by uid 89); 1 Feb 2017 23:23:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=H*i:sk:5b7dfd6, H*f:sk:5b7dfd6, H*MI:sk:5b7dfd6, Hx-languages-length:3374 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 01 Feb 2017 23:23:57 +0000 Received: from svr-orw-mbx-03.mgc.mentorg.com ([147.34.90.203]) by relay1.mentorg.com with esmtp id 1cZ4Fn-0006Mb-Ok from Luis_Gustavo@mentor.com ; Wed, 01 Feb 2017 15:23:55 -0800 Received: from [172.30.10.1] (147.34.91.1) by svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Wed, 1 Feb 2017 15:23:52 -0800 Reply-To: Luis Machado Subject: Re: [PATCH v4 2/2] Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy References: <1485909045-30285-1-git-send-email-palves@redhat.com> <1485909045-30285-3-git-send-email-palves@redhat.com> <5b7dfd6c-483e-618b-0d25-7f5b12ad32de@redhat.com> To: Pedro Alves , From: Luis Machado Message-ID: <433551e3-d608-1e46-18ae-b779998ede0d@codesourcery.com> Date: Wed, 01 Feb 2017 23:24:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: <5b7dfd6c-483e-618b-0d25-7f5b12ad32de@redhat.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: svr-orw-mbx-04.mgc.mentorg.com (147.34.90.204) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) X-IsSubscribed: yes X-SW-Source: 2017-02/txt/msg00054.txt.bz2 On 02/01/2017 04:49 PM, Pedro Alves wrote: > On 02/01/2017 05:36 PM, Luis Machado wrote: > >>> +typedef std::unique_ptr stdio_file_up; >>> + >>> +/* Like stdio_file, but specifically for stderr. >>> + >>> + This exists because there is no real line-buffering on Windows, see >>> + >>> + so the stdout is either fully-buffered or non-buffered. We can't >>> + make stdout non-buffered, because of two concerns: >>> + >>> + 1. Non-buffering hurts performance. >>> + 2. Non-buffering may change GDB's behavior when it is interacting >>> + with a front-end, such as Emacs. >>> + >>> + We leave stdout as fully buffered, but flush it first when >>> + something is written to stderr. >>> + >>> + Note the the 'write_async_safe' method is not overwritten, because >> >> >> Extra "the". >> >> Did you mean overridden instead of overwritten? > > Right, fixed. > > The existing comment this is being moved from says "overwritten", > and I missed updating it. ("overwritten" made some sense > in current master, I guess, since to "override" a method > currently you "overwrite" a function pointer.) > >>> +class stderr_file : public stdio_file >>> +{ >>> +public: >>> + explicit stderr_file (FILE *stream); >>> >>> -/* Create/open a memory based file. Can be used as a scratch buffer >>> - for collecting output. */ >>> -extern struct ui_file *mem_fileopen (void); >>> + /* Flushes gdb_stdout before writing to the underlying stream. */ >>> + void write (const char *buf, long length_buf) override; >>> >> >> I noticed the above declaration and ... >> >>> + /* Flushes gdb_stdout before writing to the underlying stream. */ >>> + void puts (const char *linebuffer) override; >> >> ... the above declaration both have the same documentation. Do they >> accomplish the same? > > They both flush gdb_stdout before deferring to the stdio_file > (the superclass) for the actual writing/outputting. "puts" exists as > a separate method because for some ui_file types it's more efficient to > call some available puts-like function (e.g. tui_puts), than > having the puts method always always call the write method, which > requires a strlen call. > > Would this help? > > gdb/ui-file.h | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/gdb/ui-file.h b/gdb/ui-file.h > index fc70417..d64cdce 100644 > --- a/gdb/ui-file.h > +++ b/gdb/ui-file.h > @@ -58,6 +58,8 @@ public: > virtual void write_async_safe (const char *buf, long length_buf) > { gdb_assert_not_reached ("write_async_safe"); } > > + /* Some ui_files override this to provide a efficient implementation > + that avoids the strlen. */ > virtual void puts (const char *str) > { this->write (str, strlen (str)); } > > @@ -227,10 +229,9 @@ class stderr_file : public stdio_file > public: > explicit stderr_file (FILE *stream); > > - /* Flushes gdb_stdout before writing to the underlying stream. */ > + /* Override the output routines to flush gdb_stdout before deferring > + to stdio_file for the actual outputting. */ > void write (const char *buf, long length_buf) override; > - > - /* Flushes gdb_stdout before writing to the underlying stream. */ > void puts (const char *linebuffer) override; > }; > That looks better. Thanks.