Patchwork Use std::vector for symtab_fns

login
register
mail settings
Submitter Simon Marchi
Date Oct. 10, 2017, 8:01 p.m.
Message ID <1507665661-14742-1-git-send-email-simon.marchi@ericsson.com>
Download mbox | patch
Permalink /patch/23464/
State New
Headers show

Comments

Simon Marchi - Oct. 10, 2017, 8:01 p.m.
Simple replacement of VEC with std::vector.

gdb/ChangeLog:

	* symfile.c (registered_sym_fns): Make struct, not typedef.
	(DEF_VEC_O (registered_sym_fns)): Remove.
	(symtab_fns): Change type to std::vector.
	(add_symtab_fns): Adjust.
	(find_sym_fns): Adjust.
---
 gdb/symfile.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
Pedro Alves - Oct. 11, 2017, 1:05 p.m.
On 10/10/2017 09:01 PM, Simon Marchi wrote:
> Simple replacement of VEC with std::vector.
> 
> gdb/ChangeLog:
> 
> 	* symfile.c (registered_sym_fns): Make struct, not typedef.
> 	(DEF_VEC_O (registered_sym_fns)): Remove.
> 	(symtab_fns): Change type to std::vector.
> 	(add_symtab_fns): Adjust.
> 	(find_sym_fns): Adjust.


OK.

> -  for (i = 0; VEC_iterate (registered_sym_fns, symtab_fns, i, rsf); ++i)
> -    if (our_flavour == rsf->sym_flavour)
> -      return rsf->sym_fns;
> +  for (registered_sym_fns &rsf : symtab_fns)

Small nit: could this be a const ref?  I think it's a good
rule to prefer const over non-const references if we can.

> +    if (our_flavour == rsf.sym_flavour)
> +      return rsf.sym_fns;
>  
>    error (_("I'm sorry, Dave, I can't do that.  Symbol format `%s' unknown."),
>  	 bfd_get_target (abfd));
> 

Thanks,
Pedro Alves
Simon Marchi - Oct. 11, 2017, 1:36 p.m.
On 2017-10-11 09:05, Pedro Alves wrote:
> On 10/10/2017 09:01 PM, Simon Marchi wrote:
>> Simple replacement of VEC with std::vector.
>> 
>> gdb/ChangeLog:
>> 
>> 	* symfile.c (registered_sym_fns): Make struct, not typedef.
>> 	(DEF_VEC_O (registered_sym_fns)): Remove.
>> 	(symtab_fns): Change type to std::vector.
>> 	(add_symtab_fns): Adjust.
>> 	(find_sym_fns): Adjust.
> 
> 
> OK.
> 
>> -  for (i = 0; VEC_iterate (registered_sym_fns, symtab_fns, i, rsf); 
>> ++i)
>> -    if (our_flavour == rsf->sym_flavour)
>> -      return rsf->sym_fns;
>> +  for (registered_sym_fns &rsf : symtab_fns)
> 
> Small nit: could this be a const ref?  I think it's a good
> rule to prefer const over non-const references if we can.

Yes of course, that's an oversight on my part.

Pushed with that fixed, thanks.

Simon

Patch

diff --git a/gdb/symfile.c b/gdb/symfile.c
index a741654..ca43931 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -111,18 +111,20 @@  static void symfile_find_segment_sections (struct objfile *objfile);
    calls add_symtab_fns() to register information on each format it is
    prepared to read.  */
 
-typedef struct
+struct registered_sym_fns
 {
+  registered_sym_fns (bfd_flavour sym_flavour_, const struct sym_fns *sym_fns_)
+  : sym_flavour (sym_flavour_), sym_fns (sym_fns_)
+  {}
+
   /* BFD flavour that we handle.  */
   enum bfd_flavour sym_flavour;
 
   /* The "vtable" of symbol functions.  */
   const struct sym_fns *sym_fns;
-} registered_sym_fns;
-
-DEF_VEC_O (registered_sym_fns);
+};
 
-static VEC (registered_sym_fns) *symtab_fns = NULL;
+static std::vector<registered_sym_fns> symtab_fns;
 
 /* Values for "set print symbol-loading".  */
 
@@ -1768,9 +1770,7 @@  get_section_index (struct objfile *objfile, const char *section_name)
 void
 add_symtab_fns (enum bfd_flavour flavour, const struct sym_fns *sf)
 {
-  registered_sym_fns fns = { flavour, sf };
-
-  VEC_safe_push (registered_sym_fns, symtab_fns, &fns);
+  symtab_fns.emplace_back (flavour, sf);
 }
 
 /* Initialize OBJFILE to read symbols from its associated BFD.  It
@@ -1781,18 +1781,16 @@  add_symtab_fns (enum bfd_flavour flavour, const struct sym_fns *sf)
 static const struct sym_fns *
 find_sym_fns (bfd *abfd)
 {
-  registered_sym_fns *rsf;
   enum bfd_flavour our_flavour = bfd_get_flavour (abfd);
-  int i;
 
   if (our_flavour == bfd_target_srec_flavour
       || our_flavour == bfd_target_ihex_flavour
       || our_flavour == bfd_target_tekhex_flavour)
     return NULL;	/* No symbols.  */
 
-  for (i = 0; VEC_iterate (registered_sym_fns, symtab_fns, i, rsf); ++i)
-    if (our_flavour == rsf->sym_flavour)
-      return rsf->sym_fns;
+  for (registered_sym_fns &rsf : symtab_fns)
+    if (our_flavour == rsf.sym_flavour)
+      return rsf.sym_fns;
 
   error (_("I'm sorry, Dave, I can't do that.  Symbol format `%s' unknown."),
 	 bfd_get_target (abfd));