Constify command_line_input
authorTom Tromey <tromey@adacore.com>
Tue, 22 Oct 2019 19:32:39 +0000 (13:32 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 8 Nov 2019 13:59:36 +0000 (06:59 -0700)
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-08  Tom Tromey  <tromey@adacore.com>

* 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

gdb/ChangeLog
gdb/ada-lang.c
gdb/cli/cli-script.c
gdb/defs.h
gdb/linespec.c
gdb/python/py-gdb-readline.c
gdb/top.c

index f43d3a5aed8afd891620a681aba8f41dc6891dd9..f5c8a76c0feeb2bf2804a4b74844dcc2c27a831a 100644 (file)
@@ -1,3 +1,13 @@
+2019-11-08  Tom Tromey  <tromey@adacore.com>
+
+       * 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-06  Christian Biesinger  <cbiesinger@google.com>
 
        * linux-tdep.c (linux_info_proc): Use strtok_r instead of strtok.
index 0bddc9e8b0d422d6774e507e5cb9990dc514dbe1..2935df52a24b6d455672ea64d9235149e06fdf3e 100644 (file)
@@ -3273,7 +3273,7 @@ static int
 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;
index 8abd48c678ad6a4865137595c1c9b53b4234ac6c..316aca0f274772016a6c587a808e3e092e908448 100644 (file)
@@ -50,7 +50,7 @@ recurse_read_control_structure
 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 @@ user_args::insert_args (const char *line) const
    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];
index f12ba366ccf07fffcb1c01b4bee0b8a6b4f76a79..5d68be2a056aabb9b68b104b12a335b95304824b 100644 (file)
@@ -306,7 +306,7 @@ typedef void initialize_file_ftype (void);
 
 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);
 
index fdbb670ed79b116a52423cbed587cb4b77414844..9b7a8c9715b09d314c5a5f1a10310a2dad8980af 100644 (file)
@@ -1489,7 +1489,7 @@ decode_line_2 (struct linespec_state *self,
               std::vector<symtab_and_line> *result,
               const char *select_mode)
 {
-  char *args;
+  const char *args;
   const char *prompt;
   int i;
   std::vector<const char *> filters;
index ec4ff9e13c00ef2212dfd5e077af9ebbb8872788..dcf3b83430914b3fd3c63b9f38c2ddb2241bde73 100644 (file)
@@ -37,7 +37,8 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
 #endif
 {
   int n;
-  char *p = NULL, *q;
+  const char *p = NULL;
+  char *q;
 
   try
     {
index a443159e3e7f492909148168c05a275023e552c2..08c742548bcd6cf65bb05921523c74c81f39ddcc 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -420,7 +420,7 @@ read_command_file (FILE *stream)
 
   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 @@ gdb_safe_append_history (void)
    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;
This page took 0.039114 seconds and 4 git commands to generate.