This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Use std::vector for cli_ui_out_data::streams


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

commit b9b118c3bb29052ee76c6bf32b99962cda5113ba
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Wed Nov 30 21:46:08 2016 -0500

    Use std::vector for cli_ui_out_data::streams
    
    Use a standard vector instead of the home-made version.  I used a vector
    of plain pointers, because the cli_ui_out_data object doesn't own the
    streams objects (i.e. they shouldn't be deleted when the vector is
    deleted).
    
    gdb/ChangeLog:
    
    	* cli-out.h (cli_ui_out_data) <streams>: Change type to
    	std::vector.
    	* cli-out.c: Remove vec.h include.
    	(cli_uiout_dtor): Update.
    	(cli_field_fmt): Update.
    	(cli_spaces): Update.
    	(cli_text): Update.
    	(cli_message): Update.
    	(cli_flush): Update.
    	(cli_redirect): Update.
    	(out_field_fmt): Update.
    	(field_separator): Update.
    	(cli_out_data_ctor): Update.
    	(cli_out_new): Update.
    	(cli_out_set_stream): Update.

Diff:
---
 gdb/ChangeLog | 18 ++++++++++++++++++
 gdb/cli-out.c | 31 ++++++++++++++-----------------
 gdb/cli-out.h |  9 ++-------
 3 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e6c7bbd..e8d03bf 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,23 @@
 2016-11-30  Simon Marchi  <simon.marchi@polymtl.ca>
 
+	* cli-out.h (cli_ui_out_data) <streams>: Change type to
+	std::vector.
+	* cli-out.c: Remove vec.h include.
+	(cli_uiout_dtor): Update.
+	(cli_field_fmt): Update.
+	(cli_spaces): Update.
+	(cli_text): Update.
+	(cli_message): Update.
+	(cli_flush): Update.
+	(cli_redirect): Update.
+	(out_field_fmt): Update.
+	(field_separator): Update.
+	(cli_out_data_ctor): Update.
+	(cli_out_new): Update.
+	(cli_out_set_stream): Update.
+
+2016-11-30  Simon Marchi  <simon.marchi@polymtl.ca>
+
 	* mi/mi-out.c: Remove vec.h include.
 	(mi_ui_out_data) <streams>: Change type to std::vector.
 	(mi_field_string): Update.
diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index b98af4a..093b6e7 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -24,7 +24,6 @@
 #include "ui-out.h"
 #include "cli-out.h"
 #include "completer.h"
-#include "vec.h"
 #include "readline/readline.h"
 
 typedef struct cli_ui_out_data cli_out_data;
@@ -46,7 +45,6 @@ cli_uiout_dtor (struct ui_out *ui_out)
 {
   cli_out_data *data = (cli_out_data *) ui_out_data (ui_out);
 
-  VEC_free (ui_filep, data->streams);
   delete data;
 }
 
@@ -239,7 +237,7 @@ cli_field_fmt (struct ui_out *uiout, int fldno,
   if (data->suppress_output)
     return;
 
-  stream = VEC_last (ui_filep, data->streams);
+  stream = data->streams.back ();
   vfprintf_filtered (stream, format, args);
 
   if (align != ui_noalign)
@@ -255,7 +253,7 @@ cli_spaces (struct ui_out *uiout, int numspaces)
   if (data->suppress_output)
     return;
 
-  stream = VEC_last (ui_filep, data->streams);
+  stream = data->streams.back ();
   print_spaces_filtered (numspaces, stream);
 }
 
@@ -268,7 +266,7 @@ cli_text (struct ui_out *uiout, const char *string)
   if (data->suppress_output)
     return;
 
-  stream = VEC_last (ui_filep, data->streams);
+  stream = data->streams.back ();
   fputs_filtered (string, stream);
 }
 
@@ -280,7 +278,7 @@ cli_message (struct ui_out *uiout, const char *format, va_list args)
   if (data->suppress_output)
     return;
 
-  struct ui_file *stream = VEC_last (ui_filep, data->streams);
+  struct ui_file *stream = data->streams.back ();
   vfprintf_unfiltered (stream, format, args);
 }
 
@@ -298,7 +296,7 @@ static void
 cli_flush (struct ui_out *uiout)
 {
   cli_out_data *data = (cli_out_data *) ui_out_data (uiout);
-  struct ui_file *stream = VEC_last (ui_filep, data->streams);
+  struct ui_file *stream = data->streams.back ();
 
   gdb_flush (stream);
 }
@@ -313,9 +311,9 @@ cli_redirect (struct ui_out *uiout, struct ui_file *outstream)
   cli_out_data *data = (cli_out_data *) ui_out_data (uiout);
 
   if (outstream != NULL)
-    VEC_safe_push (ui_filep, data->streams, outstream);
+    data->streams.push_back (outstream);
   else
-    VEC_pop (ui_filep, data->streams);
+    data->streams.pop_back ();
 
   return 0;
 }
@@ -332,7 +330,7 @@ out_field_fmt (struct ui_out *uiout, int fldno,
 	       const char *format,...)
 {
   cli_out_data *data = (cli_out_data *) ui_out_data (uiout);
-  struct ui_file *stream = VEC_last (ui_filep, data->streams);
+  struct ui_file *stream = data->streams.back ();
   va_list args;
 
   va_start (args, format);
@@ -347,7 +345,7 @@ static void
 field_separator (void)
 {
   cli_out_data *data = (cli_out_data *) ui_out_data (current_uiout);
-  struct ui_file *stream = VEC_last (ui_filep, data->streams);
+  struct ui_file *stream = data->streams.back ();
 
   fputc_filtered (' ', stream);
 }
@@ -383,8 +381,7 @@ cli_out_data_ctor (cli_out_data *self, struct ui_file *stream)
 {
   gdb_assert (stream != NULL);
 
-  self->streams = NULL;
-  VEC_safe_push (ui_filep, self->streams, stream);
+  self->streams.push_back (stream);
 
   self->suppress_output = 0;
 }
@@ -406,13 +403,13 @@ cli_out_set_stream (struct ui_out *uiout, struct ui_file *stream)
 {
   cli_out_data *data = (cli_out_data *) ui_out_data (uiout);
   struct ui_file *old;
-  
-  old = VEC_pop (ui_filep, data->streams);
-  VEC_quick_push (ui_filep, data->streams, stream);
+
+  old = data->streams.back ();
+  data->streams.back () = stream;
 
   return old;
 }
-
+
 /* CLI interface to display tab-completion matches.  */
 
 /* CLI version of displayer.crlf.  */
diff --git a/gdb/cli-out.h b/gdb/cli-out.h
index 55d80a7..296b8c0 100644
--- a/gdb/cli-out.h
+++ b/gdb/cli-out.h
@@ -21,19 +21,14 @@
 #define CLI_OUT_H
 
 #include "ui-out.h"
-#include "vec.h"
-
-/* Used for cli_ui_out_data->streams.  */
-
-typedef struct ui_file *ui_filep;
-DEF_VEC_P (ui_filep);
+#include <vector>
 
 /* These are exported so that they can be extended by other `ui_out'
    implementations, like TUI's.  */
 
 struct cli_ui_out_data
   {
-    VEC (ui_filep) *streams;
+    std::vector<ui_file *> streams;
     int suppress_output;
   };


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]