Closed NicolasT closed 3 months ago
Now I want to
caml_callback
thiscb
closure, passing int
(the C pointer). Is this possible?
It's probably easier to call cb
through a C function pointer. There are some examples in the test-funptrs
and test-higher_order
test suites:
https://github.com/yallop/ocaml-ctypes/tree/master/tests/test-funptrs https://github.com/yallop/ocaml-ctypes/tree/master/tests/test-higher_order
Consider the following:
Type
t
represents astruct t *
defined in some C library. In this C code, I somehow get a reference tocb
, and have astruct t *t
available. Now I want tocaml_callback
thiscb
closure, passing int
(the C pointer). Is this possible?When declaring a stub for a function which takes a
t
, the generated C code containsvoid *x2 = CTYPES_ADDR_OF_FATPTR(x1)
, so it appears in the C code doing thecaml_callback
I somehow need to wrap mystruct t
pointer in a "fat pointer" (a record with 3 fields). However, whereCTYPES_FROM_PTR
andCTYPES_TO_PTR
exist, there seems to be no equivalent for these "fat pointers".Am I overlooking something? Or should I somehow not use
unit ptr
and instead try something usingCtypes_ptr.voidp
?