From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 42415BC6D for ; Wed, 9 May 2007 11:39:04 +0200 (CEST) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.234]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l499d2I3019254 for ; Wed, 9 May 2007 11:39:03 +0200 Received: by wx-out-0506.google.com with SMTP id s16so123274wxc for ; Wed, 09 May 2007 02:39:02 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=PR1r0cCI3AxRrsVn+O1+5Ev4snow67DtKPvr4mku/1blwBlh8AXajveiXFj2ezD1NNemoz/ENeFOJjtA+EGrU9QrwKUJMDfxDo5rLENkoyaS3je2h+iGfNrSRmmaapRdsFEYgulsMm1zHwaEEdVy69OmQzQNnnKQ25/ff/TaFKA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=RS+plV2Qt73GzEKuuEAoeox8O5VYgZseatEGLPz7wyr6yRjeaa1nlzRI0H4Arhs+PNvh8TnCc0OiqpTmz5DeBCP8K57wgBYMznY09zpHDEHH74oDTW/3SHZDWDqhYcqPokIU57mrx8ayGDdNv5S8Mv2CRUWD+BomGuvNg52Nq08= Received: by 10.90.81.14 with SMTP id e14mr103452agb.1178703542319; Wed, 09 May 2007 02:39:02 -0700 (PDT) Received: by 10.90.31.11 with HTTP; Wed, 9 May 2007 02:39:02 -0700 (PDT) Message-ID: <95513600705090239v6e05e802o729b77cc7a24da7c@mail.gmail.com> Date: Wed, 9 May 2007 11:39:02 +0200 From: "Olivier Andrieu" Sender: oandrieu@gmail.com To: "Jean-Marc EBER" Subject: Re: [Caml-list] question about the OCaml/C interface Cc: "Ocaml Mailing List" In-Reply-To: <46419449.5090404@lexifi.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <46419449.5090404@lexifi.com> X-Google-Sender-Auth: da63501fa0e5c2fb X-Miltered: at concorde with ID 464196B6.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; andrieu:01 oandrieu:01 ocaml:01 lexifi:01 ocaml:01 camlprim:01 alloc:01 camlreturn:01 allocates:01 val:01 mlsize:01 val:01 jeanmarc:01 eber:01 eber:01 Hi, On 5/9/07, Jean-Marc EBER wrote: > Hello to all, > > I have a little technical question about the OCaml/C interface: > > Is the following code "correct": yes > CAMLprim value my_func(...) > { > CAMLlocal2(ret); > ... > result = ... > ret = caml_alloc(5, 0); > Store_field(ret, 0, caml_copy_double(result)); > ... > CAMLreturn (ret); > } > > or, arguing that [caml_copy_double] allocates and may therfore launch a gc cycle > that may therefore modify [ret], one must write: no, that's the whole point of this Store_field macro, cf. its definition: #define Store_field(block, offset, val) do{ \ mlsize_t caml__temp_offset = (offset); \ value caml__temp_val = (val); \ caml_modify (&Field ((block), caml__temp_offset), caml__temp_val); \ }while(0) -- Olivier