From patchwork Fri Sep 23 19:53:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 15962 Received: (qmail 47411 invoked by alias); 23 Sep 2016 19:53:23 -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 47330 invoked by uid 89); 23 Sep 2016 19:53:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=H*r:4.86_1, ctype.h, H*F:U*tom, H*RU:cmgw2 X-HELO: gproxy4-pub.mail.unifiedlayer.com Received: from gproxy4-pub.mail.unifiedlayer.com (HELO gproxy4-pub.mail.unifiedlayer.com) (69.89.23.142) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Fri, 23 Sep 2016 19:53:12 +0000 Received: (qmail 32086 invoked by uid 0); 23 Sep 2016 19:53:10 -0000 Received: from unknown (HELO cmgw2) (10.0.90.83) by gproxy4.mail.unifiedlayer.com with SMTP; 23 Sep 2016 19:53:10 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id n7t51t00E2f2jeq017t83W; Fri, 23 Sep 2016 13:53:08 -0600 X-Authority-Analysis: v=2.1 cv=F4vEKMRN c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=GW1xBdLrtEIA:10 a=zstS-IiYAAAA:8 a=mDV3o1hIAAAA:8 a=gfHwfj_fGd5hS8QtnpoA:9 a=4G6NA9xxw8l3yy4pmD5M:22 a=_FVE-zBwftR9WsbkzFJk:22 Received: from 174-16-151-161.hlrn.qwest.net ([174.16.151.161]:55642 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1bnWWw-0005Ed-J8; Fri, 23 Sep 2016 13:53:06 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI v2 5/5] Use std::string rather than dyn-string Date: Fri, 23 Sep 2016 13:53:02 -0600 Message-Id: <1474660382-14294-6-git-send-email-tom@tromey.com> In-Reply-To: <1474660382-14294-1-git-send-email-tom@tromey.com> References: <1474660382-14294-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1bnWWw-0005Ed-J8 X-Source-Sender: 174-16-151-161.hlrn.qwest.net (bapiya.Home) [174.16.151.161]:55642 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This patch changes some code in cli-cmds.c to use std::string rather than dyn-string, removing some cleanups. Since this was the last use of dyn-string in gdb, this patch also removes make_cleanup_dyn_string_delete. 2016-09-23 Tom Tromey * utils.h (make_cleanup_dyn_string_delete): Remove declaration. * utils.c: Don't include dyn-string.h. (do_dyn_string_delete, make_cleanup_dyn_string_delete): Remove. * cli/cli-cmds.c: Include . Don't include dyn-string.h. (argv_to_string): Rename. Change return type to std::string. (alias_command): Use std::string. --- gdb/ChangeLog | 9 +++++++++ gdb/cli/cli-cmds.c | 41 ++++++++++++++++++----------------------- gdb/utils.c | 13 ------------- gdb/utils.h | 3 --- 4 files changed, 27 insertions(+), 39 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 161da29..fd13792 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2016-09-23 Tom Tromey + * utils.h (make_cleanup_dyn_string_delete): Remove declaration. + * utils.c: Don't include dyn-string.h. + (do_dyn_string_delete, make_cleanup_dyn_string_delete): Remove. + * cli/cli-cmds.c: Include . Don't include dyn-string.h. + (argv_to_string): Rename. Change return type to std::string. + (alias_command): Use std::string. + +2016-09-23 Tom Tromey + * objfiles.c: Include . (objfile_relocate): Use std::vector. diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 384a336..3d1a628 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -19,7 +19,6 @@ #include "defs.h" #include "arch-utils.h" -#include "dyn-string.h" #include "readline/readline.h" #include "readline/tilde.h" #include "completer.h" @@ -57,6 +56,7 @@ #include #include +#include /* Prototypes for local command functions */ @@ -1382,11 +1382,11 @@ apropos_command (char *searchstr, int from_tty) This does not take care of quoting elements in case they contain spaces on purpose. */ -static dyn_string_t -argv_to_dyn_string (char **argv, int n) +static std::string +argv_to_string (char **argv, int n) { int i; - dyn_string_t result = dyn_string_new (10); + std::string result; gdb_assert (argv != NULL); gdb_assert (n >= 0 && n <= countargv (argv)); @@ -1394,8 +1394,8 @@ argv_to_dyn_string (char **argv, int n) for (i = 0; i < n; ++i) { if (i > 0) - dyn_string_append_char (result, ' '); - dyn_string_append_cstr (result, argv[i]); + result += " "; + result += argv[i]; } return result; @@ -1437,9 +1437,9 @@ alias_command (char *args, int from_tty) { int i, alias_argc, command_argc; int abbrev_flag = 0; - char *args2, *equals, *alias, *command; + char *args2, *equals; + const char *alias, *command; char **alias_argv, **command_argv; - dyn_string_t alias_dyn_string, command_dyn_string; struct cleanup *cleanup; if (args == NULL || strchr (args, '=') == NULL) @@ -1491,16 +1491,14 @@ alias_command (char *args, int from_tty) /* COMMAND must exist. Reconstruct the command to remove any extraneous spaces, for better error messages. */ - command_dyn_string = argv_to_dyn_string (command_argv, command_argc); - make_cleanup_dyn_string_delete (command_dyn_string); - command = dyn_string_buf (command_dyn_string); + std::string command_string (argv_to_string (command_argv, command_argc)); + command = command_string.c_str (); if (! valid_command_p (command)) error (_("Invalid command to alias to: %s"), command); /* ALIAS must not exist. */ - alias_dyn_string = argv_to_dyn_string (alias_argv, alias_argc); - make_cleanup_dyn_string_delete (alias_dyn_string); - alias = dyn_string_buf (alias_dyn_string); + std::string alias_string (argv_to_string (alias_argv, alias_argc)); + alias = alias_string.c_str (); if (valid_command_p (alias)) error (_("Alias already exists: %s"), alias); @@ -1521,7 +1519,6 @@ alias_command (char *args, int from_tty) } else { - dyn_string_t alias_prefix_dyn_string, command_prefix_dyn_string; const char *alias_prefix, *command_prefix; struct cmd_list_element *c_alias, *c_command; @@ -1530,14 +1527,12 @@ alias_command (char *args, int from_tty) /* Create copies of ALIAS and COMMAND without the last word, and use that to verify the leading elements match. */ - alias_prefix_dyn_string = - argv_to_dyn_string (alias_argv, alias_argc - 1); - make_cleanup_dyn_string_delete (alias_prefix_dyn_string); - command_prefix_dyn_string = - argv_to_dyn_string (alias_argv, command_argc - 1); - make_cleanup_dyn_string_delete (command_prefix_dyn_string); - alias_prefix = dyn_string_buf (alias_prefix_dyn_string); - command_prefix = dyn_string_buf (command_prefix_dyn_string); + std::string alias_prefix_string (argv_to_string (alias_argv, + alias_argc - 1)); + std::string command_prefix_string (argv_to_string (alias_argv, + command_argc - 1)); + alias_prefix = alias_prefix_string.c_str (); + command_prefix = command_prefix_string.c_str (); c_command = lookup_cmd_1 (& command_prefix, cmdlist, NULL, 1); /* We've already tried to look up COMMAND. */ diff --git a/gdb/utils.c b/gdb/utils.c index 5bb0b67..9a83053 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -18,7 +18,6 @@ along with this program. If not, see . */ #include "defs.h" -#include "dyn-string.h" #include #include "gdb_wait.h" #include "event-top.h" @@ -155,18 +154,6 @@ make_cleanup_freeargv (char **arg) } static void -do_dyn_string_delete (void *arg) -{ - dyn_string_delete ((dyn_string_t) arg); -} - -struct cleanup * -make_cleanup_dyn_string_delete (dyn_string_t arg) -{ - return make_cleanup (do_dyn_string_delete, arg); -} - -static void do_bfd_close_cleanup (void *arg) { gdb_bfd_unref ((bfd *) arg); diff --git a/gdb/utils.h b/gdb/utils.h index bf77d7d..8635075 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -64,9 +64,6 @@ char **gdb_buildargv (const char *); extern struct cleanup *make_cleanup_freeargv (char **); -struct dyn_string; -extern struct cleanup *make_cleanup_dyn_string_delete (struct dyn_string *); - struct ui_file; extern struct cleanup *make_cleanup_ui_file_delete (struct ui_file *);