Issue with Julia ccall interface and symbols

Viewed 981

I'm attemping to use Julia's ccall function to interface with a C library. All the types and pointers are correct, and the below function call successfully returns the correct answer (variable defintion and setup not shown here for brevity).

    ccall((:vDSP_convD, libacc),  Void,
          (Ptr{T}, Int64,  Ptr{T},  Int64,  Ptr{T},  Int64, UInt64, UInt64),
          x_padded, 1, pointer(K, Ksize), -1, result, 1,  Rsize, Ksize)

However, if I wish to generate the function name as a symbol, and then use it as an argument to ccall, it fails.

fname = symbol(string("vDSP_conv", "D"))
ccall((fname , libacc),  Void,
          (Ptr{T}, Int64,  Ptr{T},  Int64,  Ptr{T},  Int64, UInt64, UInt64),
          x_padded, 1, pointer(K, Ksize), -1, result, 1,  Rsize, Ksize)

The error is:

ERROR: LoadError: TypeError: conv: in ccall: first argument not a 
pointer or valid constant expression, expected Ptr{T}, 
got Tuple{Symbol,ASCIIString}

If I print the type of each of these two naming versions, I get

julia> println(typeof(:vDSP_convD))
       Symbol
julia> println(typeof(fname))
       Symbol

Is there a way to get this to work? I'm guessing that I will have to wrap this in a macro or @eval to get this work, but I am curious as to why the above functionality doesn't work as shown?

Any help will be most appreciated!

EDIT

I ended up wrapping this in an @eval block to get it to work; however, I'm still curious as to the backend logic as to why the above syntax doesn't work (why it interprets a symbol as a pointer sometimes, and then not other times)

1 Answers
Related