From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id A1D0B3857C44; Mon, 28 Mar 2022 20:19:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1D0B3857C44 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] Use unique_ptr in CLI logging code X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 22f8b65e9bd75ac66d7874da8dc844dd3c42ce8b X-Git-Newrev: 8b1931b39443acab9d1f8272a8a81b261f7ef29b Message-Id: <20220328201939.A1D0B3857C44@sourceware.org> Date: Mon, 28 Mar 2022 20:19:39 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Mar 2022 20:19:39 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D8b1931b39443= acab9d1f8272a8a81b261f7ef29b commit 8b1931b39443acab9d1f8272a8a81b261f7ef29b Author: Tom Tromey Date: Fri Dec 31 11:34:59 2021 -0700 Use unique_ptr in CLI logging code =20 This changes the CLI logging code to avoid manual memory management (to the extent possible) by using unique_ptr in a couple of spots. This will come in handy in a later patch. Diff: --- gdb/cli/cli-interp.c | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c index b310ef2b050..d36715d1d8f 100644 --- a/gdb/cli/cli-interp.c +++ b/gdb/cli/cli-interp.c @@ -396,9 +396,9 @@ struct saved_output_files ui_file *log; ui_file *targ; ui_file *targerr; - ui_file *file_to_delete; + ui_file_up file_to_delete; }; -static saved_output_files saved_output; +static std::unique_ptr saved_output; =20 /* See cli-interp.h. */ =20 @@ -408,12 +408,12 @@ cli_interp_base::set_logging (ui_file_up logfile, boo= l logging_redirect, { if (logfile !=3D nullptr) { - saved_output.out =3D gdb_stdout; - saved_output.err =3D gdb_stderr; - saved_output.log =3D gdb_stdlog; - saved_output.targ =3D gdb_stdtarg; - saved_output.targerr =3D gdb_stdtargerr; - gdb_assert (saved_output.file_to_delete =3D=3D nullptr); + saved_output.reset (new saved_output_files); + saved_output->out =3D gdb_stdout; + saved_output->err =3D gdb_stderr; + saved_output->log =3D gdb_stdlog; + saved_output->targ =3D gdb_stdtarg; + saved_output->targerr =3D gdb_stdtargerr; =20 /* If something is not being redirected, then a tee containing both = the logfile and stdout. */ @@ -422,10 +422,10 @@ cli_interp_base::set_logging (ui_file_up logfile, boo= l logging_redirect, if (!logging_redirect || !debug_redirect) { tee =3D new tee_file (gdb_stdout, std::move (logfile)); - saved_output.file_to_delete =3D tee; + saved_output->file_to_delete.reset (tee); } else - saved_output.file_to_delete =3D logfile.release (); + saved_output->file_to_delete =3D std::move (logfile); =20 gdb_stdout =3D logging_redirect ? logfile_p : tee; gdb_stdlog =3D debug_redirect ? logfile_p : tee; @@ -435,22 +435,13 @@ cli_interp_base::set_logging (ui_file_up logfile, boo= l logging_redirect, } else { - /* Delete the correct file. If it's the tee then the logfile will a= lso - be deleted. */ - delete saved_output.file_to_delete; - - gdb_stdout =3D saved_output.out; - gdb_stderr =3D saved_output.err; - gdb_stdlog =3D saved_output.log; - gdb_stdtarg =3D saved_output.targ; - gdb_stdtargerr =3D saved_output.targerr; - - saved_output.out =3D nullptr; - saved_output.err =3D nullptr; - saved_output.log =3D nullptr; - saved_output.targ =3D nullptr; - saved_output.targerr =3D nullptr; - saved_output.file_to_delete =3D nullptr; + gdb_stdout =3D saved_output->out; + gdb_stderr =3D saved_output->err; + gdb_stdlog =3D saved_output->log; + gdb_stdtarg =3D saved_output->targ; + gdb_stdtargerr =3D saved_output->targerr; + + saved_output.reset (nullptr); } }