From patchwork Fri Nov 1 17:51:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35569 Received: (qmail 5335 invoked by alias); 1 Nov 2019 17:51:35 -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 5091 invoked by uid 89); 1 Nov 2019 17:51:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=HX-Languages-Length:4563, owned X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 01 Nov 2019 17:51:33 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id C8F45204A7; Fri, 1 Nov 2019 13:51:31 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [8.43.85.239]) by mx1.osci.io (Postfix) with ESMTP id 8F87020172 for ; Fri, 1 Nov 2019 13:51:30 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 5E46820AF6 for ; Fri, 1 Nov 2019 13:51:30 -0400 (EDT) X-Gerrit-PatchSet: 1 Date: Fri, 1 Nov 2019 13:51:30 -0400 From: "Tom Tromey (Code Review)" To: gdb-patches@sourceware.org Message-ID: Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange Subject: [review] Constify command_line_input X-Gerrit-Change-Id: I27e6c9477fd1005ab5b16e0d337e4c015b6e6248 X-Gerrit-Change-Number: 482 X-Gerrit-ChangeURL: X-Gerrit-Commit: 6d37e5dbd2135f4598c7bffec66cfb4d965c5473 References: Reply-To: tromey@sourceware.org, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-75-g9005159e5d Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/482 ...................................................................... Constify command_line_input This changes command_line_input to return a "const char *", which is appropriate because the memory is owned by command_line_input. Then it fixes up the users. I looked at making command_line_input transfer ownership to its caller instead, but this is complicated due to the way read_next_line is called, so I decided against it. Tested by rebuilding. gdb/ChangeLog 2019-11-01 Tom Tromey * top.c (read_command_file): Update. (command_line_input): Make return type const. * python/py-gdb-readline.c: Update. * linespec.c (decode_line_2): Update. * defs.h (command_line_input): Make return type const. * cli/cli-script.c (read_next_line): Make return type const. * ada-lang.c (get_selections): Update. Change-Id: I27e6c9477fd1005ab5b16e0d337e4c015b6e6248 --- M gdb/ChangeLog M gdb/ada-lang.c M gdb/cli/cli-script.c M gdb/defs.h M gdb/linespec.c M gdb/python/py-gdb-readline.c M gdb/top.c 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 34e332b..28c439c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2019-11-01 Tom Tromey + * top.c (read_command_file): Update. + (command_line_input): Make return type const. + * python/py-gdb-readline.c: Update. + * linespec.c (decode_line_2): Update. + * defs.h (command_line_input): Make return type const. + * cli/cli-script.c (read_next_line): Make return type const. + * ada-lang.c (get_selections): Update. + +2019-11-01 Tom Tromey + * utils.c (print_sys_errmsg): Simplify. 2019-11-01 Tom Tromey diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 7370490..9aae86e 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -3273,7 +3273,7 @@ get_selections (int *choices, int n_choices, int max_results, int is_all_choice, const char *annotation_suffix) { - char *args; + const char *args; const char *prompt; int n_chosen; int first_choice = is_all_choice ? 2 : 1; diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 8abd48c..316aca0 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -50,7 +50,7 @@ static void do_define_command (const char *comname, int from_tty, const counted_command_line *commands); -static char *read_next_line (void); +static const char *read_next_line (); /* Level of control structure when reading. */ static int control_level; @@ -890,8 +890,8 @@ recurse_read_control_structure whenever we need to read commands from stdin. */ -static char * -read_next_line (void) +static const char * +read_next_line () { struct ui *ui = current_ui; char *prompt_ptr, control_prompt[256]; diff --git a/gdb/defs.h b/gdb/defs.h index f12ba36..5d68be2 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -306,7 +306,7 @@ extern char *gdb_readline_wrapper (const char *); -extern char *command_line_input (const char *, const char *); +extern const char *command_line_input (const char *, const char *); extern void print_prompt (void); diff --git a/gdb/linespec.c b/gdb/linespec.c index fdbb670..9b7a8c9 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -1489,7 +1489,7 @@ std::vector *result, const char *select_mode) { - char *args; + const char *args; const char *prompt; int i; std::vector filters; diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c index ec4ff9e..dcf3b83 100644 --- a/gdb/python/py-gdb-readline.c +++ b/gdb/python/py-gdb-readline.c @@ -37,7 +37,8 @@ #endif { int n; - char *p = NULL, *q; + const char *p = NULL; + char *q; try { diff --git a/gdb/top.c b/gdb/top.c index a443159..08c7425 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -420,7 +420,7 @@ while (ui->instream != NULL && !feof (ui->instream)) { - char *command; + const char *command; /* Get a command-line. This calls the readline package. */ command = command_line_input (NULL, NULL); @@ -1210,7 +1210,7 @@ This routine either uses fancy command line editing or simple input as the user has requested. */ -char * +const char * command_line_input (const char *prompt_arg, const char *annotation_suffix) { static struct buffer cmd_line_buffer;