Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Luis Machado <lgustavo@codesourcery.com>
To: Pedro Alves <palves@redhat.com>, <gdb-patches@sourceware.org>
Subject: Re: [PATCH v4 2/2] Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy
Date: Wed, 01 Feb 2017 23:24:00 -0000	[thread overview]
Message-ID: <433551e3-d608-1e46-18ae-b779998ede0d@codesourcery.com> (raw)
In-Reply-To: <5b7dfd6c-483e-618b-0d25-7f5b12ad32de@redhat.com>

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> stdio_file_up;
>>> +
>>> +/* Like stdio_file, but specifically for stderr.
>>> +
>>> +   This exists because there is no real line-buffering on Windows, see
>>> +   <http://msdn.microsoft.com/en-us/library/86cebhfs%28v=vs.71%29.aspx>
>>> +   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.


  reply	other threads:[~2017-02-01 23:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-01  0:30 [PATCH v4 0/2] Eliminate cleanups & make ui_file a C++ " Pedro Alves
2017-02-01  0:30 ` [PATCH v4 1/2] Add back gdb_pretty_print_insn Pedro Alves
2017-02-01 17:01   ` Luis Machado
2017-02-01 18:10   ` Simon Marchi
2017-02-01 18:26     ` Simon Marchi
2017-02-02  0:00       ` Pedro Alves
2017-02-01 20:02     ` Pedro Alves
2017-02-01 20:31       ` Pedro Alves
2017-02-01 23:50         ` Pedro Alves
2017-02-02  1:20           ` Simon Marchi
2017-02-02 11:37             ` [pushed] Reuse buffers across gdb_pretty_print_insn calls (Re: [PATCH v4 1/2] Add back gdb_pretty_print_insn) Pedro Alves
2017-02-01  0:31 ` [PATCH v4 2/2] Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy Pedro Alves
2017-02-01 17:37   ` Luis Machado
2017-02-01 22:49     ` Pedro Alves
2017-02-01 23:24       ` Luis Machado [this message]
2017-02-02  0:02         ` Pedro Alves
2017-02-27 19:43           ` Edjunior Barbosa Machado
2017-03-07 14:02             ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=433551e3-d608-1e46-18ae-b779998ede0d@codesourcery.com \
    --to=lgustavo@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox