[m-users.] Too Slow
Mark Brown
mark at mercurylang.org
Sat May 2 00:50:58 AEST 2015
Hi Matthias,
Thanks for starting the ball rolling...
On Fri, May 1, 2015 at 10:02 PM, Matthias Guedemann
<matthias.guedemann at googlemail.com> wrote:
> Hi,
>
> here is a version with some basic error handling, i.e., failing with a
> message if either creating an mp_int fails or an operation does not
> return MP_OKAY.
>
> Any information about problems, bugs etc. is welcome.
> :- pred mp_init(int::in, mp_result_type::out, mp_result_type::out,
> mp_int::out) is det.
> :- pragma foreign_proc("C",
> mp_init(Value::in, InitResult::out, OpResult::out,
> Mp_Int::out),
> [will_not_call_mercury, promise_pure, thread_safe],
> "
> int initResult, opResult;
> Mp_Int = MR_GC_NEW_ATTRIB(mp_int, MR_ALLOC_ID);
> initResult = mp_init(Mp_Int);
> opResult = mp_set_int(Mp_Int, Value);
> InitResult = initResult;
> OpResult = opResult;
> ").
You call mp_set_int before checking the result from mp_init, which
could be a problem.
Rather than return two foreign results it may be nicer to define a
Mercury enumeration of the possible errors and export it with
foreign_export_enum (sections 14.5, 14.10.1.2), then create the
appropriate Mercury value from the C code.
Cheers,
Mark.
More information about the users
mailing list