[m-rev.] for post-commit review: io.environment.m and io.call_system.m

Peter Wang novalazy at gmail.com
Tue Mar 8 12:59:39 AEDT 2022


On Tue, 08 Mar 2022 11:36:52 +1100 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> 
> Given that decode_system_command_exit_code is used
> in two modules, and does not seems to require any implementor-
> level understanding to use, should we make it a *documented*
> part of io.call_system.m?

Yes, I think that would be fine. Let's see what Julien thinks.

> @@ -262,6 +274,59 @@ call_system_return_signal(Command, Result, !IO) :-
>      }
>  ").
>  
> +%---------------------------------------------------------------------------%
> +
> +decode_system_command_exit_code(Code0) = Status :-
> +    do_decode_system_command_exit_code(Code0, Exited, ExitCode, Signalled,
> +        Signal),
> +    (
> +        Exited = yes,
> +        Status = ok(exited(ExitCode))
> +    ;
> +        Exited = no,
> +        (
> +            Signalled = yes,
> +            Status = ok(signalled(Signal))
> +        ;
> +            Signalled = no,
> +            Status = error(io_error("unknown result code from system command"))
> +        )
> +    ).
> +
> +    % Interpret the child process exit status returned by system() or wait():
> +    %
> +:- pred do_decode_system_command_exit_code(int::in, bool::out, int::out,
> +    bool::out, int::out) is det.
> +
> +:- pragma foreign_proc("C",
> +    do_decode_system_command_exit_code(Status0::in, Exited::out, Status::out,
> +        Signalled::out, Signal::out),
> +    [will_not_call_mercury, thread_safe, promise_pure,
> +        does_not_affect_liveness, no_sharing],
> +"
> +    Exited = MR_NO;
> +    Status = 0;
> +    Signalled = MR_NO;
> +    Signal = 0;
> +
> +    #if defined (WIFEXITED) && defined (WEXITSTATUS) && \
> +            defined (WIFSIGNALED) && defined (WTERMSIG)
> +        if (WIFEXITED(Status0)) {
> +            Exited = MR_YES;
> +            Status = WEXITSTATUS(Status0);
> +        } else if (WIFSIGNALED(Status0)) {
> +            Signalled = MR_YES;
> +            Signal = -WTERMSIG(Status0);

This is a pre-existing bug: the signal number will be returned as a
negative number. I'll fix it.

Peter


More information about the reviews mailing list