From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 92522 invoked by alias); 19 Oct 2017 21:00:43 -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 92024 invoked by uid 89); 19 Oct 2017 21:00:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=Hold, tracker, opportunity X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Oct 2017 21:00:35 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id v9JL0PIr002937 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 19 Oct 2017 17:00:30 -0400 Received: by simark.ca (Postfix, from userid 112) id A4E411E566; Thu, 19 Oct 2017 17:00:25 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 04D031E541; Thu, 19 Oct 2017 17:00:15 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 19 Oct 2017 21:00:00 -0000 From: Simon Marchi To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA 3/3] Remove cleanups from break-catch-syscall.c In-Reply-To: <20171018040645.7212-3-tom@tromey.com> References: <20171018040645.7212-1-tom@tromey.com> <20171018040645.7212-3-tom@tromey.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 19 Oct 2017 21:00:25 +0000 X-IsSubscribed: yes X-SW-Source: 2017-10/txt/msg00647.txt.bz2 On 2017-10-18 00:06, Tom Tromey wrote: > This removes the remaining cleanups from break-catch-syscall.c by > storing temporary strings in a vector. > > ChangeLog > 2017-10-17 Tom Tromey > > * break-catch-syscall.c (catch_syscall_completer): Use > std::string, gdb::unique_xmalloc_ptr. > --- > gdb/ChangeLog | 5 +++++ > gdb/break-catch-syscall.c | 35 ++++++++++++++++++----------------- > 2 files changed, 23 insertions(+), 17 deletions(-) > > diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c > index 01e761ce37..2bbfee0ac4 100644 > --- a/gdb/break-catch-syscall.c > +++ b/gdb/break-catch-syscall.c > @@ -560,9 +560,7 @@ catch_syscall_completer (struct cmd_list_element > *cmd, > const char *text, const char *word) > { > struct gdbarch *gdbarch = get_current_arch (); > - struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); > - const char **group_list = NULL; > - const char **syscall_list = NULL; > + gdb::unique_xmalloc_ptr group_list; > const char *prefix; > int i; > > @@ -575,34 +573,37 @@ catch_syscall_completer (struct cmd_list_element > *cmd, > if (startswith (prefix, "g:") || startswith (prefix, "group:")) > { > /* Perform completion inside 'group:' namespace only. */ > - group_list = get_syscall_group_names (gdbarch); > + group_list.reset (get_syscall_group_names (gdbarch)); > if (group_list != NULL) > - complete_on_enum (tracker, group_list, word, word); > + complete_on_enum (tracker, group_list.get (), word, word); > } > else > { > /* Complete with both, syscall names and groups. */ > - syscall_list = get_syscall_names (gdbarch); > - group_list = get_syscall_group_names (gdbarch); > + gdb::unique_xmalloc_ptr syscall_list > + (get_syscall_names (gdbarch)); > + group_list.reset (get_syscall_group_names (gdbarch)); > + > + const char **group_ptr = group_list.get (); > + > + /* Hold on to strings while we're using them. */ > + std::vector holders; > > /* Append "group:" prefix to syscall groups. */ > - for (i = 0; group_list[i] != NULL; i++) > + for (i = 0; group_ptr[i] != NULL; i++) > { > - char *prefixed_group = xstrprintf ("group:%s", group_list[i]); > + std::string prefixed_group = string_printf ("group:%s", > + group_ptr[i]); > > - group_list[i] = prefixed_group; > - make_cleanup (xfree, prefixed_group); > + group_ptr[i] = prefixed_group.c_str (); > + holders.push_back (prefixed_group); Maybe an opportunity to std::move? Alternatively: holders.emplace_back (string_printf ("group:%s", group_ptr[i])); group_ptr[i] = holders.back ().c_str (); LGTM in any case, as well as the two previous patches. Simon