On 27 May 2014 01:21, Florian Pichlmeier <[email protected]> wrote: > i changed the representation of zframe_t > > type frame > type t = frame structure ptr > let zframe_t : frame structure typ = structure "_zframe_t"
Looks good! >> Although 'zframe_t' is incomplete, 'ptr zframe_t' (i.e. zframe_t*) is >> complete, so pointer arithmetic (with +@ etc.) should work as you >> expect. > > I tried this approach with pointer arithmetic (+@), but i still get > the Static.IncompleteType exception when i call the destroy function. > > let destroy (msg : t) = > let stub = foreign "zframe_destroy" ((ptr zframe_t) @-> returning int) in > stub (msg +@ 0) > > Another problem is, that the zframe_destroy function expects **zframe_t as > input, > but with msg +@ 0 i only get *zframe_t. Does it suffice to declare the > function > like i did above, or do i need another approach? Right: this is the source of the difficulty. The argument to the C function is a pointer to pointer: void zframe_destroy(frame_t **) and so the argument in the ctypes binding needs two 'ptr' applications: let stub = foreign "zframe_destroy" (ptr (ptr zframe_t) @-> returning void) In order to call the function you'll need to store the argument in addressable memory. For example, you might write: let p = allocate (ptr zframe_t) msg in stub p Jeremy. _______________________________________________ Ctypes mailing list [email protected] http://lists.ocaml.org/listinfo/ctypes
