Is there a way to use pointer to Julia function in ccall? Following the documentation https://docs.julialang.org/en/stable/manual/calling-c-and-fortran-code/ the kernel (Julia 0.5.1) crashes (and there is no alias for C void in Julia). Obviously, the example from documentation works.
# Julia C-like function void(__stdcall*)(float progress);
function clbProgress(f::Float32)
print(f)
return Void
end
function progress(fnc::Ptr{Void}, progress::Float32)
fnc != Ptr{Void}(0) && ccall(fnc, Void, (Float32, ), progress)
end
const fnc_c = cfunction(clbProgress, Void, (Ref{Cfloat})) # here the 0.5.1 kernel crashes
progress(fnc_c, 0.1f0)
The crash is due to the fact that the list of input types should be a tuple and a one-element tuple is indicated by (x,). In addition, you have to indicate the type of the return value, which is Type{Void}, not Void itself:
function clbProgress(f::Float32)
print(f)
return Void
end
function progress(fnc::Ptr{Void}, progress::Float32)
fnc != C_NULL && ccall(fnc, Type{Void}, (Float32, ), progress)
end
const fnc_c = cfunction(clbProgress, Type{Void}, (Ref{Cfloat},))
progress(fnc_c, 0.1f0)