English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
c binding question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-02-22 (21:36)
From: Robert Roessler <roessler@r...>
Subject: Re: [Caml-list] c binding question
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