From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA 02/14] Introduce command_line_up
Date: Mon, 10 Apr 2017 02:36:00 -0000 [thread overview]
Message-ID: <ef1d04ca4498306f50094dbf819ea54a@polymtl.ca> (raw)
In-Reply-To: <20170408201208.2672-3-tom@tromey.com>
On 2017-04-08 16:11, Tom Tromey wrote:
> This introduces command_line_up, a unique_ptr for command_line
> objects, and changes many places to use it. This removes a number of
> cleanups.
>
> Command lines are funny in that sometimes they are reference counted.
> Once there is more C++-ification of some of the users, perhaps all of
> these can be changed to use shared_ptr instead.
Looks good to me in general, just a few comments.
> diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
> index 33b657d..ded2d2b 100644
> --- a/gdb/cli/cli-script.c
> +++ b/gdb/cli/cli-script.c
> @@ -165,27 +165,22 @@ build_command_line (enum command_control_type
> type, const char *args)
> /* Build and return a new command structure for the control commands
> such as "if" and "while". */
>
> -struct command_line *
> +command_line_up
> get_command_line (enum command_control_type type, const char *arg)
> {
> - struct command_line *cmd;
> - struct cleanup *old_chain = NULL;
> + command_line_up cmd;
>
> /* Allocate and build a new command line structure. */
> - cmd = build_command_line (type, arg);
> -
> - old_chain = make_cleanup_free_command_lines (&cmd);
> + cmd.reset (build_command_line (type, arg));
Can you do
command_line_up cmd (build_command_line (type, arg));
?
> @@ -1256,17 +1243,17 @@ read_command_lines (char *prompt_arg, int
> from_tty, int parse_commands,
> /* Act the same way as read_command_lines, except that each new line
> is
> obtained using READ_NEXT_LINE_FUNC. */
>
> -struct command_line *
> +command_line_up
> read_command_lines_1 (char * (*read_next_line_func) (void), int
> parse_commands,
> void (*validator)(char *, void *), void *closure)
> {
> - struct command_line *head, *tail, *next;
> - struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
> + struct command_line *tail, *next;
> + command_line_up head;
> enum command_control_type ret;
> enum misc_command_type val;
>
> control_level = 0;
> - head = tail = NULL;
> + tail = NULL;
>
> while (1)
> {
> @@ -1307,18 +1294,17 @@ read_command_lines_1 (char *
> (*read_next_line_func) (void), int parse_commands,
> }
> else
> {
> - head = next;
> - make_cleanup_free_command_lines (&head);
> + /* Make sure not to free HEAD. */
> + head.release ();
> + head.reset (next);
I don't understand that bit, why the comment and the release? From what
I understand, this else clause is executed only for the first item, when
head is still NULL. The goal being to keep a reference to the head of
the list. All the other iterations will go in the true clause, which
appends the new item at the end of the list.
> }
> tail = next;
> }
>
> dont_repeat ();
>
> - if (ret != invalid_control)
> - discard_cleanups (old_chain);
> - else
> - do_cleanups (old_chain);
> + if (ret == invalid_control)
> + head.reset (NULL);
I wonder if a simple "return NULL" would do the trick here. Either way
is fine with me.
Thanks,
Simon
next prev parent reply other threads:[~2017-04-10 2:36 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-08 20:12 [RFA 00/14] miscellaneous C++-ificiation Tom Tromey
2017-04-08 20:12 ` [RFA 09/14] Remove some cleanups from location.c Tom Tromey
2017-04-10 4:43 ` Simon Marchi
2017-04-08 20:12 ` [RFA 10/14] C++ify mi_parse Tom Tromey
2017-04-11 1:12 ` Simon Marchi
2017-04-08 20:12 ` [RFA 03/14] Change find_pcs_for_symtab_line to return a std::vector Tom Tromey
2017-04-10 2:49 ` Simon Marchi
2017-04-08 20:12 ` [RFA 02/14] Introduce command_line_up Tom Tromey
2017-04-10 2:36 ` Simon Marchi [this message]
2017-04-10 23:21 ` Tom Tromey
2017-04-08 20:12 ` [RFA 14/14] Use std::vector in compile-loc2c.c Tom Tromey
2017-04-08 20:12 ` [RFA 08/14] Remove some cleanups from gnu-v3-abi.c Tom Tromey
2017-04-10 4:09 ` Simon Marchi
2017-04-10 13:57 ` Tom Tromey
2017-04-08 20:12 ` [RFA 11/14] Use scoped_restore in more places Tom Tromey
2017-04-11 1:48 ` Simon Marchi
2017-04-08 20:12 ` [RFA 06/14] Remove cleanup_iconv Tom Tromey
2017-04-10 3:56 ` Simon Marchi
2017-04-10 23:20 ` Tom Tromey
2017-04-08 20:12 ` [RFA 01/14] Introduce event_location_up Tom Tromey
2017-04-10 1:33 ` Simon Marchi
2017-04-10 23:19 ` Tom Tromey
2017-04-08 20:13 ` [RFA 04/14] Introduce gdb_dlopen_up Tom Tromey
2017-04-10 3:13 ` Simon Marchi
2017-04-10 9:26 ` Pedro Alves
2017-04-10 23:31 ` Tom Tromey
2017-04-08 20:13 ` [RFA 13/14] Use std::vector in find_instruction_backward Tom Tromey
2017-04-08 20:13 ` [RFA 12/14] Use std::vector in reread_symbols Tom Tromey
2017-04-11 1:59 ` Simon Marchi
2017-04-08 20:22 ` [RFA 07/14] Fix up wchar_iterator comment Tom Tromey
2017-04-10 4:05 ` Simon Marchi
2017-04-10 23:29 ` Tom Tromey
2017-04-08 20:23 ` [RFA 05/14] Change increment_reading_symtab to return a scoped_restore Tom Tromey
2017-04-10 3:27 ` 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=ef1d04ca4498306f50094dbf819ea54a@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.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