diff mbox

[RFA,v2,08/17] Remove some cleanups in MI

Message ID 1476393012-29987-9-git-send-email-tom@tromey.com
State New
Headers show

Commit Message

Tom Tromey Oct. 13, 2016, 9:10 p.m. UTC
This patch removes a couple of cleanups from MI by using
gdb::unique_ptr.

2016-09-26  Tom Tromey  <tom@tromey.com>

	* mi/mi-main.c (mi_cmd_data_read_memory): Use gdb::unique_ptr.
	Remove some cleanups.
---
 gdb/ChangeLog    |  5 +++++
 gdb/mi/mi-main.c | 11 ++++-------
 2 files changed, 9 insertions(+), 7 deletions(-)

Comments

Pedro Alves Oct. 13, 2016, 10:38 p.m. UTC | #1
On 10/13/2016 10:10 PM, Tom Tromey wrote:
> This patch removes a couple of cleanups from MI by using
> gdb::unique_ptr.
> 
> 2016-09-26  Tom Tromey  <tom@tromey.com>
> 
> 	* mi/mi-main.c (mi_cmd_data_read_memory): Use gdb::unique_ptr.
> 	Remove some cleanups.

OK.

Thanks,
Pedro Alves
diff mbox

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 04e550a..7c072b5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@ 
+2016-09-26  Tom Tromey  <tom@tromey.com>
+
+	* mi/mi-main.c (mi_cmd_data_read_memory): Use gdb::unique_ptr.
+	Remove some cleanups.
+
 2016-10-10  Tom Tromey  <tom@tromey.com>
 
 	* tui/tui-interp.c (tui_on_normal_stop, tui_on_signal_received)
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index b80b4f2..067c9e3 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1413,7 +1413,6 @@  mi_cmd_data_read_memory (char *command, char **argv, int argc)
 {
   struct gdbarch *gdbarch = get_current_arch ();
   struct ui_out *uiout = current_uiout;
-  struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
   CORE_ADDR addr;
   long total_bytes, nr_cols, nr_rows;
   char word_format;
@@ -1421,7 +1420,6 @@  mi_cmd_data_read_memory (char *command, char **argv, int argc)
   long word_size;
   char word_asize;
   char aschar;
-  gdb_byte *mbuf;
   int nr_bytes;
   long offset = 0;
   int oind = 0;
@@ -1506,13 +1504,13 @@  mi_cmd_data_read_memory (char *command, char **argv, int argc)
 
   /* Create a buffer and read it in.  */
   total_bytes = word_size * nr_rows * nr_cols;
-  mbuf = XCNEWVEC (gdb_byte, total_bytes);
-  make_cleanup (xfree, mbuf);
+
+  gdb::unique_ptr<gdb_byte[]> mbuf (new gdb_byte[total_bytes]);
 
   /* Dispatch memory reads to the topmost target, not the flattened
      current_target.  */
   nr_bytes = target_read (current_target.beneath,
-			  TARGET_OBJECT_MEMORY, NULL, mbuf,
+			  TARGET_OBJECT_MEMORY, NULL, mbuf.get (),
 			  addr, total_bytes);
   if (nr_bytes <= 0)
     error (_("Unable to read memory."));
@@ -1566,7 +1564,7 @@  mi_cmd_data_read_memory (char *command, char **argv, int argc)
 	    else
 	      {
 		ui_file_rewind (stream);
-		print_scalar_formatted (mbuf + col_byte, word_type, &opts,
+		print_scalar_formatted (&mbuf[col_byte], word_type, &opts,
 					word_asize, stream);
 		ui_out_field_stream (uiout, NULL, stream);
 	      }
@@ -1593,7 +1591,6 @@  mi_cmd_data_read_memory (char *command, char **argv, int argc)
       }
     do_cleanups (cleanup_stream);
   }
-  do_cleanups (cleanups);
 }
 
 void