This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v2 07/22] Remove last cleanups from solib-svr4.c
- From: John Baldwin <jhb at FreeBSD dot org>
- To: Pedro Alves <palves at redhat dot com>, Tom Tromey <tom at tromey dot com>, gdb-patches at sourceware dot org
- Date: Wed, 6 Mar 2019 11:39:27 -0800
- Subject: Re: [PATCH v2 07/22] Remove last cleanups from solib-svr4.c
- References: <20190227201849.32210-1-tom@tromey.com> <20190227201849.32210-8-tom@tromey.com> <cf4097f4-1403-b081-2114-0bb34b141e0d@redhat.com>
On 3/6/19 11:32 AM, Pedro Alves wrote:
> On 02/27/2019 08:18 PM, Tom Tromey wrote:
>> This removes the last cleanups from solib-svr4.c, replacing them with
>> uses of make_scope_exit.
>>
>> gdb/ChangeLog
>> 2019-02-27 Tom Tromey <tom@tromey.com>
>>
>> * solib-svr4.c (svr4_parse_libraries, svr4_current_sos_direct):
>> Use make_scope_exit.
>> ---
>> gdb/ChangeLog | 5 +++++
>> gdb/solib-svr4.c | 17 ++++++++++-------
>> 2 files changed, 15 insertions(+), 7 deletions(-)
>>
>> diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
>> index 2b370ef96d0..2301cf94c2f 100644
>> --- a/gdb/solib-svr4.c
>> +++ b/gdb/solib-svr4.c
>> @@ -1198,8 +1198,10 @@ static const struct gdb_xml_element svr4_library_list_elements[] =
>> static int
>> svr4_parse_libraries (const char *document, struct svr4_library_list *list)
>> {
>> - struct cleanup *back_to = make_cleanup (svr4_free_library_list,
>> - &list->head);
>> + auto cleanup = make_scope_exit ([&] ()
>> + {
>> + svr4_free_library_list (&list->head);
>> + });
>>
>
> When passing lambdas as last argument to a function, I think indenting
> like this reads clearer:
>
> auto cleanup = make_scope_exit ([&] ()
> {
> svr4_free_library_list (&list->head);
> });
>
> Makes it read more like an if/for scope block, and of course,
> avoids aligning things too much to the right side. Examples of
> this can be found throughout gdbserver, for example:
>
> for_each_thread ([] (thread_info *thread)
> {
> thread->status_pending_p = 0;
> });
>
> and, also, that's how you'd indent if you used SCOPE_EXIT instead:
>
> SCOPE_EXIT
> {
> svr4_free_library_list (&list->head);
> }
>
> LLVM has a written rule for this:
>
> https://llvm.org/docs/CodingStandards.html#format-lambdas-like-blocks-of-code
>
> If others agree, I'd vote for having a similar rule of our own.
I'd +1 that rule FWIW.
--
John Baldwin