From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 1/6] Remove cleanup from old_renaming_is_invisible
Date: Thu, 30 Nov 2017 03:01:00 -0000 [thread overview]
Message-ID: <20171130030140.14830-2-tom@tromey.com> (raw)
In-Reply-To: <20171130030140.14830-1-tom@tromey.com>
This removes a cleanup from ada-lang.c by changing xget_renaming_scope
to return a std::string.
ChangeLog
2017-11-29 Tom Tromey <tom@tromey.com>
* ada-lang.c (xget_renaming_scope): Return std::string.
(old_renaming_is_invisible): Update.
---
gdb/ChangeLog | 5 +++++
gdb/ada-lang.c | 35 +++++++----------------------------
2 files changed, 12 insertions(+), 28 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3265c211fb..d5dfa07b78 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5180,9 +5180,9 @@ remove_extra_symbols (struct block_symbol *syms, int nsyms)
/* Given a type that corresponds to a renaming entity, use the type name
to extract the scope (package name or function name, fully qualified,
and following the GNAT encoding convention) where this renaming has been
- defined. The string returned needs to be deallocated after use. */
+ defined. */
-static char *
+static std::string
xget_renaming_scope (struct type *renaming_type)
{
/* The renaming types adhere to the following convention:
@@ -5193,8 +5193,6 @@ xget_renaming_scope (struct type *renaming_type)
const char *name = type_name_no_tag (renaming_type);
const char *suffix = strstr (name, "___XR");
const char *last;
- int scope_len;
- char *scope;
/* Now, backtrack a bit until we find the first "__". Start looking
at suffix - 3, as the <rename> part is at least one character long. */
@@ -5204,14 +5202,7 @@ xget_renaming_scope (struct type *renaming_type)
break;
/* Make a copy of scope and return it. */
-
- scope_len = last - name;
- scope = (char *) xmalloc ((scope_len + 1) * sizeof (char));
-
- strncpy (scope, name, scope_len);
- scope[scope_len] = '\0';
-
- return scope;
+ return std::string (name, last);
}
/* Return nonzero if NAME corresponds to a package name. */
@@ -5251,21 +5242,14 @@ is_package_name (const char *name)
static int
old_renaming_is_invisible (const struct symbol *sym, const char *function_name)
{
- char *scope;
- struct cleanup *old_chain;
-
if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
return 0;
- scope = xget_renaming_scope (SYMBOL_TYPE (sym));
- old_chain = make_cleanup (xfree, scope);
+ std::string scope = xget_renaming_scope (SYMBOL_TYPE (sym));
/* If the rename has been defined in a package, then it is visible. */
- if (is_package_name (scope))
- {
- do_cleanups (old_chain);
- return 0;
- }
+ if (is_package_name (scope.c_str ()))
+ return 0;
/* Check that the rename is in the current function scope by checking
that its name starts with SCOPE. */
@@ -5277,12 +5261,7 @@ old_renaming_is_invisible (const struct symbol *sym, const char *function_name)
if (startswith (function_name, "_ada_"))
function_name += 5;
- {
- int is_invisible = !startswith (function_name, scope);
-
- do_cleanups (old_chain);
- return is_invisible;
- }
+ return !startswith (function_name, scope.c_str ());
}
/* Remove entries from SYMS that corresponds to a renaming entity that
--
2.13.6
next prev parent reply other threads:[~2017-11-30 3:01 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-30 3:01 [RFA 0/6] remove cleanups from Ada Tom Tromey
2017-11-30 3:01 ` [RFA 6/6] Remove unnecessary cleanup from ada_collect_symbol_completion_matches Tom Tromey
2017-11-30 3:01 ` [RFA 3/6] Remove cleanup from print_mention_exception Tom Tromey
2017-11-30 3:01 ` Tom Tromey [this message]
2017-11-30 3:01 ` [RFA 4/6] Remove some more cleanups from ada-lang.c Tom Tromey
2017-11-30 3:01 ` [RFA 5/6] Change Ada exceptions to use std::string Tom Tromey
2017-11-30 22:03 ` Joel Brobecker
2017-11-30 22:59 ` Joel Brobecker
2017-11-30 23:53 ` Tom Tromey
2017-12-01 12:10 ` Joel Brobecker
2017-11-30 3:01 ` [RFA 2/6] Remove cleanup from create_excep_cond_exprs Tom Tromey
2017-11-30 22:02 ` [RFA 0/6] remove cleanups from Ada Joel Brobecker
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=20171130030140.14830-2-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