From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 1/2] Constify ada_encode return type
Date: Fri, 2 Oct 2020 14:26:03 -0600 [thread overview]
Message-ID: <20201002202604.1517475-2-tromey@adacore.com> (raw)
In-Reply-To: <20201002202604.1517475-1-tromey@adacore.com>
Callers of ada_encode don't ever modify the result, and also don't own
it -- it is owned by a static buffer in ada_encode_1. This patch
changes ada_encode to return a const char *, which I feel is somewhat
clearer.
gdb/ChangeLog
2020-10-02 Tom Tromey <tromey@adacore.com>
* ada-lang.h (ada_encode): Constify result.
* ada-lang.c (ada_encode): Constify result.
(ada_encode_1): Constify result.
---
gdb/ChangeLog | 6 ++++++
gdb/ada-exp.y | 6 +++---
gdb/ada-lang.c | 4 ++--
gdb/ada-lang.h | 2 +-
4 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 57d89b01fec..61d8df9df48 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -1201,9 +1201,9 @@ write_var_or_type (struct parser_state *par_state,
if (block == NULL)
block = par_state->expression_context_block;
- encoded_name = ada_encode (name0.ptr);
- name_len = strlen (encoded_name);
- encoded_name = obstack_strndup (&temp_parse_space, encoded_name, name_len);
+ const char *temp_name = ada_encode (name0.ptr);
+ name_len = strlen (temp_name);
+ encoded_name = obstack_strndup (&temp_parse_space, temp_name, name_len);
for (depth = 0; depth < MAX_RENAMING_CHAIN_LENGTH; depth += 1)
{
int tail_index;
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 0df406bff48..2502d2847b2 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -923,7 +923,7 @@ const struct ada_opname_map ada_opname_table[] = {
THROW_ERRORS, throw an error if invalid operator name is found.
Otherwise, return NULL in that case. */
-static char *
+static const char *
ada_encode_1 (const char *decoded, bool throw_errors)
{
static char *encoding_buffer = NULL;
@@ -978,7 +978,7 @@ ada_encode_1 (const char *decoded, bool throw_errors)
/* The "encoded" form of DECODED, according to GNAT conventions.
The result is valid until the next call to ada_encode. */
-char *
+const char *
ada_encode (const char *decoded)
{
return ada_encode_1 (decoded, true);
diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
index ae313ce700a..949d16ce3a6 100644
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -318,7 +318,7 @@ extern struct type *ada_get_base_type (struct type *);
extern struct type *ada_check_typedef (struct type *);
-extern char *ada_encode (const char *);
+extern const char *ada_encode (const char *);
extern const char *ada_enum_name (const char *);
--
2.26.2
next prev parent reply other threads:[~2020-10-02 20:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-02 20:26 [PATCH 0/2] ada_encode rewrites Tom Tromey
2020-10-02 20:26 ` Tom Tromey [this message]
2020-10-02 21:51 ` [PATCH 1/2] Constify ada_encode return type Simon Marchi
2020-10-07 18:26 ` Tom Tromey
2020-10-02 20:26 ` [PATCH 2/2] Use obstack in ada_encode_1 Tom Tromey
2020-10-02 21:54 ` Simon Marchi
2020-10-07 18:35 ` Tom Tromey
2020-10-07 18:36 ` Simon Marchi
2020-10-09 20:14 ` 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=20201002202604.1517475-2-tromey@adacore.com \
--to=tromey@adacore.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).