This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2 07/22] Remove last cleanups from solib-svr4.c


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]