Hi there,
This is a follow-up of Issue #27477. Running Julia 1.1.0 on darwin64.
module B
using Cairo
lib_path = Cairo._jl_libcairo
test() = ccall((:cairo_version_string, lib_path),Cstring,())
end
julia> B.test()
ERROR: TypeError: in ccall: first argument not a pointer or valid constant expression, expected Ptr, got Tuple{Symbol,String}
Stacktrace:
[1] test() at ./REPL[1]:4
[2] top-level scope at none:0
I found a workaround:
module B
using Cairo
lib_path = Cairo._jl_libcairo
test() = eval(:(ccall((:cairo_version_string, $lib_path),Cstring,())))
end
julia> B.test()
Cstring(0x000000012c08bc49)
But when I try to to parametrize the argument type but ran into another issue. See the sample code below
julia> module B
using Cairo
lib_path = Cairo._jl_libcairo
arg_type = ()
call_str =:(ccall((:cairo_version_string, $lib_path),Cstring,$arg_type))
dump(call_str)
test() = eval(call_str)
end
WARNING: replacing module B.
Expr
head: Symbol call
args: Array{Any}((4,))
1: Symbol ccall
2: Expr
head: Symbol tuple
args: Array{Any}((2,))
1: QuoteNode
value: Symbol cairo_version_string
2: String "/Users/hcui7/.julia/packages/Homebrew/s09IX/deps/usr/lib/libcairo.dylib"
3: Symbol Cstring
4: Tuple{} ()
Main.B
julia> B.test()
ERROR: syntax: ccall argument types must be a tuple; try "(T,)"
Stacktrace:
[1] eval at ./boot.jl:328 [inlined]
[2] eval at ./REPL[10]:1 [inlined]
[3] test() at ./REPL[10]:7
[4] top-level scope at none:0
If I hard-code the arg_type, it works:
julia> module B
using Cairo
lib_path = Cairo._jl_libcairo
arg_type = ()
call_str =:(ccall((:cairo_version_string, $lib_path),Cstring,()))
dump(call_str)
test() = eval(call_str)
end
WARNING: replacing module B.
Expr
head: Symbol call
args: Array{Any}((4,))
1: Symbol ccall
2: Expr
head: Symbol tuple
args: Array{Any}((2,))
1: QuoteNode
value: Symbol cairo_version_string
2: String "/Users/hcui7/.julia/packages/Homebrew/s09IX/deps/usr/lib/libcairo.dylib"
3: Symbol Cstring
4: Expr
head: Symbol tuple
args: Array{Any}((0,))
Main.B
julia> B.test()
Cstring(0x0000000123892c49)
Julia>