From patchwork Tue Sep 27 04:08:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 16055 Received: (qmail 95715 invoked by alias); 27 Sep 2016 04:47:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 95660 invoked by uid 89); 27 Sep 2016 04:47:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=H*r:4.86_1, H*F:U*tom, SCM, xfree X-HELO: gproxy1.mail.unifiedlayer.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO gproxy1.mail.unifiedlayer.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 Sep 2016 04:47:45 +0000 Received: from cmgw4 (cmgw5 [10.0.90.85]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 1B109175F95 for ; Mon, 26 Sep 2016 22:47:44 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id oUnh1t0032f2jeq01UnksX; Mon, 26 Sep 2016 22:47:44 -0600 X-Authority-Analysis: v=2.1 cv=Hq7lRSjS c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=GW1xBdLrtEIA:10 a=zstS-IiYAAAA:8 a=Lk92X8vGQ9RV5ww24qgA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 71-218-192-86.hlrn.qwest.net ([71.218.192.86]:56110 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1bojhN-0006Nj-Lo; Mon, 26 Sep 2016 22:08:53 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 03/22] Use scoped_restore for ui_file Date: Mon, 26 Sep 2016 22:08:31 -0600 Message-Id: <1474949330-4307-4-git-send-email-tom@tromey.com> In-Reply-To: <1474949330-4307-1-git-send-email-tom@tromey.com> References: <1474949330-4307-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1bojhN-0006Nj-Lo X-Source-Sender: 71-218-192-86.hlrn.qwest.net (bapiya.Home) [71.218.192.86]:56110 X-Source-Auth: tom+tromey.com X-Email-Count: 23 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This replaces all the uses of make_cleanup_restore_ui_file with scoped_restore. 2016-09-26 Tom Tromey * 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 + * 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 + * 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 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); - if (ui_out_redirect (current_uiout, port_file) < 0) warning (_("Current output protocol does not support redirection")); else diff --git a/gdb/top.c b/gdb/top.c index 84285b2..d782466 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -706,22 +706,17 @@ execute_command_to_string (char *p, int from_tty) str_file = mem_fileopen (); make_cleanup_ui_file_delete (str_file); - make_cleanup_restore_ui_file (&gdb_stdout); - make_cleanup_restore_ui_file (&gdb_stderr); - make_cleanup_restore_ui_file (&gdb_stdlog); - make_cleanup_restore_ui_file (&gdb_stdtarg); - make_cleanup_restore_ui_file (&gdb_stdtargerr); if (ui_out_redirect (current_uiout, str_file) < 0) warning (_("Current output protocol does not support redirection")); else make_cleanup_ui_out_redirect_pop (current_uiout); - gdb_stdout = str_file; - gdb_stderr = str_file; - gdb_stdlog = str_file; - gdb_stdtarg = str_file; - gdb_stdtargerr = str_file; + scoped_restore save_stdout (&gdb_stdout, str_file); + scoped_restore save_stderr (&gdb_stderr, str_file); + scoped_restore save_stdlog (&gdb_stdlog, str_file); + scoped_restore save_stdtarg (&gdb_stdtarg, str_file); + scoped_restore save_stdtargerr (&gdb_stdtargerr, str_file); execute_command (p, from_tty); diff --git a/gdb/utils.c b/gdb/utils.c index 9a83053..5fb4b28 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -319,35 +319,6 @@ make_cleanup_htab_delete (htab_t htab) return make_cleanup (do_htab_delete_cleanup, htab); } -struct restore_ui_file_closure -{ - struct ui_file **variable; - struct ui_file *value; -}; - -static void -do_restore_ui_file (void *p) -{ - struct restore_ui_file_closure *closure - = (struct restore_ui_file_closure *) p; - - *(closure->variable) = closure->value; -} - -/* Remember the current value of *VARIABLE and make it restored when - the cleanup is run. */ - -struct cleanup * -make_cleanup_restore_ui_file (struct ui_file **variable) -{ - struct restore_ui_file_closure *c = XNEW (struct restore_ui_file_closure); - - c->variable = variable; - c->value = *variable; - - return make_cleanup_dtor (do_restore_ui_file, (void *) c, xfree); -} - /* Helper for make_cleanup_value_free_to_mark. */ static void diff --git a/gdb/utils.h b/gdb/utils.h index 63583ed..6179582 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -134,9 +134,6 @@ extern struct cleanup *make_cleanup_restore_uinteger (unsigned int *variable); struct target_ops; extern struct cleanup *make_cleanup_unpush_target (struct target_ops *ops); -extern struct cleanup * - make_cleanup_restore_ui_file (struct ui_file **variable); - extern struct cleanup *make_cleanup_value_free_to_mark (struct value *); extern struct cleanup *make_cleanup_value_free (struct value *);