diff options
author | Tom Tromey <tom@tromey.com> | 2017-04-07 15:34:02 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-04-12 11:16:18 -0600 |
commit | 4d89769a7b4e38e94a6e027281b36eff71fc8214 (patch) | |
tree | c99858aecfb6b30141f0c626556f8e89144038f9 /gdb/mi/mi-parse.c | |
parent | 4b217cc72b7ab04e2bea519f9fbd47d8952e08f5 (diff) | |
download | gdb-4d89769a7b4e38e94a6e027281b36eff71fc8214.zip gdb-4d89769a7b4e38e94a6e027281b36eff71fc8214.tar.gz gdb-4d89769a7b4e38e94a6e027281b36eff71fc8214.tar.bz2 |
C++ify mi_parse
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-12 Tom Tromey <tom@tromey.com>
* 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): New constructor.
(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.
Diffstat (limited to 'gdb/mi/mi-parse.c')
-rw-r--r-- | gdb/mi/mi-parse.c | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c index 19cbb14..fea85d5 100644 --- a/gdb/mi/mi-parse.c +++ b/gdb/mi/mi-parse.c @@ -208,45 +208,38 @@ mi_parse_argv (const char *args, struct mi_parse *parse) } } -void -mi_parse_free (struct mi_parse *parse) +mi_parse::mi_parse () + : op (MI_COMMAND), + command (NULL), + token (NULL), + cmd (NULL), + cmd_start (NULL), + args (NULL), + argv (NULL), + argc (0), + all (0), + thread_group (-1), + thread (-1), + frame (-1), + language (language_unknown) { - 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); } -/* A cleanup that calls mi_parse_free. */ - -static void -mi_parse_cleanup (void *arg) +mi_parse::~mi_parse () { - mi_parse_free ((struct mi_parse *) arg); + xfree (command); + xfree (token); + xfree (args); + freeargv (argv); } -struct mi_parse * +std::unique_ptr<struct mi_parse> 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)); - parse->all = 0; - parse->thread_group = -1; - parse->thread = -1; - parse->frame = -1; - parse->language = language_unknown; - - cleanup = make_cleanup (mi_parse_cleanup, parse); + std::unique_ptr<struct mi_parse> parse (new struct mi_parse); /* Before starting, skip leading white space. */ cmd = skip_spaces_const (cmd); @@ -265,8 +258,6 @@ mi_parse (const char *cmd, char **token) parse->command = xstrdup (chp); parse->op = CLI_COMMAND; - discard_cleanups (cleanup); - return parse; } @@ -383,7 +374,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 +385,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; |