[RFA,3/3] Use std::vector in gdb_bfd_data
Commit Message
This changes gdb_bfd_data to use std::vector rather than VEC.
ChangeLog
2017-10-17 Tom Tromey <tom@tromey.com>
* gdb_bfd.c (~gdb_bfd_data): Use for_each.
(struct gdb_bfd_data) <included_bfds>: Now a std::vector.
(gdb_bfd_record_inclusion): Update.
---
gdb/ChangeLog | 6 ++++++
gdb/gdb_bfd.c | 18 +++++-------------
2 files changed, 11 insertions(+), 13 deletions(-)
Comments
On 2017-10-18 00:14, Tom Tromey wrote:
> This changes gdb_bfd_data to use std::vector rather than VEC.
>
> ChangeLog
> 2017-10-17 Tom Tromey <tom@tromey.com>
>
> * gdb_bfd.c (~gdb_bfd_data): Use for_each.
> (struct gdb_bfd_data) <included_bfds>: Now a std::vector.
> (gdb_bfd_record_inclusion): Update.
> ---
> gdb/ChangeLog | 6 ++++++
> gdb/gdb_bfd.c | 18 +++++-------------
> 2 files changed, 11 insertions(+), 13 deletions(-)
>
> diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
> index e943d9bb62..de7d6f2fb5 100644
> --- a/gdb/gdb_bfd.c
> +++ b/gdb/gdb_bfd.c
> @@ -33,9 +33,7 @@
> #include "target.h"
> #include "gdb/fileio.h"
> #include "inferior.h"
> -
> -typedef bfd *bfdp;
> -DEF_VEC_P (bfdp);
> +#include <algorithm>
>
> /* An object of this type is stored in the section's user data when
> mapping a section. */
> @@ -87,14 +85,8 @@ struct gdb_bfd_data
>
> ~gdb_bfd_data ()
> {
> - int ix;
> - bfd *included_bfd;
> -
> - for (ix = 0;
> - VEC_iterate (bfdp, included_bfds, ix, included_bfd);
> - ++ix)
> - gdb_bfd_unref (included_bfd);
> - VEC_free (bfdp, included_bfds);
> + std::for_each (included_bfds.begin (), included_bfds.end (),
> + gdb_bfd_unref);
It's a matter of taste, but I prefer the form
for (bfd *b : included_bfs):
gdb_bfd_unref (b);
But instead, can we make the vector a vector of gdb_bfd_ref_ptr, so that
the default destructor would take care of everything?
Simon
>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
Simon> But instead, can we make the vector a vector of gdb_bfd_ref_ptr, so
Simon> that the default destructor would take care of everything?
Yeah, good idea. I made this change as well.
Note this can't be done with archive_bfd, because I think the rule is
that members must be closed before the archive is closed. Though
perhaps we could move the bfd closing into the destructor as well.
Tom
@@ -33,9 +33,7 @@
#include "target.h"
#include "gdb/fileio.h"
#include "inferior.h"
-
-typedef bfd *bfdp;
-DEF_VEC_P (bfdp);
+#include <algorithm>
/* An object of this type is stored in the section's user data when
mapping a section. */
@@ -87,14 +85,8 @@ struct gdb_bfd_data
~gdb_bfd_data ()
{
- int ix;
- bfd *included_bfd;
-
- for (ix = 0;
- VEC_iterate (bfdp, included_bfds, ix, included_bfd);
- ++ix)
- gdb_bfd_unref (included_bfd);
- VEC_free (bfdp, included_bfds);
+ std::for_each (included_bfds.begin (), included_bfds.end (),
+ gdb_bfd_unref);
}
/* The reference count. */
@@ -130,7 +122,7 @@ struct gdb_bfd_data
bfd *archive_bfd = nullptr;
/* Table of all the bfds this bfd has included. */
- VEC (bfdp) *included_bfds = nullptr;
+ std::vector<bfd *> included_bfds;
/* The registry. */
REGISTRY_FIELDS = {};
@@ -878,7 +870,7 @@ gdb_bfd_record_inclusion (bfd *includer, bfd *includee)
gdb_bfd_ref (includee);
gdata = (struct gdb_bfd_data *) bfd_usrdata (includer);
- VEC_safe_push (bfdp, gdata->included_bfds, includee);
+ gdata->included_bfds.push_back (includee);
}
/* See gdb_bfd.h. */