public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA 03/22] Use scoped_restore for ui_file
Date: Sat, 01 Oct 2016 04:28:00 -0000	[thread overview]
Message-ID: <7417a71f254c7f42026408c5e143b374@simark.ca> (raw)
In-Reply-To: <1474949330-4307-4-git-send-email-tom@tromey.com>

On 2016-09-27 00:08, Tom Tromey wrote:
> This replaces all the uses of make_cleanup_restore_ui_file with
> scoped_restore.
> 
> 2016-09-26  Tom Tromey  <tom@tromey.com>
> 
> 	* utils.c (make_cleanup_restore_ui_file, do_restore_ui_file)
> 	(struct restore_ui_file_closure): Remove.
> 	* utils.h (make_cleanup_restore_ui_file): Don't declare.
> 	* guile/scm-ports.c (ioscm_with_output_to_port_worker): Use
> 	scoped_restore.
> 	* top.c (execute_command_to_string): Use scoped_restore.
> ---
>  gdb/ChangeLog         |  9 +++++++++
>  gdb/guile/scm-ports.c | 10 ++++------
>  gdb/top.c             | 15 +++++----------
>  gdb/utils.c           | 29 -----------------------------
>  gdb/utils.h           |  3 ---
>  5 files changed, 18 insertions(+), 48 deletions(-)
> 
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 104048f..da69ce8 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,5 +1,14 @@
>  2016-09-26  Tom Tromey  <tom@tromey.com>
> 
> +	* utils.c (make_cleanup_restore_ui_file, do_restore_ui_file)
> +	(struct restore_ui_file_closure): Remove.
> +	* utils.h (make_cleanup_restore_ui_file): Don't declare.
> +	* guile/scm-ports.c (ioscm_with_output_to_port_worker): Use
> +	scoped_restore.
> +	* top.c (execute_command_to_string): Use scoped_restore.
> +
> +2016-09-26  Tom Tromey  <tom@tromey.com>
> +
>  	* utils.h (class scoped_restore): New class.
>  	* top.c (execute_command_to_string): Use scoped_restore.
>  	* python/python.c (python_interactive_command): Use
> diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c
> index 5559475..96e4372 100644
> --- a/gdb/guile/scm-ports.c
> +++ b/gdb/guile/scm-ports.c
> @@ -524,15 +524,13 @@ ioscm_with_output_to_port_worker (SCM port, SCM
> thunk, enum oport oport,
> 
>    make_cleanup_ui_file_delete (port_file);
> 
> +  scoped_restore<ui_file *> save_file (oport == GDB_STDERR
> +				       ? &gdb_stderr : &gdb_stdout);
> +
>    if (oport == GDB_STDERR)
> -    {
> -      make_cleanup_restore_ui_file (&gdb_stderr);
> -      gdb_stderr = port_file;
> -    }
> +    gdb_stderr = port_file;
>    else
>      {
> -      make_cleanup_restore_ui_file (&gdb_stdout);
> -

I think that situations like this, where cleanups are created in an 
scope inner to the function scope, but ran at the end of the function 
scope, are quite frequent in gdb.  You obviously can't simply define the 
scoped_restore in the inner scope, as it wouldn't have the desired 
effect.  I think that it could be worked around using the general 
pattern:

   shared_ptr< scoped_restore<ui_file *> > save_file;

   if (...)
     {
       save_file = new scoped_restore<ui_file *>(&gdb_stderr, port_file)
     }
   else
     {
       save_file = new scoped_restore<ui_file *>(&gdb_stdout, port_file)
     }

We can't use std::shared_ptr, since it's only in c++11, but I think it's 
just a matter of time before we define our own version of it.

An alternative would be to have a default constructor for 
scoped_restore, that creates an inactive scoped_restore, and then assign 
it a variable to restore later with acquire(T* var)/acquire(T* var, T 
value) methods or something.  I am not sure which one is better.

To support some use cases where discard_cleanups is used, we might need 
a way to "release" the scoped_restore, which would essentially cancel 
it.  So if we have a "release" method, maybe having the symmetrical 
"acquire" would make sense.

What do you think?

Simon

  reply	other threads:[~2016-10-01  4:28 UTC|newest]

Thread overview: 123+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-27  4:49 [RFA 00/22] More C++-ification Tom Tromey
2016-09-27  4:41 ` [RFA 07/22] Change scoped_minimal_symbol_reader to store objfile Tom Tromey
2016-09-29  9:19   ` Trevor Saunders
2016-09-30 21:41     ` Tom Tromey
2016-09-27  4:41 ` [RFA 15/22] Use std::string in macho_symfile_read_all_oso Tom Tromey
2016-10-09 17:28   ` Pedro Alves
2016-10-10 22:40     ` Tom Tromey
2016-10-10 22:46       ` Pedro Alves
2016-09-27  4:42 ` [RFA 19/22] Convert tid_range_parser to class Tom Tromey
2016-09-30  1:41   ` Pedro Alves
2016-09-30 14:52     ` Tom Tromey
     [not found]       ` <926126cb-b3c5-340b-ac1c-5bc14ca41bf9@redhat.com>
2016-10-04 19:24         ` Pedro Alves
2016-10-04 23:09           ` Pedro Alves
2016-10-05  2:16             ` Trevor Saunders
2016-10-12  2:12             ` Tom Tromey
2016-10-13  1:06               ` Pedro Alves
2016-09-27  4:42 ` [RFA 16/22] Use std::vector in elf_read_minimal_symbols Tom Tromey
2016-10-09 17:30   ` Pedro Alves
2016-09-27  4:43 ` [RFA 20/22] Initial conversion of dwarf_expr_ctx Tom Tromey
2016-10-09 17:40   ` Pedro Alves
2016-09-27  4:45 ` [RFA 21/22] Convert DWARF expr functions to methods Tom Tromey
2016-10-09 19:18   ` Pedro Alves
2016-09-27  4:47 ` [RFA 05/22] Turn wchar iterator into a class Tom Tromey
2016-10-06  1:01   ` Pedro Alves
2016-09-27  4:47 ` [RFA 22/22] Convert dwarf_expr_context_funcs to methods Tom Tromey
2016-10-09 19:11   ` Pedro Alves
2016-10-10 18:31     ` Pedro Alves
2016-10-10 19:33       ` Pedro Alves
2016-09-27  4:47 ` [RFA 02/22] Use RAII to save and restore scalars Tom Tromey
2016-09-27 10:24   ` Trevor Saunders
2016-09-30  1:40     ` Pedro Alves
2016-09-30  9:22       ` Pedro Alves
2016-09-30 15:00       ` Tom Tromey
2016-09-30 23:50         ` Pedro Alves
2016-09-30 15:44       ` Tom Tromey
2016-09-30 23:51         ` Pedro Alves
2016-10-01  3:55           ` Tom Tromey
2016-10-01  4:23             ` Tom Tromey
2016-10-01 10:33               ` Pedro Alves
2016-10-02 17:11                 ` Tom Tromey
2016-10-05  0:06                   ` Pedro Alves
2016-10-12 22:36                     ` Tom Tromey
2016-09-27  4:47 ` [RFA 04/22] Use scoped_restore for current_ui Tom Tromey
2016-09-27  4:48 ` [RFA 08/22] Record minimal symbols directly in reader Tom Tromey
2016-10-01  4:29   ` Simon Marchi
2016-10-06  1:12     ` Pedro Alves
2016-09-27  4:48 ` [RFA 01/22] Change selttest.c to use use std::vector Tom Tromey
2016-09-27  8:50   ` Trevor Saunders
2016-09-27 16:44     ` Tom Tromey
2016-09-28 14:58       ` Trevor Saunders
2016-09-29  8:59         ` Tom Tromey
2016-10-06  0:18       ` Pedro Alves
2016-10-06  0:39       ` Pedro Alves
2016-09-30 14:43   ` Simon Marchi
2016-09-30 21:40     ` Tom Tromey
2016-10-06  0:45       ` Pedro Alves
2016-09-27  4:48 ` [RFA 03/22] Use scoped_restore for ui_file Tom Tromey
2016-10-01  4:28   ` Simon Marchi [this message]
2016-10-01  5:22     ` Tom Tromey
2016-10-01 11:47       ` Simon Marchi
2016-10-13 14:56         ` Tom Tromey
2016-09-27  4:48 ` [RFA 09/22] Remove make_cleanup_restore_current_ui Tom Tromey
2016-09-29 11:55   ` Trevor Saunders
2016-10-01  3:47     ` Tom Tromey
2016-10-01  4:29   ` Simon Marchi
2016-10-06  2:53     ` Tom Tromey
2016-10-06  1:24   ` Pedro Alves
2016-10-06  2:52     ` Tom Tromey
2016-10-09  4:31   ` Simon Marchi
2016-10-09 15:10     ` Tom Tromey
2016-10-09 19:20       ` Pedro Alves
2016-10-12 22:43         ` Tom Tromey
2016-10-13  1:28           ` Pedro Alves
2016-10-13  6:11             ` Eli Zaretskii
2016-10-13 10:16               ` Pedro Alves
2016-10-13 13:53                 ` Eli Zaretskii
2016-10-13 14:26                   ` Pedro Alves
2016-10-13 14:46                     ` Eli Zaretskii
2016-10-13 15:04                       ` Pedro Alves
2016-10-13 15:19                         ` Eli Zaretskii
2016-10-13 15:43                           ` Pedro Alves
2016-10-13 15:48                             ` Pedro Alves
2016-10-17 23:43                             ` Go C++11? (was: Re: [RFA 09/22] Remove make_cleanup_restore_current_ui) Pedro Alves
2016-10-18  6:14                               ` Eli Zaretskii
2016-10-19 18:02                               ` Go C++11? Luis Machado
2016-10-19 22:34                                 ` Pedro Alves
2016-10-13 15:27                       ` [RFA 09/22] Remove make_cleanup_restore_current_ui Pedro Alves
2016-10-13 14:26                 ` Trevor Saunders
2016-09-27  4:50 ` [RFA 17/22] Remove make_cleanup_restore_current_uiout Tom Tromey
2016-09-29 14:35   ` Trevor Saunders
2016-09-29 15:23     ` Tom Tromey
2016-09-29 17:55       ` Simon Marchi
2016-09-29 20:34         ` Tom Tromey
2016-09-30  2:45       ` Pedro Alves
2016-09-30 23:48         ` Tom Tromey
2016-09-30 23:52           ` Pedro Alves
2016-09-27  4:51 ` [RFA 18/22] Some cleanup removal in dwarf2loc.c Tom Tromey
2016-10-09 17:37   ` Pedro Alves
2016-09-27  4:51 ` [RFA 14/22] Replace two xmallocs with vector Tom Tromey
2016-10-09 17:20   ` Pedro Alves
2016-10-12 22:39     ` Tom Tromey
2016-10-13  1:17       ` Pedro Alves
2016-10-13  2:04         ` Tom Tromey
2016-10-13 15:15     ` Tom Tromey
2016-10-13 15:26       ` Trevor Saunders
2016-09-27  4:51 ` [RFA 13/22] Remove unnecessary cleanup from stabsread.c Tom Tromey
2016-09-30 16:19   ` Tom Tromey
2016-10-09 17:07   ` Pedro Alves
2016-09-27  4:51 ` [RFA 12/22] Remove unnecessary null_cleanup Tom Tromey
2016-10-09 17:06   ` Pedro Alves
2016-09-27  4:52 ` [RFA 10/22] Remove some cleanups in MI Tom Tromey
2016-10-06  1:42   ` Pedro Alves
2016-09-27  4:52 ` [RFA 06/22] Introduce scoped_minimal_symbol_reader Tom Tromey
2016-10-06  1:10   ` Pedro Alves
2016-10-06 15:37     ` Tom Tromey
2016-10-10 23:06     ` Tom Tromey
2016-10-10 23:26       ` Pedro Alves
2016-09-27  8:32 ` [RFA 11/22] Change command stats reporting to use class Tom Tromey
2016-10-09 17:01   ` Pedro Alves
2016-10-11 17:31     ` Tom Tromey
2016-10-08 13:57 ` [RFA 00/22] More C++-ification Simon Marchi
2016-10-08 16:42   ` Pedro Alves
2016-10-09  2:09   ` Tom Tromey

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=7417a71f254c7f42026408c5e143b374@simark.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).