Hi everyone,
I’m working on a PR to extend MPI.jl, which is a Julia package ccalling into a C/Fortran library.
I need to store inside my module a constant Ref{Ptr{Cvoid}}
. Since the precompiler actually clears the value of all pointers, I learned that I must do it in the __init__
method of my Module.
Unfortunately, this does not seem to work unless I use an eval
call, which breaks incremental compilation, and as such I want to avoid it.
For example, consider the following package:
bash> mkdir -p MyModule/src && echo "
module MyModule
const a = Ref{Ptr{Cvoid}}()
const b = Ref{Ptr{Cvoid}}()
function __init__()
a[] = Ptr{Cvoid}(1)
eval(:(b[] = 1))
end
end" >> MyModule/src/MyModule.jl && cd MyModule
then, if you dev it and using
it (which is necessary to trigger a precompilation), you will see that a
has been reset:
julia> ] dev .
julia> using MyModule
julia> MyModule.a
Base.RefValue{Ptr{Nothing}}(Ptr{Nothing} @0x0000000000000000)
julia> MyModule.b
Base.RefValue{Ptr{Nothing}}(Ptr{Nothing} @0x0000000000000001)
How can I set this variable without using an eval
call?
–