Re: [PATCH] Delete program spaces directly when removing inferiors

Pedro Alves
2015-07-08T12:05:57Z

On 09/29/2014 09:33 PM, Simon Marchi wrote:

> -void
> -delete_inferior (int pid)
> -{
> - struct inferior *inf = find_inferior_pid (pid);
> -
> - delete_inferior_1 (inf, 0);
> -
> - if (print_inferior_events)
> - printf_unfiltered (_("[Inferior %d exited]\n"), pid);
> -}
> + /* If this program space is rendered useless, remove it. */
> + if (program_space_empty_p (inf->pspace))
> + delete_program_space (inf->pspace);

I think there's something odd with indentation here.

> - struct program_space *ss, **ss_link;
> - struct program_space *current = current_program_space;
> + gdb_assert(pspace != NULL);
> + gdb_assert(pspace != current_program_space);
>
> - ss = program_spaces;
> - ss_link = &program_spaces;
> - while (ss)
> + if (pspace == program_spaces)
> + program_spaces = pspace->next;
> + else
> {
> - if (ss == current || !pspace_empty_p (ss))
> + struct program_space *i = program_spaces;
> +
> + for (i = program_spaces; i != NULL; i = i->next)
> {
> - ss_link = &ss->next;
> - ss = *ss_link;
> - continue;
> + if (i->next == pspace)
> + {
> + i->next = i->next->next;
> + break;
> + }
> }
> -
> - *ss_link = ss->next;
> - release_program_space (ss);
> - ss = *ss_link;
> }

I don't find this conversion from while to if+else+for an
improvement. You can instead write:

ss = program_spaces;
ss_link = &program_spaces;
while (ss != NULL)
{
if (ss == pspace)
{
*ss_link = ss->next;
break;
}

ss_link = &ss->next;
ss = *ss_link;
}
release_program_space (pspace);

We use this _link pattern in several places.

OK with that change.

Thanks,
Pedro Alves