public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 11/22] Use std::vector for cli_ui_out_data::streams
Date: Thu, 24 Nov 2016 15:28:00 -0000	[thread overview]
Message-ID: <20161124152710.25007-11-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20161124152428.24725-1-simon.marchi@polymtl.ca>

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 (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.
---
 gdb/cli-out.c | 31 +++++++++++++++----------------
 gdb/cli-out.h |  9 ++-------
 2 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index b98af4a..83da5ac 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -46,7 +46,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 +238,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 +254,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 +267,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 +279,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 +297,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 +312,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 +331,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 +346,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 +382,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 +404,14 @@ 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.pop_back ();
+  data->streams.push_back (stream);
 
   return old;
 }
-\f
+
 /* 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;
   };
 
-- 
2.10.0

  parent reply	other threads:[~2016-11-24 15:28 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-24 15:24 [PATCH 00/22] Convert ui-out subsystem to C++ Simon Marchi
2016-11-24 15:24 ` [PATCH 01/22] Remove unused functions and declarations Simon Marchi
2016-11-24 15:24 ` [PATCH 06/22] Remove verbosity from ui_out_message and friends Simon Marchi
2016-11-24 15:24 ` [PATCH 02/22] Rename ui_out_data to mi_ui_out_data Simon Marchi
2016-11-24 15:24 ` [PATCH 08/22] Use new/delete instead of malloc/free-based functions Simon Marchi
2016-11-24 15:24 ` [PATCH 03/22] Remove ui_out_destroy Simon Marchi
2016-11-24 15:24 ` [PATCH 09/22] Use std::vector for ui_out::levels Simon Marchi
2016-11-24 15:24 ` [PATCH 07/22] Remove stale comments Simon Marchi
2016-11-24 18:38   ` Pedro Alves
2016-11-26 15:29     ` Simon Marchi
2016-11-24 15:27 ` [PATCH 10/22] Use std::vector for mi_ui_out_data::streams Simon Marchi
2016-11-24 18:38   ` Pedro Alves
2016-11-26 15:48     ` Simon Marchi
2016-11-24 15:28 ` [PATCH 13/22] Replace hand-made linked list of ui_out_hdr by vector and iterator Simon Marchi
2016-11-24 18:41   ` Pedro Alves
2016-11-26 16:13     ` Simon Marchi
2016-12-01 20:22       ` Simon Marchi
2016-12-01 20:23         ` Pedro Alves
2016-11-24 15:28 ` [PATCH 16/22] Class-ify ui_out_level Simon Marchi
2016-11-24 18:41   ` Pedro Alves
2016-11-26 16:22     ` Simon Marchi
2016-11-30 12:07       ` Pedro Alves
2016-11-30 12:41         ` Antoine Tremblay
2016-11-30 13:27           ` Pedro Alves
2016-11-30 13:47             ` Antoine Tremblay
2016-11-30 14:17               ` Pedro Alves
2016-11-30 14:21                 ` Antoine Tremblay
2016-11-30 20:40         ` Simon Marchi
2016-11-24 15:28 ` [PATCH 15/22] Class-ify ui_out_hdr Simon Marchi
2016-11-24 15:28 ` [PATCH 12/22] Use std::string in ui_out_table Simon Marchi
2016-11-24 15:28 ` [PATCH 17/22] Simplify ui-out level code Simon Marchi
2016-11-24 18:42   ` Pedro Alves
2016-11-26 16:39     ` Simon Marchi
2016-11-30 12:08       ` Pedro Alves
2016-11-24 15:28 ` [PATCH 18/22] ui_out_table: Replace boolean flag with enum Simon Marchi
2016-11-24 18:42   ` Pedro Alves
2016-11-26 16:47     ` Simon Marchi
2016-11-30 12:10       ` Pedro Alves
2016-11-24 15:28 ` Simon Marchi [this message]
2016-11-24 18:41   ` [PATCH 11/22] Use std::vector for cli_ui_out_data::streams Pedro Alves
2016-11-26 15:51     ` Simon Marchi
2016-11-24 15:28 ` [PATCH 14/22] Use std::string for ui_out_hdr's text fields Simon Marchi
2016-11-24 15:32 ` [PATCH 22/22] Introduce enum_flag type for ui_out flags Simon Marchi
2016-11-30 13:34   ` Pedro Alves
2016-11-30 21:32     ` Simon Marchi
2016-12-02 22:22     ` [pushed] " Simon Marchi
2016-11-24 15:36 ` [PATCH 05/22] Constify wrap_here/wrap_hint code path Simon Marchi
2016-11-24 15:36 ` [PATCH 04/22] Fix return value of uo_redirect Simon Marchi
2016-11-24 16:08 ` [PATCH 00/22] Convert ui-out subsystem to C++ Simon Marchi
2016-11-24 18:46   ` Pedro Alves
2016-11-24 19:15     ` Simon Marchi
2016-11-24 20:33       ` Simon Marchi
2016-11-24 18:47   ` Pedro Alves
2016-11-27  3:14     ` Simon Marchi
2016-12-01  2:51     ` Simon Marchi
2016-12-01 21:24       ` Simon Marchi
2016-11-24 19:11 ` [PATCH 20/22] Class-ify ui_out_table Simon Marchi
2016-11-30 12:29   ` Pedro Alves
2016-11-24 19:19 ` [PATCH 21/22] Class-ify ui_out Simon Marchi
2016-11-30 12:46   ` Pedro Alves
2016-11-30 21:47     ` Simon Marchi
2016-11-26 15:20 ` [PATCH 19/22] Class-ify ui_out_impl simon.marchi
2016-11-30 13:09   ` Pedro Alves
2016-11-30 22:38     ` Simon Marchi
2016-11-30 22:58       ` Pedro Alves
2016-12-01 19:04         ` Simon Marchi
2016-12-01 19:30           ` Pedro Alves
     [not found] ` <20161124153228.25177-20-simon.marchi@polymtl.ca>
2016-11-26 17:18   ` [PATCH 20/22] Class-ify ui_out_table Simon Marchi
2016-11-30 12:30     ` Pedro Alves
2016-11-30 21:48       ` [PATCH v2] " Simon Marchi
2016-11-30 23:01         ` Pedro Alves

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=20161124152710.25007-11-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --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).