[m-dev.] diff: fix bug in try_io
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Dec 31 02:05:14 AEDT 1999
Estimated hours taken: 1
library/exception.m:
Fix a bug in try_io: it was using `pragma export',
but exception handling does not work across the
C interface.
Workspace: /home/mercury0/fjh/mercury
Index: library/exception.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/exception.m,v
retrieving revision 1.11
diff -u -d -r1.11 exception.m
--- exception.m 1999/12/21 10:33:57 1.11
+++ exception.m 1999/12/30 14:07:16
@@ -406,14 +406,24 @@
:- pred very_unsafe_perform_io(pred(T, io__state, io__state), T).
:- mode very_unsafe_perform_io(pred(out, di, uo) is det, out) is det.
:- mode very_unsafe_perform_io(pred(out, di, uo) is cc_multi, out)
- is det.
+ is cc_multi.
% Mercury doesn't support impure higher-order pred terms, so if we want
% to form a closure from unsafe_perform_io, as we need to do above,
% then we must (falsely!) promise that it is pure.
:- pragma promise_pure(very_unsafe_perform_io/2). % XXX this is a lie
very_unsafe_perform_io(Goal, Result) :-
- impure unsafe_perform_io(Goal, Result).
+ impure make_io_state(IOState0),
+ Goal(Result, IOState0, IOState),
+ impure consume_io_state(IOState).
+
+:- impure pred make_io_state(io__state::uo) is det.
+:- pragma c_code(make_io_state(_IO::uo),
+ [will_not_call_mercury, thread_safe], "").
+
+:- impure pred consume_io_state(io__state::di) is det.
+:- pragma c_code(consume_io_state(_IO::di),
+ [will_not_call_mercury, thread_safe], "").
:- pred wrap_exception(univ::in, exception_result(T)::out) is det.
wrap_exception(Exception, exception(Exception)).
@@ -1469,38 +1479,5 @@
io__write(StdErr, univ_value(Exception)),
io__nl(StdErr)
).
-
-/*
-** unsafe_perform_io/2 is the same as unsafe_perform_io/1
-** (see extras/trailed_update/unsafe.m)
-** except that it also allows the predicate to return an output argument.
-*/
-:- impure pred unsafe_perform_io(pred(T, io__state, io__state), T).
-:- mode unsafe_perform_io(pred(out, di, uo) is det, out) is det.
-:- mode unsafe_perform_io(pred(out, di, uo) is cc_multi, out) is det.
-
-:- pragma c_code(
-unsafe_perform_io(P::(pred(out, di, uo) is det), X::out),
- may_call_mercury,
-"{
- ML_exception_call_io_pred_det(TypeInfo_for_T, P, &X);
-}").
-:- pragma c_code(
-unsafe_perform_io(P::(pred(out, di, uo) is cc_multi), X::out),
- may_call_mercury,
-"{
- ML_exception_call_io_pred_cc_multi(TypeInfo_for_T, P, &X);
-}").
-
-:- pred call_io_pred(pred(T, io__state, io__state), T, io__state, io__state).
-:- mode call_io_pred(pred(out, di, uo) is det, out, di, uo) is det.
-:- mode call_io_pred(pred(out, di, uo) is cc_multi, out, di, uo) is cc_multi.
-
-:- pragma export(call_io_pred(pred(out, di, uo) is det, out, di, uo),
- "ML_exception_call_io_pred_det").
-:- pragma export(call_io_pred(pred(out, di, uo) is cc_multi, out, di, uo),
- "ML_exception_call_io_pred_cc_multi").
-
-call_io_pred(P, X) --> P(X).
%-----------------------------------------------------------------------------%
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list