From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 09/10] Remove typep and VEC(typep) from linespec.c
Date: Sun, 01 Apr 2018 16:35:00 -0000 [thread overview]
Message-ID: <20180401163539.15314-10-tom@tromey.com> (raw)
In-Reply-To: <20180401163539.15314-1-tom@tromey.com>
This removes VEC(typep) from linespec.c in favor of std::vector. It
also removes the "typep" typedef. This change allowed the removal of
some cleanups.
I believe the previous cleanup code in find_superclass_methods could
result in a memory leak, so this patch is an improvement in that way
as well.
2018-03-31 Tom Tromey <tom@tromey.com>
* linespec.c (typep): Remove typedef.
(find_methods, find_superclass_methods): Take a std::vector.
(find_method): Use std::vector.
---
gdb/ChangeLog | 6 ++++++
gdb/linespec.c | 35 ++++++++++-------------------------
2 files changed, 16 insertions(+), 25 deletions(-)
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 96a3117293..1cd79d2da9 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -80,9 +80,6 @@ enum class linespec_complete_what
typedef struct symbol *symbolp;
DEF_VEC_P (symbolp);
-typedef struct type *typep;
-DEF_VEC_P (typep);
-
/* An address entry is used to ensure that any given location is only
added to the result a single time. It holds an address and the
program space from which the address came. */
@@ -1212,7 +1209,7 @@ iterate_over_file_blocks
static void
find_methods (struct type *t, enum language t_lang, const char *name,
std::vector<const char *> *result_names,
- VEC (typep) **superclasses)
+ std::vector<struct type *> *superclasses)
{
int ibase;
const char *class_name = type_name_no_tag (t);
@@ -1273,7 +1270,7 @@ find_methods (struct type *t, enum language t_lang, const char *name,
}
for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
- VEC_safe_push (typep, *superclasses, TYPE_BASECLASS (t, ibase));
+ superclasses->push_back (TYPE_BASECLASS (t, ibase));
}
/* Find an instance of the character C in the string S that is outside
@@ -3649,32 +3646,24 @@ add_all_symbol_names_from_pspace (struct collect_info *info,
}
static void
-find_superclass_methods (VEC (typep) *superclasses,
+find_superclass_methods (std::vector<struct type *> &&superclasses,
const char *name, enum language name_lang,
std::vector<const char *> *result_names)
{
size_t old_len = result_names->size ();
- VEC (typep) *iter_classes;
- struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
- iter_classes = superclasses;
while (1)
{
- VEC (typep) *new_supers = NULL;
- int ix;
- struct type *t;
+ std::vector<struct type *> new_supers;
- make_cleanup (VEC_cleanup (typep), &new_supers);
- for (ix = 0; VEC_iterate (typep, iter_classes, ix, t); ++ix)
+ for (struct type *t : superclasses)
find_methods (t, name_lang, name, result_names, &new_supers);
- if (result_names->size () != old_len || VEC_empty (typep, new_supers))
+ if (result_names->size () != old_len || new_supers.empty ())
break;
- iter_classes = new_supers;
+ superclasses = std::move (new_supers);
}
-
- do_cleanups (cleanup);
}
/* This finds the method METHOD_NAME in the class CLASS_NAME whose type is
@@ -3688,10 +3677,9 @@ find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs,
VEC (bound_minimal_symbol_d) **minsyms)
{
struct symbol *sym;
- struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
int ix;
size_t last_result_len;
- VEC (typep) *superclass_vec;
+ std::vector<struct type *> superclass_vec;
std::vector<const char *> result_names;
struct collect_info info;
@@ -3716,8 +3704,6 @@ find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs,
those names. This loop is written in a somewhat funny way
because we collect data across the program space before deciding
what to do. */
- superclass_vec = NULL;
- make_cleanup (VEC_cleanup (typep), &superclass_vec);
last_result_len = 0;
for (ix = 0; VEC_iterate (symbolp, sym_classes, ix, sym); ++ix)
{
@@ -3743,7 +3729,7 @@ find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs,
/* If we did not find a direct implementation anywhere in
this program space, consider superclasses. */
if (result_names.size () == last_result_len)
- find_superclass_methods (superclass_vec, method_name,
+ find_superclass_methods (std::move (superclass_vec), method_name,
SYMBOL_LANGUAGE (sym), &result_names);
/* We have a list of candidate symbol names, so now we
@@ -3752,7 +3738,7 @@ find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs,
add_all_symbol_names_from_pspace (&info, pspace, result_names,
FUNCTIONS_DOMAIN);
- VEC_truncate (typep, superclass_vec, 0);
+ superclass_vec.clear ();
last_result_len = result_names.size ();
}
}
@@ -3762,7 +3748,6 @@ find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs,
{
*symbols = info.result.symbols;
*minsyms = info.result.minimal_symbols;
- do_cleanups (cleanup);
return;
}
--
2.13.6
next prev parent reply other threads:[~2018-04-01 16:35 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-01 16:35 [RFA 00/10] Remove some cleanups " Tom Tromey
2018-04-01 16:35 ` [RFA 01/10] Remove some cleanups from search_minsyms_for_name Tom Tromey
2018-04-02 1:39 ` Simon Marchi
2018-04-01 16:35 ` [RFA 05/10] Have filter_results take a std::vector Tom Tromey
2018-04-01 16:35 ` [RFA 06/10] Remove a string copy from event_location_to_sals Tom Tromey
2018-04-01 16:35 ` [RFA 02/10] Fix some indentation in linespec.c Tom Tromey
2018-04-02 1:49 ` Simon Marchi
2018-04-01 16:35 ` Tom Tromey [this message]
2018-04-01 16:35 ` [RFA 03/10] Make copy_token_string return unique_xmalloc_ptr Tom Tromey
2018-04-01 16:35 ` [RFA 07/10] Change streq to return bool Tom Tromey
2018-04-02 2:28 ` Simon Marchi
2018-04-01 16:35 ` [RFA 10/10] Remove unnecessary include from linespec.h Tom Tromey
2018-04-01 16:35 ` [RFA 08/10] More use of std::vector in linespec.c Tom Tromey
2018-04-02 2:35 ` Simon Marchi
2018-04-01 16:35 ` [RFA 04/10] Return std::string from canonical_to_fullform Tom Tromey
2018-04-02 2:15 ` Simon Marchi
2018-04-02 2:44 ` [RFA 00/10] Remove some cleanups from linespec.c Simon Marchi
2018-04-03 22:31 ` Tom Tromey
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=20180401163539.15314-10-tom@tromey.com \
--to=tom@tromey.com \
--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).