[m-rev.] for review: add system_error_is_success/1
Julien Fischer
jfischer at opturion.com
Sun Feb 12 20:48:49 AEDT 2023
For review by anyone.
----------------------
Add system_error_is_success/1.
library/io.m:
As above.
library/io.error_util.m:
Delete the equivalent operation is_success/1 from here and
just use system_error_is_success/1 instead.
NEWS.md:
Announce the new predicate.
Julien.
diff --git a/NEWS.md b/NEWS.md
index c211a7e..f103fe2 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -302,6 +302,7 @@ Changes to the Mercury standard library
- pred `get_windows_error/2`
- pred `get_exception_object_error/2`
- pred `get_system_error_name/2`
+ - pred `system_error_is_success/1`
- func `init_posn/0`
- pred `write_binary_string_utf8/3`
- pred `write_binary_string_utf8/4`
diff --git a/library/io.error_util.m b/library/io.error_util.m
index 3679619..8371dd4 100644
--- a/library/io.error_util.m
+++ b/library/io.error_util.m
@@ -118,35 +118,10 @@
Error = null;
").
-:- pred is_success(system_error::in) is semidet.
-:- pragma inline(pred(is_success/1)).
-
-:- pragma foreign_proc("C",
- is_success(Error::in),
- [will_not_call_mercury, promise_pure, thread_safe],
-"
- // This works for errno and Win32 error values (ERROR_SUCCESS == 0).
- SUCCESS_INDICATOR = (Error == 0) ? MR_TRUE : MR_FALSE;
-").
-
-:- pragma foreign_proc("C#",
- is_success(Error::in),
- [will_not_call_mercury, promise_pure, thread_safe],
-"
- SUCCESS_INDICATOR = (Error == null);
-").
-
-:- pragma foreign_proc("Java",
- is_success(Error::in),
- [will_not_call_mercury, promise_pure, thread_safe],
-"
- SUCCESS_INDICATOR = (Error == null);
-").
-
:- pragma inline(pred(is_error/5)).
is_error(Error, Prefix, MaybeError, !IO) :-
- ( if is_success(Error) then
+ ( if system_error_is_success(Error) then
MaybeError = no
else
make_io_error_from_system_error_impl(Error, Prefix, IOError, !IO),
@@ -154,7 +129,7 @@ is_error(Error, Prefix, MaybeError, !IO) :-
).
is_error_maybe_win32(Error, IsWin32Error, Prefix, MaybeError, !IO) :-
- ( if is_success(Error) then
+ ( if system_error_is_success(Error) then
MaybeError = no
else
make_io_error_from_maybe_win32_error(Error, IsWin32Error, Prefix,
@@ -222,7 +197,7 @@ throw_on_close_error(Error, !IO) :-
throw_on_error(Error, Prefix, !IO) :-
% This follows the logic of is_error, but does not construct
% a MaybeError as an intermediate data structure.
- ( if is_success(Error) then
+ ( if system_error_is_success(Error) then
true
else
make_io_error_from_system_error_impl(Error, Prefix, IOError, !IO),
diff --git a/library/io.m b/library/io.m
index 373329c..b8d1b19 100644
--- a/library/io.m
+++ b/library/io.m
@@ -2147,6 +2147,11 @@
%
:- pred get_system_error_name(io.error::in, string::out) is semidet.
+ % Succeeds if the given system error value corresponds to the lack of an
+ % error.
+ %
+:- pred system_error_is_success(io.system_error::in) is semidet.
+
%---------------------------------------------------------------------------%
%
% Instances of the stream typeclasses.
@@ -5037,6 +5042,31 @@ system_error_exception_name(_, _) :-
error("io.system_error_exception_name: inapplicable back-end").
%---------------------------------------------------------------------------%
+
+:- pragma inline(pred(system_error_is_success/1)).
+:- pragma foreign_proc("C",
+ system_error_is_success(Error::in),
+ [will_not_call_mercury, promise_pure, thread_safe],
+"
+ // This works for errno and Win32 error values (ERROR_SUCCESS == 0).
+ SUCCESS_INDICATOR = (Error == 0) ? MR_TRUE : MR_FALSE;
+").
+
+:- pragma foreign_proc("C#",
+ system_error_is_success(Error::in),
+ [will_not_call_mercury, promise_pure, thread_safe],
+"
+ SUCCESS_INDICATOR = (Error == null);
+").
+
+:- pragma foreign_proc("Java",
+ system_error_is_success(Error::in),
+ [will_not_call_mercury, promise_pure, thread_safe],
+"
+ SUCCESS_INDICATOR = (Error == null);
+").
+
+%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
%
% For use by library.m.
More information about the reviews
mailing list