JuliaLang/julia — pull request #2468 by stevengj (2013-03-05 03:54:27+00:00)
Title: RFC: add unsafe_pointer_to_any (fixes #2458)

This adds a function `unsafe_pointer_to_any(p::Ptr)` that takes a boxed `jl_value_t*` and converts it back to a Julia `Any`. It works by adding a new `pointerany` intrinsic.

This is useful in callback functions, because raw `jl_value_t*` pointers to boxed Julia types can be passed as `void*` to C functions by declaring the argument as `Any`, but there was previously no way to undo this conversion to get back the native Julia object.

In particular, it should be quite useful in implementing closures, as discussed [on the mailing list](https://groups.google.com/forum/#!topic/julia-dev/9FRwq3hVwgA).