Version française
Home     About     Download     Resources     Contact us    
Browse thread
Wrapping a callback to OCaml code from C
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Wrapping a callback to OCaml code from C
On Fri, Jun 24, 2005 at 01:15:16PM +0200, Daniel Bünzli wrote:
> 
> Le 24 juin 05 à 12:40, Richard Jones a écrit :
> 
> >On Thu, Jun 23, 2005 at 10:47:33PM +0100, Richard Jones wrote:
> >[...]
> >
> >There was quite a delay in this posting appearing.  In the meantime I
> >think I've fixed the problem by adding CAMLparam0 .. CAMLlocal3 ..
> >CAMLreturn0 around the callback wrapper function.
> 
> I would like to understand why this is needed. Did you allocate  
> something with the gc in your Val_obj functions ?

Yes.  Val_obj is in fact a thin wrapper around this function:

static inline value
Val_voidptr (void *ptr, const char *)
{
  CAMLparam0 ();
  CAMLlocal1 (rv);
  rv = caml_alloc (1, Abstract_tag);
  Field (rv, 0) = (value) ptr;
  CAMLreturn (rv);
}

and of course callback_wrapper calls callback2 which calls into OCaml
code - rather a lot of allocation possibilities there!

Rich.

-- 
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com