[m-rev.] diff: Fix use of MR_strerror.

Julien Fischer jfischer at opturion.com
Thu Oct 31 20:52:10 AEDT 2019


On Thu, 31 Oct 2019, Julien Fischer wrote:

> On Thu, 31 Oct 2019, Peter Wang wrote:
>
>>  Also, error_to_cerrno returning -1 for unknown(Err, Msg) seems like a
>>  weird choice.
>
> Yes, looking at that again, it's not really a great choice.  I'll change
> it to be semidet and only succeed for non-unknown errors.

On second thoughts, no I won't.  The unknown/2 alternative encodes the
original error number anyway, so we should just return that.

Here's a diff:

diff --git a/extras/posix/posix.m b/extras/posix/posix.m
index 9795b6a..5c27c82 100644
--- a/extras/posix/posix.m
+++ b/extras/posix/posix.m
@@ -172,8 +172,7 @@
  :- pred errno(posix.error::out, io::di, io::uo) is det.

      % error_to_cerrno(Error, CError):
-    % CError is the error number corresponding to Error, or -1 if Error is
-    % unknown_error/2.
+    % CError is the error number corresponding to Error.
      %
  :- pred error_to_cerrno(posix.error::in, int::out) is det.

@@ -226,7 +225,7 @@ error_to_num(Err) = Num :-
      ( if num_error(Num0, Err) then
          Num = Num0
      else
-        Num = (-1)
+        unexpected($pred, "cannot convert to posix.error")
      ).

  :- pred num_error(int, posix.error).
@@ -389,8 +388,12 @@ num_error(Num, Err) :-
      }
  ").

-error_to_cerrno(Errno, CErrno) :-
-    CErrno = num_to_cerrno(error_to_num(Errno)).
+error_to_cerrno(Error, CErrno) :-
+    ( if Error = unknown(CErrnoPrime, _) then
+        CErrno = CErrnoPrime
+    else
+        CErrno = num_to_cerrno(error_to_num(Error))
+    ).

  %-----------------------------------------------------------------------------%
  :- end_module posix.

Julien.


More information about the reviews mailing list