From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 5E4FDBC37 for ; Mon, 11 Jan 2010 13:12:48 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArQBAF+kSkvU4xEIkGdsb2JhbACBRJocAQEBAQkJDAcTA7kxAoQtBA X-IronPort-AV: E=Sophos;i="4.49,255,1262559600"; d="scan'208";a="41182244" Received: from moutng.kundenserver.de ([212.227.17.8]) by mail2-smtp-roc.national.inria.fr with ESMTP; 11 Jan 2010 13:12:48 +0100 Received: from office1.lan.sumadev.de (dslb-188-097-009-166.pools.arcor-ip.net [188.97.9.166]) by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis) id 0LmwP6-1O6vfd0pv2-00gyiN; Mon, 11 Jan 2010 13:12:39 +0100 Received: from [192.168.0.32] (dslb-084-058-051-010.pools.arcor-ip.net [84.58.51.10]) by office1.lan.sumadev.de (Postfix) with ESMTPSA id D01BBC0E8E; Mon, 11 Jan 2010 13:12:36 +0100 (CET) Subject: Re: [Caml-list] problem creating .cma library From: Gerd Stolpmann To: guillaume.yziquel@citycable.ch Cc: Richard Jones , 'caml-list List' In-Reply-To: <4B48D912.8090602@citycable.ch> References: <56670.41.177.16.252.1262195331.squirrel@41.177.16.252> <4B3BE288.4030701@citycable.ch> <3EE07409-9559-4B91-BA3E-8787D1378275@inria.fr> <4B47C201.7090201@citycable.ch> <4B47C59C.9080505@starynkevitch.net> <4B47C9BE.4060309@citycable.ch> <001f01ca9101$7ee76850$7cb638f0$@romulus.metastack.com> <4B486974.7060007@citycable.ch> <20100109125224.GC26610@annexia.org> <4B48D912.8090602@citycable.ch> Content-Type: text/plain Date: Mon, 11 Jan 2010 13:18:31 +0100 Message-Id: <1263212311.17350.15.camel@flake.lan.gerd-stolpmann.de> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 Content-Transfer-Encoding: 7bit X-Provags-ID: V01U2FsdGVkX19x1u8pwkcZFsJy0fAsupn5uHbcjvDtmcAUjaH TdDgLukR5gilwlb7BGhrebD2rrX+CnSzQGE90oaXM37bK92ekT xyAR/pmZ8b8palqel1nXQ== X-Spam: no; 0.00; gerd:01 stolpmann:01 gerd:01 pcre:01 camlprim:01 sexp:01 camlparam:01 sexp:01 val:01 val:01 alloc:01 camlreturn:01 threading:01 camlreturn:01 stolpmann:01 > 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 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 ------------------------------------------------------------