[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Gerd Stolpmann <gerd@g...> |
| Subject: | Re: [Caml-list] problem creating .cma library |
> For instance, here is the piece of code that executes R code ad catches
> errors. I've tried to follow guidelines available on the net, and
> inspired myself from pcre.
>
> > CAMLprim value r_eval_sxp (value sexp_list) {
> > CAMLparam0();
> > CAMLlocal2(ml_error_call, ml_error_message);
> > SEXP e;
> > int error = 0;
> > PROTECT(e = R_tryEval(Sexp_val(sexp_list), R_GlobalEnv, &error));
> > UNPROTECT(1);
> > if (error) {
> > ml_error_call = Val_sexp(error_call);
> > error_call = NULL;
> > ml_error_message = caml_copy_string(error_message);
> > error_message = NULL;
> > value error_result = caml_alloc_small(2, 0);
> > Store_field(error_result, 0, ml_error_call);
> > Store_field(error_result, 1, ml_error_message);
> > raise_with_arg(*caml_named_value("OCaml-R generic error"), error_result);
> > }
> > CAMLreturn(Val_sexp(e));
> > }
>
> Do you see GC / allocation / threading problems with it?
>
> Would it be legitimate to include CAMLlocal2 inside the error-handling
> braces?
No. You would start a new context for local roots, and there is no way
to end it (CAMLreturn ends the context).
There are the macros Begin_roots<n> and End_roots that should be used in
this case, e.g.
if (error) {
value ml_error_call = Val_unit;
value ml_error_message = Val_unit;
Begin_roots2(ml_error_call, ml_error_message);
...
End_roots();
raise_with_arg(...)
}
The macros are only documented in memory.h.
So far I know, raising an exception from within Begin_roots/End_roots is
not allowed.
Gerd
--
------------------------------------------------------------
Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany
gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de
Phone: +49-6151-153855 Fax: +49-6151-997714
------------------------------------------------------------