[ocaml-ctypes] Lifecycle of a callback?

Jeremy Yallop yallop at gmail.com
Thu Oct 23 12:58:35 BST 2014


On 23 October 2014 11:48, Trevor Smith <trevorsummerssmith at gmail.com> wrote:
> I tried this out this morning. However I am seeing strange behavior with the
> memory addresses. In native code, whenever I pass a pointer through the
> accessor I receive a different address than the original address -- however,
> in valgrind the addresses are the same.
>
> Relevant code:
> git clone git at github.com:trevorsummerssmith/ocaml-libuv.git && cd
> ocaml-libuv && git checkout origin/test-lifecycle && make tests
>
> I see, eg:
>
> loop: 0x109d76800
> Handle: 0x9d76800
> Handle: 0x9d76800
> F.
> ==============================================================================
> Failure: handle suite:0:accessors
>
> The loop address always starts with '10'. However in valgrind the addresses
> are the same.
>
> The c accessors are in lib_gen/lib_accessors.c, the test is in
> test/test_handle.ml

The code generated by ctypes doesn't have declarations  for your
accessor functions in scope, so the C compiler helpfully assumes that
the functions return (32-bit) ints rather than (64-bit) pointers,
leading to garbage in the upper bits.  You should be able to fix the
problem by outputting suitable declarations (perhaps by including a
header) in libuv_bindgen.ml.


More information about the Ctypes mailing list