caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* c binding question
@ 2006-02-22  8:09 Michael Wohlwend
  2006-02-22 21:37 ` [Caml-list] " Robert Roessler
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Wohlwend @ 2006-02-22  8:09 UTC (permalink / raw)
  To: caml-list

Hi,

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? 

thanks,
 Michael


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] c binding question
  2006-02-22  8:09 c binding question Michael Wohlwend
@ 2006-02-22 21:37 ` Robert Roessler
  0 siblings, 0 replies; 2+ messages in thread
From: Robert Roessler @ 2006-02-22 21:37 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-02-22 21:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-22  8:09 c binding question Michael Wohlwend
2006-02-22 21:37 ` [Caml-list] " Robert Roessler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).