-
-
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
efficient interface for accessing an external c variable's value #1815
Comments
Ok, this seems like a good idea. I used to prefer |
cglobal sounds good However, I'm not certain this signature would actually be correct (removing the implicit unsafe_ref call): to allow unsafe_assign, there could be a optional third parameter that did assignment (and also returned the new value)? there could be an expectation that, like ccalls, there would be wrapper functions written for common variables |
Good points. |
I woild prefer cvar or cval. On Friday, December 21, 2012, Jeff Bezanson wrote:
|
We should add the following types:
This generalizes |
I think you guys are overthinking this.
In many cases, you might not even be dereferencing the pointer at all; you might just be passing it to other C API functions. (For example, in the Python API, various Python types, e.g The only other interface I would optionally consider adding would be The user can wrap other abstractions on top of a C global if needed. |
Yes, you're probably right. That interface looks good. |
I'm not at all certain of the implications of this but I hope it still makes it possible to ccall a C function pointer returned by an earlier ccall. |
@GunnarFarneback, I don't think |
Ah, that is better. For some reason, I had thought it wouldn't be possible to generate the pointer in a different JIT invokation from its use, so I had proposed something complicated, but this seems to do it. |
…sign -> unsafe_load/store! in the manual
proposed api (new built-in):
cvalue( (:sym, :lib), Type ) :: Type
functionally equivalent to
unsafe_ref( convert( Ptr{T}, dlsym( :sym, dlopen(:lib) ) ) )
but with only the unsafe_ref call occurring at runtime, the rest being converted into a llvm global at compile time (similar to the first argument to ccall)
additionally, another valuable function would be
cexists( (:sym, :lib) ) :: Bool
then I think dlsym/dlopen can be removed from the language?
The text was updated successfully, but these errors were encountered: