caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gerd Stolpmann <gerd@gerd-stolpmann.de>
To: guillaume.yziquel@citycable.ch
Cc: Richard Jones <rich@annexia.org>,
	'caml-list List' <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] problem creating .cma library
Date: Mon, 11 Jan 2010 13:18:31 +0100	[thread overview]
Message-ID: <1263212311.17350.15.camel@flake.lan.gerd-stolpmann.de> (raw)
In-Reply-To: <4B48D912.8090602@citycable.ch>

> 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
------------------------------------------------------------


  reply	other threads:[~2010-01-11 12:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-30 17:48 rouanvd
2009-12-30 23:30 ` [Caml-list] " Guillaume Yziquel
2010-01-05 13:04   ` Damien Doligez
2010-01-08 23:38     ` Guillaume Yziquel
2010-01-08 23:54       ` Basile STARYNKEVITCH
2010-01-09  0:11         ` Guillaume Yziquel
2010-01-09  7:58           ` David Allsopp
2010-01-09 11:33             ` Guillaume Yziquel
2010-01-09 12:52               ` Richard Jones
2010-01-09 14:00                 ` Daniel Bünzli
2010-01-09 14:02                   ` Daniel Bünzli
2010-01-09 14:21                     ` Joel Reymont
2010-01-09 19:36                   ` Guillaume Yziquel
2010-01-10  2:11                     ` Daniel Bünzli
2010-01-11 17:14                       ` Guillaume Yziquel
2010-01-10 13:31                     ` ygrek
2010-01-11 18:01                       ` Guillaume Yziquel
2010-01-09 19:29                 ` Guillaume Yziquel
2010-01-11 12:18                   ` Gerd Stolpmann [this message]
2010-01-11 17:11                     ` Guillaume Yziquel
2010-01-20 14:42                   ` Damien Doligez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1263212311.17350.15.camel@flake.lan.gerd-stolpmann.de \
    --to=gerd@gerd-stolpmann.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=guillaume.yziquel@citycable.ch \
    --cc=rich@annexia.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).