-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
need way to convert jl_value_t* back to Any for callbacks #2458
Comments
@vtjnash, Doesn't seem to work quite properly. e.g.:
when I would have expected |
hmm, true. I treated |
See my comment in e8d6ba3. |
I'm still not convinced that patch was wrong. Although when you add support to cfunction for Any, the importance of that point should be sufficiently diminished to consider this resolved. |
It seems obvious to me that |
@JeffBezanson, allowing For example, in Python a I can understand that it seems inconsistent to call a |
@stevengj If it is boxed, does that imply you have the necessary indirection container to just use @JeffBezanson, you specified that unsafe_ref for the Any type was initially an error so that it could be defined in the most useful way later. An Array of Any's is boxed to contain pointers. The special case in base is just to make it more convenient to users to express them as values, but still flexible on the backend for alternative behaviors. I think this may be a better solution: https://github.com/JuliaLang/julia/tree/jn/ref_any |
Ok, then what is needed is a way to convert There is no way the It seems to me As I said, don't read too much into the "special case" of |
RFC: add unsafe_pointer_to_any (fixes #2458)
ccall allows you to pass
Any
for an argument type, which causes the rawjl_value_t*
to the boxed argument to be passed through to the C routine. This is very useful for callingjl_
functions and other C functions that are aware of the Julia API.It would also be very useful for passing true closures (issue #1096) and other Julia objects through to callbacks (many C callback APIs allow one to pass an arbitrary
void*
through to the callback). However, there needs to be a way to convert thejl_value_t*
back toAny
in Julia.e.g. an
unsafe_pointer_to_any(p)
function, orunbox(Any, p::Ptr{Void})
, or something like that.It would be trivial to code this by adding a C function like:
to
jlapi.c
, and then doingbut this seems like a slightly silly way to implement it. However, I'm not sure where to put in a lower-level hook to do the conversion (or if this is already possible).
The text was updated successfully, but these errors were encountered: