I’m trying to define some Julia callbacks to give to a C library, but hit some strange crashes when those functions are invoked. In an attempt to pin down the problem I have created a very simple project which still crashes Julia.
This happens in both 1.7.2 and 1.8.5.
The buggy module is defined like this:
module bug_ccall
@noinline get_value(i::Int64)::Int64 = i * 27
const GET_VALUE = @cfunction(get_value, Int64, (Int64, ))
pretend_c_call(i) = ccall(GET_VALUE, Int64, (Int64, ), Int64(i))
println("While compiling module: ", pretend_c_call(2))
end # module
When I compile this module, I get the expected printout:
While compiling module: 54
However, when I invoke the ccall from outside the module, I get a crash:
PS C:\Users\manni\Documents\tep\bug_ccall> julia --project=. -e 'using bug_ccall; println(:outside_the_module_, bug_ccall.pretend_c_call(4))'
While compiling module: 54
Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x5ece0ac0 -- unknown function (ip: 000000005ece0ac0)
in expression starting at none:1
unknown function (ip: 000000005ece0ac0)
Allocations: 2723 (Pool: 2712; Big: 11); GC: 0
Am I misunderstanding something? What is the correct way to use a @cfunction
from another module?