From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id E19D5385840F; Fri, 24 Feb 2023 19:05:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E19D5385840F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677265508; bh=nXUNlAwngm5Bvv2aOmx6q3DtqSuwYHLpZ8Q17b4FVBk=; h=From:To:Subject:Date:From; b=r+riA3s8vb0C/L0LtOcsUONmNLmsnWZOMnerDye0vnI0Ue78MhsOjWgebBTIvnXp+ 5aXVs7vRyuQ/bi1e9uEcR5MCVcI59DfR8YXcWd0NtYsXb8LPH7YcDobW2izEyLdww+ jAQTwdqSceKs5tBLtMtgiIK/sGquyDkdznmeYIjQ= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Don't use struct buffer in event-top.c X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 71a64d8ba873b5618e357e85d6536d6fdd466aa6 X-Git-Newrev: 356628ee2a1ac34e705697967105dfbbcd7fd033 Message-Id: <20230224190508.E19D5385840F@sourceware.org> Date: Fri, 24 Feb 2023 19:05:08 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D356628ee2a1a= c34e705697967105dfbbcd7fd033 commit 356628ee2a1ac34e705697967105dfbbcd7fd033 Author: Tom Tromey Date: Fri Dec 16 12:45:40 2022 -0700 Don't use struct buffer in event-top.c =20 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. Diff: --- 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 14984707df1..f0a3f0d418c 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" @@ -868,12 +867,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 =3D current_ui; =20 - buffer_init (&line_buffer); - FILE *stream =3D ui->instream !=3D nullptr ? ui->instream : ui->stdin_st= ream; gdb_assert (stream !=3D nullptr); =20 @@ -893,32 +889,28 @@ gdb_readline_no_editing_callback (gdb_client_data cli= ent_data) =20 if (c =3D=3D 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; } =20 if (c =3D=3D '\n') { - if (line_buffer.used_size > 0 - && line_buffer.buffer[line_buffer.used_size - 1] =3D=3D '\r') - line_buffer.used_size--; + if (!line_buffer.empty () && line_buffer.back () =3D=3D '\r') + line_buffer.pop_back (); break; } =20 - buffer_grow_char (&line_buffer, c); + line_buffer +=3D c; } =20 - buffer_grow_char (&line_buffer, '\0'); - result =3D buffer_finish (&line_buffer); - ui->input_handler (gdb::unique_xmalloc_ptr (result)); + ui->input_handler (make_unique_xstrdup (line_buffer.c_str ())); }