From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 7/8] Use std::string in d-namespace.c
Date: Sun, 10 Sep 2017 21:50:00 -0000 [thread overview]
Message-ID: <20170910215037.24329-8-tom@tromey.com> (raw)
In-Reply-To: <20170910215037.24329-1-tom@tromey.com>
This removes some cleanups from d-namespace.c by replacing manual
string management with std::string.
ChangeLog
2017-09-10 Tom Tromey <tom@tromey.com>
* d-namespace.c (d_lookup_symbol): Use std::string.
(find_symbol_in_baseclass): Likewise.
---
gdb/ChangeLog | 5 +++++
gdb/d-namespace.c | 45 ++++++++++++---------------------------------
2 files changed, 17 insertions(+), 33 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 735de68..f757ab5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2017-09-10 Tom Tromey <tom@tromey.com>
+ * d-namespace.c (d_lookup_symbol): Use std::string.
+ (find_symbol_in_baseclass): Likewise.
+
+2017-09-10 Tom Tromey <tom@tromey.com>
+
* ctf.c (ctf_start): Use std::string.
2017-09-10 Tom Tromey <tom@tromey.com>
diff --git a/gdb/d-namespace.c b/gdb/d-namespace.c
index ae2e7e3..bc791f7 100644
--- a/gdb/d-namespace.c
+++ b/gdb/d-namespace.c
@@ -108,16 +108,13 @@ d_lookup_symbol (const struct language_defn *langdef,
if (search)
{
- char *classname, *nested;
+ std::string classname, nested;
unsigned int prefix_len;
- struct cleanup *cleanup;
struct block_symbol class_sym;
/* A simple lookup failed. Check if the symbol was defined in
a base class. */
- cleanup = make_cleanup (null_cleanup, NULL);
-
/* Find the name of the class and the name of the method,
variable, etc. */
prefix_len = d_entire_prefix_len (name);
@@ -130,42 +127,31 @@ d_lookup_symbol (const struct language_defn *langdef,
lang_this = lookup_language_this (language_def (language_d), block);
if (lang_this.symbol == NULL)
- {
- do_cleanups (cleanup);
- return null_block_symbol;
- }
+ return null_block_symbol;
type = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (lang_this.symbol)));
- classname = xstrdup (TYPE_NAME (type));
- nested = xstrdup (name);
+ classname = TYPE_NAME (type);
+ nested = name;
}
else
{
/* The class name is everything up to and including PREFIX_LEN. */
- classname = savestring (name, prefix_len);
+ classname = std::string (name, prefix_len);
/* The rest of the name is everything else past the initial scope
operator. */
- nested = xstrdup (name + prefix_len + 1);
+ nested = std::string (name + prefix_len + 1);
}
- /* Add cleanups to free memory for these strings. */
- make_cleanup (xfree, classname);
- make_cleanup (xfree, nested);
-
/* Lookup a class named CLASSNAME. If none is found, there is nothing
more that can be done. */
- class_sym = lookup_global_symbol (classname, block, domain);
+ class_sym = lookup_global_symbol (classname.c_str (), block, domain);
if (class_sym.symbol == NULL)
- {
- do_cleanups (cleanup);
- return null_block_symbol;
- }
+ return null_block_symbol;
/* Look for a symbol named NESTED in this class. */
sym = d_lookup_nested_symbol (SYMBOL_TYPE (class_sym.symbol),
- nested, block);
- do_cleanups (cleanup);
+ nested.c_str (), block);
}
return sym;
@@ -260,18 +246,14 @@ static struct block_symbol
find_symbol_in_baseclass (struct type *parent_type, const char *name,
const struct block *block)
{
- char *concatenated_name = NULL;
struct block_symbol sym;
- struct cleanup *cleanup;
int i;
sym.symbol = NULL;
sym.block = NULL;
- cleanup = make_cleanup (free_current_contents, &concatenated_name);
for (i = 0; i < TYPE_N_BASECLASSES (parent_type); ++i)
{
- size_t len;
struct type *base_type = TYPE_BASECLASS (parent_type, i);
const char *base_name = TYPE_BASECLASS_NAME (parent_type, i);
@@ -287,10 +269,8 @@ find_symbol_in_baseclass (struct type *parent_type, const char *name,
/* Now search all static file-level symbols. We have to do this for
things like typedefs in the class. First search in this symtab,
what we want is possibly there. */
- len = strlen (base_name) + strlen (name) + 2;
- concatenated_name = (char *) xrealloc (concatenated_name, len);
- xsnprintf (concatenated_name, len, "%s.%s", base_name, name);
- sym = lookup_symbol_in_static_block (concatenated_name, block,
+ std::string concatenated_name = std::string (base_name) + "." + name;
+ sym = lookup_symbol_in_static_block (concatenated_name.c_str (), block,
VAR_DOMAIN);
if (sym.symbol != NULL)
break;
@@ -298,7 +278,7 @@ find_symbol_in_baseclass (struct type *parent_type, const char *name,
/* Nope. We now have to search all static blocks in all objfiles,
even if block != NULL, because there's no guarantees as to which
symtab the symbol we want is in. */
- sym = lookup_static_symbol (concatenated_name, VAR_DOMAIN);
+ sym = lookup_static_symbol (concatenated_name.c_str (), VAR_DOMAIN);
if (sym.symbol != NULL)
break;
@@ -312,7 +292,6 @@ find_symbol_in_baseclass (struct type *parent_type, const char *name,
}
}
- do_cleanups (cleanup);
return sym;
}
--
2.9.4
next prev parent reply other threads:[~2017-09-10 21:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-10 21:50 [RFA 0/8] various cleanup removals Tom Tromey
2017-09-10 21:50 ` [RFA 5/8] Remove cleanups from find_frame_funname Tom Tromey
2017-09-11 20:25 ` Simon Marchi
2017-09-10 21:50 ` [RFA 2/8] Replace interp_set_temp with scoped_restore_interp Tom Tromey
2017-09-10 21:50 ` [RFA 4/8] Remove cleanups from findcmd.c Tom Tromey
2017-09-10 21:50 ` Tom Tromey [this message]
2017-09-10 21:50 ` [RFA 8/8] Remove make_show_memory_breakpoints_cleanup Tom Tromey
2017-09-11 20:34 ` Simon Marchi
2017-09-10 21:50 ` [RFA 3/8] Replace clear_hook_in_cleanup with scoped_restore_hook_in Tom Tromey
2017-09-10 21:50 ` [RFA 6/8] Use std::string in ctf_start Tom Tromey
2017-09-10 21:50 ` [RFA 1/8] Change setup_breakpoint_reporting to return a scoped_restore Tom Tromey
2017-09-11 20:35 ` [RFA 0/8] various cleanup removals Simon Marchi
2017-09-11 22:04 ` 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=20170910215037.24329-8-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