[ocaml-ctypes] Lifecycle of a callback?

Trevor Smith trevorsummerssmith at gmail.com
Tue Oct 21 13:24:41 BST 2014


Hi all,

In the libuv bindings I am working on there is need for user callbacks. A
user registers the callback with a function, and then at an arbitrary point
in time later, the callback code is actually ran (started when the user
starts the libuv event loop). I had naively thought that I would need to
keep a reference to the user callback and then release this reference after
the user callback was actually called (because the callback would be used
at an arbitrary point in the future and could get gc'd).

I made an example this morning to test this out, however I cannot get it to
fail (ie throw an CallToExpiredClosure).

Perhaps my assumption is wrong, and I do not have to keep around a
reference? Or my test is not testing what I think it is?

I see similar discussion that doesn't have a clear resolution here:
https://github.com/dbuenzli/tgls/issues/6 and
http://lists.ocaml.org/pipermail/ctypes/2013-December/000028.html

My test code is here:
https://github.com/trevorsummerssmith/ocaml-libuv/blob/test-lifecycle/test/test_lifecycle.ml

Test it: make && make tests # valgrind seems happy with it

I am running with libuv-1.0.0-rc1
https://github.com/joyent/libuv/tree/v1.0.0-rc1/ OCaml 4.0.2.1 and on a Mac
10.9.5

Thanks!

Trevor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/ctypes/attachments/20141021/48a6670a/attachment.html>


More information about the Ctypes mailing list