Re: [PATCH v2 2/5] Don't reset errno/bfd_error on 'throw_perror_with_name'

Pedro Alves
2020-03-27T18:20:52Z

On 3/17/20 3:47 PM, Sergio Durigan Junior via Gdb-patches wrote:

> the commit that "introduced" it is:
>
> commit c906108c21474dfb4ed285bcc0ac6fe02cd400cc
> Author: Stan Shebs <shebs@codesourcery.com>
> Date: Fri Apr 16 01:35:26 1999 +0000
>
> Initial creation of sourceware repository
>
> so yeah...

Given the previous discussions, I'd appreciate this comment was
updated/clarified.

>
> If we go to the POSIX specification for 'perror', it doesn't really
> say anything about whether errno should be preserved or not. It does,
> however, say that 'perror's messages should be the same as those
> returned by 'strerror', and 'strerror' is not supposed to alter errno
> if the call is successful.
>
> Maybe when our wrapper was written it was OK to modify errno, I don't
> know. But I'd like to propose that we stick to POSIX in this case.
>

This really has nothing to do with POSIX, because this isn't a
normal wrapper. Control is not returning, we're throwing. As I
mentioned before, we shouldn't be relying on errno being preserved
across throw/catch. For _that_ reason, I'm still OK with this patch,
(even though I disagree with the given rationale).

Thanks,
Pedro Alves