`ccall` and Type Parameters in 0.6

This worked before (0.5):

julia> f{T}(::Type{T}) = ccall(:strlen, T, (Ptr{UInt8},), "abc")
f (generic function with 1 method)

julia> f(Int)
3

julia> f(UInt)
0x0000000000000003

But now:

julia> f{T}(::Type{T}) = ccall(:strlen, T, (Ptr{UInt8},), "abc")
ERROR: TypeError: ccall method definition: expected Type, got TypeVar

Is this intended? It’s not in the news. (Was it ever supposed to work? Where is it documented?)

And I don’t know what is the intended behavior here, but:

"with unionall"
try_substrtod(::Type{T}, s) where T = 
    ccall(:jl_try_substrtod, Nullable{T}, (Ptr{UInt8},Csize_t,Csize_t), s, 0, sizeof(s))

"without unionall"
try_substrtod(s) =
    ccall(:jl_try_substrtod, Nullable{Float64}, (Ptr{UInt8},Csize_t,Csize_t), s, 0, sizeof(s))
julia> try_substrtod("10.0")
Nullable{Float64}(10.0)

julia> try_substrtod(Float64, "10.0")

signal (11): Segmentation fault
while loading no file, in expression starting on line 0
julia_struct_has_layout at /home/fabio/Source/Git/Languages/julia/src/cgutils.cpp:442 [inlined]
julia_struct_to_llvm at /home/fabio/Source/Git/Languages/julia/src/cgutils.cpp:470
verify_ccall_sig at /home/fabio/Source/Git/Languages/julia/src/ccall.cpp:1415 [inlined]
emit_ccall at /home/fabio/Source/Git/Languages/julia/src/ccall.cpp:1536
emit_expr at /home/fabio/Source/Git/Languages/julia/src/codegen.cpp:4041
emit_function at /home/fabio/Source/Git/Languages/julia/src/codegen.cpp:5963
jl_compile_linfo at /home/fabio/Source/Git/Languages/julia/src/codegen.cpp:1201
jl_compile_for_dispatch at /home/fabio/Source/Git/Languages/julia/src/gf.c:1627
jl_compile_method_internal at /home/fabio/Source/Git/Languages/julia/src/julia_internal.h:294 [inlined]
jl_call_method_internal at /home/fabio/Source/Git/Languages/julia/src/julia_internal.h:341 [inlined]
jl_apply_generic at /home/fabio/Source/Git/Languages/julia/src/gf.c:2225
do_call at /home/fabio/Source/Git/Languages/julia/src/interpreter.c:75
eval at /home/fabio/Source/Git/Languages/julia/src/interpreter.c:242
jl_interpret_toplevel_expr at /home/fabio/Source/Git/Languages/julia/src/interpreter.c:34
jl_toplevel_eval_flex at /home/fabio/Source/Git/Languages/julia/src/toplevel.c:577
jl_toplevel_eval_in at /home/fabio/Source/Git/Languages/julia/src/builtins.c:484
eval at ./boot.jl:235
unknown function (ip: 0x7fe252cf9d8f)
jl_call_fptr_internal at /home/fabio/Source/Git/Languages/julia/src/julia_internal.h:326 [inlined]
jl_call_method_internal at /home/fabio/Source/Git/Languages/julia/src/julia_internal.h:345 [inlined]
jl_apply_generic at /home/fabio/Source/Git/Languages/julia/src/gf.c:2225
eval_user_input at ./REPL.jl:66
unknown function (ip: 0x7fe0410e1576)
jl_call_fptr_internal at /home/fabio/Source/Git/Languages/julia/src/julia_internal.h:326 [inlined]
jl_call_method_internal at /home/fabio/Source/Git/Languages/julia/src/julia_internal.h:345 [inlined]
jl_apply_generic at /home/fabio/Source/Git/Languages/julia/src/gf.c:2225
macro expansion at ./REPL.jl:97 [inlined]
#1 at ./event.jl:73
unknown function (ip: 0x7fe0410d7d2f)
jl_call_fptr_internal at /home/fabio/Source/Git/Languages/julia/src/julia_internal.h:326 [inlined]
jl_call_method_internal at /home/fabio/Source/Git/Languages/julia/src/julia_internal.h:345 [inlined]
jl_apply_generic at /home/fabio/Source/Git/Languages/julia/src/gf.c:2225
jl_apply at /home/fabio/Source/Git/Languages/julia/src/julia.h:1410 [inlined]
start_task at /home/fabio/Source/Git/Languages/julia/src/task.c:261
unknown function (ip: 0xffffffffffffffff)
Allocations: 2263084 (Pool: 2261779; Big: 1305); GC: 1
[1]    9293 segmentation fault  julia

I’ve seen one case where a type parameter was used with ccall in base: https://github.com/JuliaLang/julia/blob/268420df5211670fd7df3e6e4d1b4fc3f15c793f/base/util.jl#L635-L636
So I guess this is supposed to work?

I was about to post this as an issue but I don’t really know anything about ccall so I am asking here first.

Yes.

The segfault is a bug.

The type parameter does not affect calling convention.

1 Like

Well okay. I still don’t know what any of this is so I am just going to assume whatever issue is here as “reported” and go to sleep. Goodnight, and happy coding…