From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Simplify macro_define_command
Date: Mon, 22 Apr 2024 12:46:30 -0400 [thread overview]
Message-ID: <55a909d2-1585-4845-b8e2-9d2dbf66868c@simark.ca> (raw)
In-Reply-To: <20240422154923.1601231-1-tromey@adacore.com>
On 4/22/24 11:49 AM, Tom Tromey wrote:
> This simplifies macro_define_command, using std::vector to remove some
> manual memory management. temporary_macro_definition is also
> simplified -- much of the code there was simply unnecessary.
>
> Regression tested on x86-64 Fedora 38.
> ---
> gdb/macrocmd.c | 55 +++++++++++++++-----------------------------------
> 1 file changed, 16 insertions(+), 39 deletions(-)
>
> diff --git a/gdb/macrocmd.c b/gdb/macrocmd.c
> index ddabfede0f5..0d0db5d1b90 100644
> --- a/gdb/macrocmd.c
> +++ b/gdb/macrocmd.c
> @@ -308,33 +308,24 @@ extract_identifier (const char **expp, int is_parameter)
> return gdb::unique_xmalloc_ptr<char> (result);
> }
>
> -struct temporary_macro_definition : public macro_definition
> +struct temporary_macro_definition
> {
> - temporary_macro_definition ()
> + ~temporary_macro_definition ()
> {
> - table = nullptr;
> - kind = macro_object_like;
> - argc = 0;
> - argv = nullptr;
> - replacement = nullptr;
> + free_vector_argv (argv);
> }
Since this structure has a destructor, perhaps make it
non-copyable/assignable/etc (rule of 3/5)?
It could be a subsequent cleanup, but that class could have a more
general name and live in gdbsupport/common-utils.h. It could then be
used by other current users of free_vector_argv.
> @@ -358,26 +343,18 @@ macro_define_command (const char *exp, int from_tty)
>
> while (*exp != ')')
> {
> - int i;
> -
> - if (new_macro.argc == alloced)
> - {
> - alloced *= 2;
> - argv = (char **) xrealloc (argv, alloced * sizeof (char *));
> - /* Must update new_macro as well... */
> - new_macro.argv = (const char * const *) argv;
> - }
> - argv[new_macro.argc] = extract_identifier (&exp, 1).release ();
> - if (! argv[new_macro.argc])
> + auto arg = extract_identifier (&exp, 1);
> + if (! arg)
arg == nullptr
> error (_("Macro is missing an argument."));
> - ++new_macro.argc;
>
> - for (i = new_macro.argc - 2; i >= 0; --i)
> + for (const char *existing : new_macro.argv)
> {
> - if (! strcmp (argv[i], argv[new_macro.argc - 1]))
> + if (! strcmp (existing, arg.get ()))
> error (_("Two macro arguments with identical names."));
> }
You could remove the braces while at it.
Simon
prev parent reply other threads:[~2024-04-22 16:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-22 15:49 Tom Tromey
2024-04-22 16:46 ` Simon Marchi [this message]
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=55a909d2-1585-4845-b8e2-9d2dbf66868c@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=tromey@adacore.com \
/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).