From patchwork Sat Sep 9 15:35:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22783 Received: (qmail 123950 invoked by alias); 9 Sep 2017 15:46:17 -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 123605 invoked by uid 89); 9 Sep 2017 15:46:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy7-pub.mail.unifiedlayer.com Received: from gproxy7-pub.mail.unifiedlayer.com (HELO gproxy7-pub.mail.unifiedlayer.com) (70.40.196.235) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 09 Sep 2017 15:46:15 +0000 Received: from CMOut01 (unknown [10.0.90.82]) by gproxy7.mail.unifiedlayer.com (Postfix) with ESMTP id 798E1216ECB for ; Sat, 9 Sep 2017 09:35:54 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id 7Tbr1w00K2f2jeq01TbuxS; Sat, 09 Sep 2017 09:35:54 -0600 X-Authority-Analysis: v=2.2 cv=K4VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=Z3hAZLgNvZLKqDUjbCcA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:59756 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dqhnT-00381I-AN; Sat, 09 Sep 2017 09:35:51 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 7/7] Use ui_out_emit_list and ui_out_emit_tuple with gdb::optional Date: Sat, 9 Sep 2017 09:35:40 -0600 Message-Id: <20170909153540.15008-8-tom@tromey.com> In-Reply-To: <20170909153540.15008-1-tom@tromey.com> References: <20170909153540.15008-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dqhnT-00381I-AN X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:59756 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes a few spots to use ui_out_emit_list and/or ui_out_emit_tuple with gdb::optional, to preserve existing behavior. This allows for the removal of a few more cleanups. ChangeLog 2017-09-09 Tom Tromey * mi/mi-cmd-var.c (mi_cmd_var_list_children): Use gdb::optional, ui_out_emit_list, ui_out_emit_tuple. (mi_cmd_var_update): Likewise. --- gdb/ChangeLog | 6 ++++++ gdb/mi/mi-cmd-var.c | 24 +++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index cc8e4e4..d1ed50f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2017-09-09 Tom Tromey + * mi/mi-cmd-var.c (mi_cmd_var_list_children): Use gdb::optional, + ui_out_emit_list, ui_out_emit_tuple. + (mi_cmd_var_update): Likewise. + +2017-09-09 Tom Tromey + * mi/mi-interp.c (mi_user_selected_context_changed): Use ui_out_redirect_pop. * guile/scm-ports.c (ioscm_with_output_to_port_worker): Use diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c index 191e770..8b22b2f 100644 --- a/gdb/mi/mi-cmd-var.c +++ b/gdb/mi/mi-cmd-var.c @@ -410,14 +410,15 @@ mi_cmd_var_list_children (const char *command, char **argv, int argc) if (from < to) { - struct cleanup *cleanup_children; + /* For historical reasons this might emit a list or a tuple, so + we construct one or the other. */ + gdb::optional tuple_emitter; + gdb::optional list_emitter; if (mi_version (uiout) == 1) - cleanup_children - = make_cleanup_ui_out_tuple_begin_end (uiout, "children"); + tuple_emitter.emplace (uiout, "children"); else - cleanup_children - = make_cleanup_ui_out_list_begin_end (uiout, "children"); + list_emitter.emplace (uiout, "children"); for (ix = from; ix < to && VEC_iterate (varobj_p, children, ix, child); ++ix) @@ -426,7 +427,6 @@ mi_cmd_var_list_children (const char *command, char **argv, int argc) print_varobj (child, print_values, 1 /* print expression */); } - do_cleanups (cleanup_children); } uiout->field_int ("has_more", varobj_has_more (var, to)); @@ -648,7 +648,6 @@ void mi_cmd_var_update (const char *command, char **argv, int argc) { struct ui_out *uiout = current_uiout; - struct cleanup *cleanup; char *name; enum print_values print_values; @@ -665,10 +664,15 @@ mi_cmd_var_update (const char *command, char **argv, int argc) else print_values = PRINT_NO_VALUES; + /* For historical reasons this might emit a list or a tuple, so we + construct one or the other. */ + gdb::optional tuple_emitter; + gdb::optional list_emitter; + if (mi_version (uiout) <= 1) - cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "changelist"); + tuple_emitter.emplace (uiout, "changelist"); else - cleanup = make_cleanup_ui_out_list_begin_end (uiout, "changelist"); + list_emitter.emplace (uiout, "changelist"); /* Check if the parameter is a "*", which means that we want to update all variables. */ @@ -693,8 +697,6 @@ mi_cmd_var_update (const char *command, char **argv, int argc) varobj_update_one (var, print_values, 1 /* explicit */); } - - do_cleanups (cleanup); } /* Helper for mi_cmd_var_update(). */