-
-
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
allow ccall library name to be non-constant #37123
Conversation
Fantabulous! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to work, though as you mention, still an awful hack. Not great that if the user makes a slight mistake, the ccall
will just segfault.
julia> f(x) = (y = x + 1; ccall((:a, y), Cvoid, ()))
f (generic function with 1 method)
julia> f(1)
signal (11): Segmentation fault: 11
Is it possible to instead modify the new @ccall
macro to let us do this without the syntactic ambiguity?
Should also document that the user code may be called multiple times and it's undefined behavior if they return different values. |
a6d0bf7
to
83b708e
Compare
I added a check to replace some of the more likely crashes with a lowering error. AFAICT everything caught by this error used to segfault, so it should be ok. |
83b708e
to
7191c3a
Compare
12e7653
to
a129e73
Compare
a129e73
to
0c06281
Compare
be executed when the `ccall` itself is executed. However, it is assumed that the library | ||
location does not change once it is determined, so the result of the call can be cached and | ||
reused. Therefore, the number of times the expression executes is undefined, and returning | ||
different values for multiple calls results in undefined behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UB has a rather strong connotation, when this seems merely unspecified?
gvname += f_name; | ||
gvname += "_"; | ||
gvname += std::to_string(globalUnique++); | ||
Module *M = ctx.emission_context.shared_module(jl_LLVMContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems odd to explicitly share a private variable. This could go in jl_Module
Yay! 🎉 |
Fixes #36458.
This is a bit ugly since
ccall
still has non-standard IR with call expressions nested inside it. The nice part is that we can piggyback on the existing caching mechanism, and still do only one NULL pointer check.cc @staticfloat