This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 10/22] Use std::vector for mi_ui_out_data::streams
- From: Simon Marchi <simon dot marchi at polymtl dot ca>
- To: gdb-patches at sourceware dot org
- Cc: Simon Marchi <simon dot marchi at polymtl dot ca>
- Date: Thu, 24 Nov 2016 10:26:58 -0500
- Subject: [PATCH 10/22] Use std::vector for mi_ui_out_data::streams
- Authentication-results: sourceware.org; auth=none
- References: <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 mi_ui_out_data object doesn't own the
streams objects (i.e. they shouldn't be deleted when the vector is
deleted).
gdb/ChangeLog:
* mi/mi-out.c (mi_ui_out_data) <streams>: Change type to
std::vector.
(mi_field_string): Update.
(mi_field_fmt): Update.
(mi_flush): Update.
(mi_redirect): Update.
(field_separator): Update.
(mi_open): Update.
(mi_close): Update.
(mi_out_buffered): Update.
(mi_out_rewind): Update.
(mi_out_put): Update.
(mi_out_data_ctor): Update.
(mi_out_data_dtor): Don't free streams.
---
gdb/mi/mi-out.c | 30 +++++++++++++-----------------
1 file changed, 13 insertions(+), 17 deletions(-)
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index 2561f16..c89076a 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -23,16 +23,14 @@
#include "ui-out.h"
#include "mi-out.h"
#include "vec.h"
-
-typedef struct ui_file *ui_filep;
-DEF_VEC_P (ui_filep);
+#include <vector>
struct mi_ui_out_data
{
int suppress_field_separator;
int suppress_output;
int mi_version;
- VEC (ui_filep) *streams;
+ std::vector<ui_file *> streams;
};
typedef struct mi_ui_out_data mi_out_data;
@@ -222,7 +220,7 @@ mi_field_string (struct ui_out *uiout, int fldno, int width,
if (data->suppress_output)
return;
- stream = VEC_last (ui_filep, data->streams);
+ stream = data->streams.back ();
field_separator (uiout);
if (fldname)
fprintf_unfiltered (stream, "%s=", fldname);
@@ -245,7 +243,7 @@ mi_field_fmt (struct ui_out *uiout, int fldno, int width,
if (data->suppress_output)
return;
- stream = VEC_last (ui_filep, data->streams);
+ stream = data->streams.back ();
field_separator (uiout);
if (fldname)
fprintf_unfiltered (stream, "%s=\"", fldname);
@@ -280,7 +278,7 @@ void
mi_flush (struct ui_out *uiout)
{
mi_out_data *data = (mi_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);
}
@@ -291,9 +289,9 @@ mi_redirect (struct ui_out *uiout, struct ui_file *outstream)
mi_out_data *data = (mi_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;
}
@@ -306,7 +304,7 @@ static void
field_separator (struct ui_out *uiout)
{
mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
- struct ui_file *stream = VEC_last (ui_filep, data->streams);
+ ui_file *stream = data->streams.back ();
if (data->suppress_field_separator)
data->suppress_field_separator = 0;
@@ -318,7 +316,7 @@ static void
mi_open (struct ui_out *uiout, const char *name, enum ui_out_type type)
{
mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
- struct ui_file *stream = VEC_last (ui_filep, data->streams);
+ ui_file *stream = data->streams.back ();
field_separator (uiout);
data->suppress_field_separator = 1;
@@ -341,7 +339,7 @@ static void
mi_close (struct ui_out *uiout, enum ui_out_type type)
{
mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
- struct ui_file *stream = VEC_last (ui_filep, data->streams);
+ ui_file *stream = data->streams.back ();
switch (type)
{
@@ -363,7 +361,7 @@ void
mi_out_rewind (struct ui_out *uiout)
{
mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
- struct ui_file *stream = VEC_last (ui_filep, data->streams);
+ ui_file *stream = data->streams.back ();
ui_file_rewind (stream);
}
@@ -374,7 +372,7 @@ void
mi_out_put (struct ui_out *uiout, struct ui_file *stream)
{
mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
- struct ui_file *outstream = VEC_last (ui_filep, data->streams);
+ ui_file *outstream = data->streams.back ();
ui_file_put (outstream, ui_file_write_for_put, stream);
ui_file_rewind (outstream);
@@ -397,8 +395,7 @@ mi_out_data_ctor (mi_out_data *self, int mi_version, 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_field_separator = 0;
self->suppress_output = 0;
@@ -412,7 +409,6 @@ mi_out_data_dtor (struct ui_out *ui_out)
{
mi_out_data *data = (mi_out_data *) ui_out_data (ui_out);
- VEC_free (ui_filep, data->streams);
delete data;
}
--
2.10.0