From patchwork Tue Apr 11 15:01:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 19956 Received: (qmail 109767 invoked by alias); 11 Apr 2017 15:01:40 -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 97659 invoked by uid 89); 11 Apr 2017 15:01:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:5395, 3637 X-HELO: gproxy6-pub.mail.unifiedlayer.com Received: from gproxy6-pub.mail.unifiedlayer.com (HELO gproxy6-pub.mail.unifiedlayer.com) (67.222.39.168) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Tue, 11 Apr 2017 15:01:25 +0000 Received: (qmail 25774 invoked by uid 0); 11 Apr 2017 15:01:25 -0000 Received: from unknown (HELO cmgw3) (10.0.90.84) by gproxy6.mail.unifiedlayer.com with SMTP; 11 Apr 2017 15:01:25 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id 731M1v01k2f2jeq0131Qgx; Tue, 11 Apr 2017 09:01:24 -0600 X-Authority-Analysis: v=2.2 cv=VKStp5HX c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=AzvcPWV-tVgA:10 a=zstS-IiYAAAA:8 a=g5xNc_ggDeNxAUL_mksA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-65-226.hlrn.qwest.net ([75.166.65.226]:50042 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1cxxIH-0007Ml-At; Tue, 11 Apr 2017 09:01:21 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 10/17] C++ify mi_parse Date: Tue, 11 Apr 2017 09:01:05 -0600 Message-Id: <20170411150112.23207-11-tom@tromey.com> In-Reply-To: <20170411150112.23207-1-tom@tromey.com> References: <20170411150112.23207-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1cxxIH-0007Ml-At X-Source-Sender: 75-166-65-226.hlrn.qwest.net (bapiya.Home) [75.166.65.226]:50042 X-Source-Auth: tom+tromey.com X-Email-Count: 11 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This changes mi_parse to return a unique_ptr, and to use "new"; then fixes up the users. This allows removing one cleanup. gdb/ChangeLog 2017-04-11 Tom Tromey * mi/mi-parse.h (struct mi_parse): Add constructor, destructor. (mi_parse): Update return type.. (mi_parse_free): Remove. * mi/mi-parse.c (mi_parse::~mi_parse): Rename from mi_parse_free. (mi_parse_cleanup): Remove. (mi_parse): Return a unique_ptr. Use new. * mi/mi-main.c (mi_execute_command): Update. --- gdb/ChangeLog | 10 ++++++++++ gdb/mi/mi-main.c | 8 +++----- gdb/mi/mi-parse.c | 40 +++++++++------------------------------- gdb/mi/mi-parse.h | 14 +++++++++----- 4 files changed, 31 insertions(+), 41 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f0c9a7b..a6febff 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2017-04-11 Tom Tromey + * mi/mi-parse.h (struct mi_parse): Add constructor, destructor. + (mi_parse): Update return type.. + (mi_parse_free): Remove. + * mi/mi-parse.c (mi_parse::~mi_parse): Rename from mi_parse_free. + (mi_parse_cleanup): Remove. + (mi_parse): Return a unique_ptr. Use new. + * mi/mi-main.c (mi_execute_command): Update. + +2017-04-11 Tom Tromey + * location.c (explicit_location_lex_one): Return a unique_xmalloc_ptr. (string_to_explicit_location): Update. Remove cleanups. diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 91fe104..d99c40e 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -2117,7 +2117,7 @@ void mi_execute_command (const char *cmd, int from_tty) { char *token; - struct mi_parse *command = NULL; + std::unique_ptr command; /* This is to handle EOF (^D). We just quit gdb. */ /* FIXME: we should call some API function here. */ @@ -2158,7 +2158,7 @@ mi_execute_command (const char *cmd, int from_tty) TRY { - captured_mi_execute_command (current_uiout, command); + captured_mi_execute_command (current_uiout, command.get ()); } CATCH (result, RETURN_MASK_ALL) { @@ -2186,7 +2186,7 @@ mi_execute_command (const char *cmd, int from_tty) && thread_count () != 0 /* If the command already reports the thread change, no need to do it again. */ - && !command_notifies_uscc_observer (command)) + && !command_notifies_uscc_observer (command.get ())) { struct mi_interp *mi = (struct mi_interp *) top_level_interpreter (); int report_change = 0; @@ -2211,8 +2211,6 @@ mi_execute_command (const char *cmd, int from_tty) } } - mi_parse_free (command); - do_cleanups (cleanup); } } diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c index 19cbb14..198d5c6 100644 --- a/gdb/mi/mi-parse.c +++ b/gdb/mi/mi-parse.c @@ -208,46 +208,28 @@ mi_parse_argv (const char *args, struct mi_parse *parse) } } -void -mi_parse_free (struct mi_parse *parse) +mi_parse::~mi_parse () { - if (parse == NULL) - return; - if (parse->command != NULL) - xfree (parse->command); - if (parse->token != NULL) - xfree (parse->token); - if (parse->args != NULL) - xfree (parse->args); - if (parse->argv != NULL) - freeargv (parse->argv); - xfree (parse); + xfree (command); + xfree (token); + xfree (args); + freeargv (argv); } -/* A cleanup that calls mi_parse_free. */ - -static void -mi_parse_cleanup (void *arg) -{ - mi_parse_free ((struct mi_parse *) arg); -} - -struct mi_parse * +std::unique_ptr mi_parse (const char *cmd, char **token) { const char *chp; - struct mi_parse *parse = XNEW (struct mi_parse); struct cleanup *cleanup; - memset (parse, 0, sizeof (*parse)); + std::unique_ptr parse (new struct mi_parse); + memset (parse.get (), 0, sizeof (struct mi_parse)); parse->all = 0; parse->thread_group = -1; parse->thread = -1; parse->frame = -1; parse->language = language_unknown; - cleanup = make_cleanup (mi_parse_cleanup, parse); - /* Before starting, skip leading white space. */ cmd = skip_spaces_const (cmd); @@ -265,8 +247,6 @@ mi_parse (const char *cmd, char **token) parse->command = xstrdup (chp); parse->op = CLI_COMMAND; - discard_cleanups (cleanup); - return parse; } @@ -383,7 +363,7 @@ mi_parse (const char *cmd, char **token) list. */ if (parse->cmd->argv_func != NULL) { - mi_parse_argv (chp, parse); + mi_parse_argv (chp, parse.get ()); if (parse->argv == NULL) error (_("Problem parsing arguments: %s %s"), parse->command, chp); } @@ -394,8 +374,6 @@ mi_parse (const char *cmd, char **token) if (parse->cmd->cli.cmd != NULL) parse->args = xstrdup (chp); - discard_cleanups (cleanup); - /* Fully parsed, flag as an MI command. */ parse->op = MI_COMMAND; return parse; diff --git a/gdb/mi/mi-parse.h b/gdb/mi/mi-parse.h index b11e5d3..a09e704 100644 --- a/gdb/mi/mi-parse.h +++ b/gdb/mi/mi-parse.h @@ -41,6 +41,13 @@ enum mi_command_type struct mi_parse { + mi_parse () = default; + + ~mi_parse (); + + mi_parse (const mi_parse &) = delete; + mi_parse &operator= (const mi_parse &) = delete; + enum mi_command_type op; char *command; char *token; @@ -67,11 +74,8 @@ struct mi_parse the TOKEN field of the resultant mi_parse object, to be freed by mi_parse_free. */ -extern struct mi_parse *mi_parse (const char *cmd, char **token); - -/* Free a command returned by mi_parse_command. */ - -extern void mi_parse_free (struct mi_parse *cmd); +extern std::unique_ptr mi_parse (const char *cmd, + char **token); /* Parse a string argument into a print_values value. */