[ocaml-ctypes] ptr ptr argument
Daniel Bünzli
daniel.buenzli at erratique.ch
Wed Dec 18 16:21:42 GMT 2013
Not sure what is your problem is exactly (be more specific in your questions). But the following notes may answer.
First if zframe is abstract (and since it always seem to be allocated allocated by the C side) there no need to actually describe it as structure, just declare it that way:
type zframe = unit ptr
let zframe : zframe typ = ptr void
let zframe_opt : zframe option typ = ptr_opt void
we're using zframe to denote pointer on zframe_t, then:
> let create msg =
> let stub = foreign "zframe_new"
> (string @-> size_t @-> returning (ptr_opt Structs._zframe_t))
> in
> let msg_size = Size_t.of_int (String.length msg) in
> stub msg msg_size
This will generate the binding to zframe_new on each call to create. Better is to do:
let zframe_new =
foreign "zframe_new" (string @-> size_t @-> returning zframe_opt)
let zframe_new data =
zframe_new data (Size_t.of_int (String.length data))
Then
let zframe_send =
foreign "zframe_send" (ptr zframe @-> ptr void @-> int @-> returning int)
let zframe_send frame socket flags =
let fptr = allocate (ptr zframe) frame in
zframe_end fptr socket flags
Best,
Daniel
More information about the Ctypes
mailing list