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 nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 759E0BB81 for ; Wed, 22 Feb 2006 22:36:55 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k1MLasjD008242 for ; Wed, 22 Feb 2006 22:36:55 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA01723 for ; Wed, 22 Feb 2006 22:36:54 +0100 (MET) Received: from smtp104.sbc.mail.mud.yahoo.com (smtp104.sbc.mail.mud.yahoo.com [68.142.198.203]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id k1MLaqEC008239 for ; Wed, 22 Feb 2006 22:36:53 +0100 Received: (qmail 38236 invoked from network); 22 Feb 2006 21:36:52 -0000 Received: from unknown (HELO ?192.168.1.100?) (rftp@pacbell.net@69.230.226.66 with plain) by smtp104.sbc.mail.mud.yahoo.com with SMTP; 22 Feb 2006 21:36:52 -0000 Message-ID: <43FCD98E.30600@rftp.com> Date: Wed, 22 Feb 2006 13:37:18 -0800 From: Robert Roessler User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20060217 SeaMonkey/1.5a MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] c binding question References: <200602220909.55592.micha-1@fantasymail.de> In-Reply-To: <200602220909.55592.micha-1@fantasymail.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 43FCD976.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 43FCD974.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 char:01 datatype:01 lib:01 char:01 pcre:01 pointer:01 struct:01 wrote:01 abstract:01 essentially:01 data:02 parameter:02 variables:02 binding:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Michael Wohlwend wrote: > I want to make an interface to a c-lib in which some function take a char* as > a parameter and store this paramenter in their internal variables. > I have done this this way: > > I copy the ocaml-string to a new c-string and I allocated a custom block to > store the abstract datatype of the lib together with the allocated char* for > that string. The finalize function of that custom block releases the > allocated memory of the string and cleans up the rest... > > Is this the correct way to do this? Sounds reasonable to me - this is essentially what I do in LablPCRE. In that case, the PCRE regcomp call fills in a local data structure with (among other things) a pointer to malloc'ed storage... a custom block is created, the struct is copied into it, and then a finalize function uses PCRE's regfree call to clean up. Robert Roessler roessler@rftp.com http://www.rftp.com