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=0.0 required=5.0 tests=none 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 D1D3EBC69 for ; Wed, 28 Mar 2007 14:50:37 +0200 (CEST) Received: from mta5.srv.hcvlny.cv.net (mta5.srv.hcvlny.cv.net [167.206.4.200]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2SCob1b004055 for ; Wed, 28 Mar 2007 14:50:37 +0200 Received: from [192.168.15.101] (ool-457da870.dyn.optonline.net [69.125.168.112]) by mta5.srv.hcvlny.cv.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTP id <0JFM00DNT6CBTY00@mta5.srv.hcvlny.cv.net> for caml-list@inria.fr; Wed, 28 Mar 2007 08:50:36 -0400 (EDT) Date: Wed, 28 Mar 2007 08:53:30 -0500 From: Serge Aleynikov Subject: Re: [Caml-list] Wrapping OCaml function returning a variant In-reply-to: To: Joel Reymont Cc: Caml List Message-id: <460A735A.3040102@hq.idt.net> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT References: <460A65AB.8020902@hq.idt.net> User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) X-Miltered: at concorde with ID 460A649D.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 alloc:01 ocaml's:01 ocaml:01 pointer:01 28,:98 2007,:98 heap:01 heap:01 garbage:01 wrote:01 wrote:01 caml-list:01 opaque:01 strings:01 Joel Reymont wrote: > > On Mar 28, 2007, at 1:55 PM, Serge Aleynikov wrote: > >> If you are using caml_copy_string() or caml_alloc_string() they >> allocate strings on OCaml's heap, and will be automatically garbage >> collected. > > How do I pass a C string into OCaml if the assumption is that it will > not be modified? Do I still need to copy it with caml_copy_string? If you need to be able to access your C string value from OCaml, caml_copy_string is what you need. OTOH, if you want the string to be passed to OCaml as an opaque type (in which case OCaml won't be able to access its value directly, though the value will live on the C heap and can only be accessible from C) you can pass the string pointer using a Custom block (see section 18.9.2 http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html). Regards, Serge