-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
ccall does not support non-const library names #2316
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
Comments
A slightly less ugly hack would be to fall back on |
Good point, thanks for the tip! I still find it frustrating that |
part of the problem with ccall is that a lot of it must be known at compile time to be efficient. the restriction on having the symbol lookup be const is supposed to hint that changing the variable might not have an effect, and would be much slower if allowed (the library name is cached at compile-time for efficiency). it's possible to allow the library to be non-constant, but this would force a call to dlsym every time, since we don't know when or if the library name will ever change. c-functions I'm interested to hear if you have ideas for how to make this easier, without introducing another performance trap |
Even though the python shared library name is not known until runtime, there's nothing that prevents you from forming the code that needs to know that name afterwards, and then compiling it, e.g. by passing function definitions to |
Fortunately, the |
Since |
|
Tk and Cairo have a similar problem, which I solved using this quick hack at the time. We should probably either make it official/document it or think of a better way. |
For PyCall, I need to determine the Python shared library name at runtime (by calling
python
and querying itsLDLIBRARY
), butccall
does not allow the library name to be a non-const
variable:gives
ERROR: type: anonymous: in ccall: function argument not a pointer or valid, constant expression, expected BitsKind, got (AbstractKind,)
However, as an ugly hack:
seems to sort of work (Julia allows me to modify
libpython
even though I declared itconst
, which seems mildly horrifying and likely to break in future versions). But from struggling to use this hack in a module, it seems like it breaks easily even now.Please provide a way to do this properly.
PS. The more I use
ccall
the more I hate that it behaves so differently from an ordinary function call. No splicing (#1313), apparently no macros or functions of any kind in some of the arguments, and probably there are other limitations I haven't noticed yet. All of this goofiness seems like a bug to me.The text was updated successfully, but these errors were encountered: