Yes, `Any` is what to use for passing through a julia value pointer.
It will not be copied, and is guaranteed to be referenced for the
duration of the ccall. If you need it referenced longer than that, you
need to keep a reference somewhere manually.
Always use Ptr{Void} for void*. That will even work in both 0.3 and 0.4.
On Wed, Feb 25, 2015 at 3:39 PM, Kirill Ignatiev
<[email protected]> wrote:
> I have a C function that expects an opaque void* pointer to hold some user
> data. This is specifically about a small problem with Sundials.jl, but it's
> also unclear to me generally.
>
> How do I safely pass a Julia value to the function? What are the
> conventions? The value will later be passed to Julia callbacks, so it needs
> to remain valid forever. I don't mind leaking it, if necessary.
>
> The function CVodeUserData in Sundials.jl expects either
>
> (Ptr{None}, Ptr{None})
>
> or
>
> (Ptr{None}, Any)
>
> (the 2nd argument is the Julia value, the first is library's internal
> structure).
>
> Which of these is correct? The original code for CVodeUserDataB seems to use
> Ptr{None} (why not Ptr{Void} or Any?), but I keep getting an error saying
> that my Julia has no method matching convert(::Type{Ptr{Union()}},
> ::MyType).
>
> Is Any the correct type for a Julia value to be passed to C? Will the value
> be moved or deallocated?