public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 5/7] Don't use struct buffer in event-top.c
Date: Fri, 16 Dec 2022 16:50:15 -0700	[thread overview]
Message-ID: <20221216235017.3722833-6-tom@tromey.com> (raw)
In-Reply-To: <20221216235017.3722833-1-tom@tromey.com>

This changes event-top.c to use std::string rather than struct buffer.
This isn't completely ideal, in that it requires a copy of the string
to be made.
---
 gdb/event-top.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/gdb/event-top.c b/gdb/event-top.c
index fa86a89e4a1..73ac3e077eb 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -36,7 +36,6 @@
 #include "gdbcmd.h"		/* for dont_repeat() */
 #include "annotate.h"
 #include "maint.h"
-#include "gdbsupport/buffer.h"
 #include "ser-event.h"
 #include "gdbsupport/gdb_select.h"
 #include "gdbsupport/gdb-sigmask.h"
@@ -864,12 +863,9 @@ void
 gdb_readline_no_editing_callback (gdb_client_data client_data)
 {
   int c;
-  char *result;
-  struct buffer line_buffer;
+  std::string line_buffer;
   struct ui *ui = current_ui;
 
-  buffer_init (&line_buffer);
-
   FILE *stream = ui->instream != nullptr ? ui->instream : ui->stdin_stream;
   gdb_assert (stream != nullptr);
 
@@ -889,32 +885,28 @@ gdb_readline_no_editing_callback (gdb_client_data client_data)
 
       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));
 	  ui->input_handler (NULL);
 	  return;
 	}
 
       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');
-  result = buffer_finish (&line_buffer);
-  ui->input_handler (gdb::unique_xmalloc_ptr<char> (result));
+  ui->input_handler (make_unique_xstrdup (line_buffer.c_str ()));
 }
 \f
 
-- 
2.38.1


  parent reply	other threads:[~2022-12-16 23:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-16 23:50 [PATCH 0/7] Remove struct buffer Tom Tromey
2022-12-16 23:50 ` [PATCH 1/7] Remove struct buffer from tracefile-tfile.c Tom Tromey
2022-12-16 23:50 ` [PATCH 2/7] Don't use struct buffer in handle_qxfer_traceframe_info Tom Tromey
2022-12-16 23:50 ` [PATCH 3/7] Don't use struct buffer in handle_qxfer_btrace Tom Tromey
2022-12-16 23:50 ` [PATCH 4/7] Don't use struct buffer in handle_qxfer_threads Tom Tromey
2022-12-16 23:50 ` Tom Tromey [this message]
2022-12-16 23:50 ` [PATCH 6/7] Don't use struct buffer in top.c Tom Tromey
2022-12-16 23:50 ` [PATCH 7/7] Remove struct buffer Tom Tromey
2023-02-24 19:04 ` [PATCH 0/7] " Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221216235017.3722833-6-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).