public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Don't use struct buffer in top.c
@ 2023-02-24 19:05 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2023-02-24 19:05 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1293ecd838c82e86f6c81d4518f5c662f8eaa0b9

commit 1293ecd838c82e86f6c81d4518f5c662f8eaa0b9
Author: Tom Tromey <tom@tromey.com>
Date:   Fri Dec 16 12:53:20 2022 -0700

    Don't use struct buffer in top.c
    
    This changes top.c to use std::string rather than struct buffer.  Like
    the event-top.c change, this is not completely ideal in that it
    requires a copy of the string.

Diff:
---
 gdb/top.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/gdb/top.c b/gdb/top.c
index d71d8495622..22a24a9f0c3 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -50,7 +50,6 @@
 #include "maint.h"
 #include "filenames.h"
 #include "frame.h"
-#include "gdbsupport/buffer.h"
 #include "gdbsupport/gdb_select.h"
 #include "gdbsupport/scope-exit.h"
 #include "gdbarch.h"
@@ -879,18 +878,16 @@ save_command_line (const char *cmd)
 
    A NULL return means end of file.  */
 
-static char *
+static gdb::unique_xmalloc_ptr<char>
 gdb_readline_no_editing (const char *prompt)
 {
-  struct buffer line_buffer;
+  std::string line_buffer;
   struct ui *ui = current_ui;
   /* Read from stdin if we are executing a user defined command.  This
      is the right thing for prompt_for_continue, at least.  */
   FILE *stream = ui->instream != NULL ? ui->instream : stdin;
   int fd = fileno (stream);
 
-  buffer_init (&line_buffer);
-
   if (prompt != NULL)
     {
       /* Don't use a _filtered function here.  It causes the assumed
@@ -925,28 +922,25 @@ gdb_readline_no_editing (const char *prompt)
 
       if (c == EOF)
 	{
-	  if (line_buffer.used_size > 0)
+	  if (!line_buffer.empty ())
 	    /* The last line does not end with a newline.  Return it, and
 	       if we are called again fgetc will still return EOF and
 	       we'll return NULL then.  */
 	    break;
-	  xfree (buffer_finish (&line_buffer));
 	  return NULL;
 	}
 
       if (c == '\n')
 	{
-	  if (line_buffer.used_size > 0
-	      && line_buffer.buffer[line_buffer.used_size - 1] == '\r')
-	    line_buffer.used_size--;
+	  if (!line_buffer.empty () && line_buffer.back () == '\r')
+	    line_buffer.pop_back ();
 	  break;
 	}
 
-      buffer_grow_char (&line_buffer, c);
+      line_buffer += c;
     }
 
-  buffer_grow_char (&line_buffer, '\0');
-  return buffer_finish (&line_buffer);
+  return make_unique_xstrdup (line_buffer.c_str ());
 }
 
 /* Variables which control command line editing and history
@@ -1402,7 +1396,7 @@ command_line_input (std::string &cmd_line_buffer, const char *prompt_arg,
 	}
       else
 	{
-	  rl.reset (gdb_readline_no_editing (prompt));
+	  rl = gdb_readline_no_editing (prompt);
 	}
 
       cmd = handle_line_of_input (cmd_line_buffer, rl.get (),

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-24 19:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-24 19:05 [binutils-gdb] Don't use struct buffer in top.c Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).