From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/3] gdb: make macro_stringify return a gdb::unique_xmalloc_ptr<char>
Date: Sun, 28 Jun 2020 12:56:28 -0400 [thread overview]
Message-ID: <20200628165628.96730-4-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20200628165628.96730-1-simon.marchi@polymtl.ca>
The change to macro_stringify is straightforward. This allows removing
the manual memory management in fixup_definition.
gdb/ChangeLog:
* macroexp.h (macro_stringify): Return
gdb::unique_xmalloc_ptr<char>.
* macroexp.c (macro_stringify): Likewise.
* macrotab.c (fixup_definition): Update.
Change-Id: Id7db8988bdbd569dd51c4f4655b00eb26db277cb
---
gdb/macroexp.c | 4 ++--
gdb/macroexp.h | 6 ++----
gdb/macrotab.c | 14 ++++----------
3 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/gdb/macroexp.c b/gdb/macroexp.c
index e1d185d30c8e..5f749ffe8928 100644
--- a/gdb/macroexp.c
+++ b/gdb/macroexp.c
@@ -698,7 +698,7 @@ stringify (struct macro_buffer *dest, const char *arg, int len)
/* See macroexp.h. */
-char *
+gdb::unique_xmalloc_ptr<char>
macro_stringify (const char *str)
{
int len = strlen (str);
@@ -707,7 +707,7 @@ macro_stringify (const char *str)
stringify (&buffer, str, len);
buffer.appendc ('\0');
- return buffer.release ().release ();
+ return buffer.release ();
}
\f
diff --git a/gdb/macroexp.h b/gdb/macroexp.h
index 511991cacd20..2e29d02d34bd 100644
--- a/gdb/macroexp.h
+++ b/gdb/macroexp.h
@@ -78,9 +78,7 @@ int macro_is_identifier_nondigit (int c);
int macro_is_digit (int c);
-/* Stringify STR according to C rules and return an xmalloc'd pointer
- to the result. */
-
-char *macro_stringify (const char *str);
+/* Stringify STR according to C rules and return a null-terminated string. */
+gdb::unique_xmalloc_ptr<char> macro_stringify (const char *str);
#endif /* MACROEXP_H */
diff --git a/gdb/macrotab.c b/gdb/macrotab.c
index 63cd30148ac2..0fefe8faaacf 100644
--- a/gdb/macrotab.c
+++ b/gdb/macrotab.c
@@ -882,25 +882,19 @@ macro_undef (struct macro_source_file *source, int line,
static struct macro_definition *
fixup_definition (const char *filename, int line, struct macro_definition *def)
{
- static char *saved_expansion;
-
- if (saved_expansion)
- {
- xfree (saved_expansion);
- saved_expansion = NULL;
- }
+ gdb::unique_xmalloc_ptr<char> saved_expansion;
if (def->kind == macro_object_like)
{
if (def->argc == macro_FILE)
{
saved_expansion = macro_stringify (filename);
- def->replacement = saved_expansion;
+ def->replacement = saved_expansion.get ();
}
else if (def->argc == macro_LINE)
{
- saved_expansion = xstrprintf ("%d", line);
- def->replacement = saved_expansion;
+ saved_expansion.reset (xstrprintf ("%d", line));
+ def->replacement = saved_expansion.get ();
}
}
--
2.27.0
next prev parent reply other threads:[~2020-06-28 16:56 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-28 16:56 [PATCH 0/3] Small cleanups in macro code Simon Marchi
2020-06-28 16:56 ` [PATCH 1/3] gdb: remove callback in macro expand functions Simon Marchi
2020-06-30 20:47 ` Tom Tromey
2020-06-30 22:14 ` Matt Rice
2020-06-30 22:26 ` Simon Marchi
2020-06-28 16:56 ` [PATCH 2/3] gdb: make macro_expand_next return a gdb::unique_xmalloc_ptr<char> Simon Marchi
2020-06-30 20:53 ` Tom Tromey
2020-06-30 22:26 ` Simon Marchi
2020-06-28 16:56 ` Simon Marchi [this message]
2020-06-30 20:55 ` [PATCH 3/3] gdb: make macro_stringify " Tom Tromey
2020-07-01 0:26 ` Simon Marchi
2020-07-01 15:36 ` Tom Tromey
2020-07-04 2:28 ` Simon Marchi
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=20200628165628.96730-4-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--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