From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31379 invoked by alias); 17 Jan 2017 13:49:24 -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 29912 invoked by uid 89); 17 Jan 2017 13:49:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL,BAYES_20,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=20gdbccodingstandards, 20GDBCCodingStandards, sk:20gdb-c, Internals 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; Tue, 17 Jan 2017 13:49:13 +0000 Received: from svr-orw-mbx-03.mgc.mentorg.com ([147.34.90.203]) by relay1.mentorg.com with esmtp id 1cTU8N-0001Dt-RK from Luis_Gustavo@mentor.com ; Tue, 17 Jan 2017 05:49:11 -0800 Received: from [172.30.8.199] (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; Tue, 17 Jan 2017 05:49:08 -0800 Subject: Re: [PATCH 1/6] New function null_stream References: <1484051178-16013-1-git-send-email-yao.qi@linaro.org> <1484560977-8693-1-git-send-email-yao.qi@linaro.org> <1484560977-8693-2-git-send-email-yao.qi@linaro.org> To: Yao Qi , Reply-To: Luis Machado From: Luis Machado Message-ID: Date: Tue, 17 Jan 2017 13:49:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <1484560977-8693-2-git-send-email-yao.qi@linaro.org> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) X-IsSubscribed: yes X-SW-Source: 2017-01/txt/msg00319.txt.bz2 On 01/16/2017 04:02 AM, Yao Qi wrote: > This patch adds a new function null_stream, which returns a null > stream. The null stream can be used in multiple places. It is > used in gdb_insn_length, and the following patches will use it too. > > gdb: > > 2017-01-13 Yao Qi > > * disasm.c (do_ui_file_delete): Delete. > (gdb_insn_length): Move code creating stream to ... > * utils.c (null_stream): ... here. New function. > * utils.h (null_stream): Declare. > --- > gdb/disasm.c | 17 +---------------- > gdb/utils.c | 13 +++++++++++++ > gdb/utils.h | 4 ++++ > 3 files changed, 18 insertions(+), 16 deletions(-) > > diff --git a/gdb/disasm.c b/gdb/disasm.c > index f419501..ae3a2f1 100644 > --- a/gdb/disasm.c > +++ b/gdb/disasm.c > @@ -838,28 +838,13 @@ gdb_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr, > return length; > } > > -static void > -do_ui_file_delete (void *arg) > -{ > - ui_file_delete ((struct ui_file *) arg); > -} > - > /* Return the length in bytes of the instruction at address MEMADDR in > debugged memory. */ > > int > gdb_insn_length (struct gdbarch *gdbarch, CORE_ADDR addr) > { > - static struct ui_file *null_stream = NULL; > - > - /* Dummy file descriptor for the disassembler. */ > - if (!null_stream) > - { > - null_stream = ui_file_new (); > - make_final_cleanup (do_ui_file_delete, null_stream); > - } > - > - return gdb_print_insn (gdbarch, addr, null_stream, NULL); > + return gdb_print_insn (gdbarch, addr, null_stream (), NULL); > } > > /* fprintf-function for gdb_buffered_insn_length. This function is a > diff --git a/gdb/utils.c b/gdb/utils.c > index f142ffe..7bad193 100644 > --- a/gdb/utils.c > +++ b/gdb/utils.c > @@ -199,6 +199,19 @@ make_cleanup_ui_file_delete (struct ui_file *arg) > return make_cleanup (do_ui_file_delete, arg); > } > > +struct ui_file * > +null_stream (void) > +{ > + static struct ui_file *stream = NULL; > + > + if (stream == NULL) > + { > + stream = ui_file_new (); > + make_final_cleanup (do_ui_file_delete, stream); > + } Since we're explicitly setting stream to NULL, we will always execute the conditional block, so it is not needed. Unless this is supposed to reuse a stream, but in that case the code would be incorrect. > + return stream; > +} > + > /* Helper function for make_cleanup_ui_out_redirect_pop. */ > > static void > diff --git a/gdb/utils.h b/gdb/utils.h > index c548a50..26e60af 100644 > --- a/gdb/utils.h > +++ b/gdb/utils.h > @@ -189,6 +189,10 @@ extern struct ui_file *gdb_stdtarg; > extern struct ui_file *gdb_stdtargerr; > extern struct ui_file *gdb_stdtargin; > > +/* Return a null stream. */ > + Spurious newline between comment and prototype. https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#Empty_line_between_subprogram_description_and_the_subprogram_implementation > +extern struct ui_file *null_stream (void); > + > /* Set the screen dimensions to WIDTH and HEIGHT. */ > > extern void set_screen_width_and_height (int width, int height); > Otherwise looks fine.