[m-rev.] for review: Allow user code to create io.error values with system errors.

Julien Fischer jfischer at opturion.com
Mon Aug 29 16:22:32 AEST 2022


On Mon, 29 Aug 2022, Peter Wang wrote:

> library/io.m:
>    Move make_io_error_from_system_error to public interface.
>
>    Add make_io_error_from_windows_error.
>
>    Rename is_maybe_win32_error to is_error_maybe_win32.
>    Make it take an argument to indicate whether the error is a Win32
>    error code.
>
>    Make make_io_error_from_maybe_win32_error (an internal predicate)
>    take an argument to indicate whether the error is a Win32
>    error code.
>
> library/dir.m:
>    Conform to changes.
>
> NEWS:
>    Announce recent system error related changes.
> ---
> NEWS          |   7 +++
> library/dir.m | 102 ++++++++++++++++++++++++++--------------
> library/io.m  | 128 ++++++++++++++++++++++++++++++--------------------
> 3 files changed, 149 insertions(+), 88 deletions(-)
>
> diff --git a/NEWS b/NEWS
> index d898dadb7..10b6dea53 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -101,6 +101,13 @@ Changes to the Mercury standard library
> 
> * The following predicates have been added:
> 
> +    - pred `make_io_error_from_system_error/5`
> +    - pred `make_io_error_from_windows_error/5`
> +    - pred `get_system_error/2`
> +    - pred `get_errno_error/2`
> +    - pred `get_windows_error/2`
> +    - pred `get_exception_object_error/2`
> +    - pred `get_system_error_name/2`
>     - pred `write_binary_string_utf8/3`
>     - pred `write_binary_string_utf8/4`

We should probably make a more general annoucment of this capability,
but that doesn't need to be done as part of this diff.

...

> diff --git a/library/io.m b/library/io.m
> index b9a8d91ef..70fdb5bcc 100644
> --- a/library/io.m
> +++ b/library/io.m
> @@ -2067,6 +2067,28 @@
>     %
> :- func make_io_error(string) = io.error.
> 
> +    % make_io_error_from_system_error(SystemError, Prefix, Error, !IO):
> +    %
> +    % Construct an io.error value given a system error and an error message
> +    % prefix, which may be the empty string. The error message will be
> +    % constructed by appending Prefix and the error message retrieved from the
> +    % system for SystemError.
> +    %
> +    % On C backends, the io.system_error must be an errno value.

I suggest adding that it must *not* be a Windows error code.

> +    % On C# and Java backends, the io.system_error must be an exception object.
> +    %

Given the way io.system_error is defined, it's impossible for it to be
anything else on those backends. I guess an additional requirement
of this predicate (in Java and C#) is that it be a non-null exception
object?

The rest looks fine.

Julien.


More information about the reviews mailing list