problem with ccall in v1.0

Where? What I see in doc is this:

ccall — Keyword.

ccall((function_name, library), returntype, (argtype1, ...), argvalue1, ...)
ccall(function_pointer, returntype, (argtype1, ...), argvalue1, ...)

Call a function in a C-exported shared library, specified by the tuple (function_name, library) , where each
component is either a string or symbol. Alternatively, ccall may also be used to call a function pointer
function_pointer , such as one returned by dlsym .

Note that the argument type tuple must be a literal tuple, and not a tuple-valued variable or expression.

Each argvalue to the ccall will be converted to the corresponding argtype , by automatic insertion of calls to unsafe_convert(argtype, cconvert(argtype, argvalue)) . (See also the documentation for unsafe_convert and cconvert for further details.) In most cases, this simply results in a call to convert(argtype, argvalue) .

The lines

  lib = "./libtest.so"
  v = ccall((:test,lib),Int32,())

lead to a segfault that terminates the REPL that leaves me back at the shell command line.

The line

  v = ccall((:test,"./libtest.so"),Int32,())

works perfectly.

The docementation on Calling C and Fortran Code · The Julia Language
says that the argument to ccall should be of the form (:function, "library")

If anyone finds it useful then the complete output given by Julia when it hits this bug and segfaults is:

julia> iinclude("m.jl")
hello

signal (11): Segmentation fault
in expression starting at /tcenas/home/anderson/julia/xxx/m.jl:13
_ZN4llvm3Use3setEPNS_5ValueE at /usr/local/bin/julia-1.0.1/bin/../lib/julia/libLLVM-6.0.so (unknown line)
_ZN4llvm8LoadInstC2EPNS_4TypeEPNS_5ValueEPKcbPNS_11InstructionE at /usr/local/bin/julia-1.0.1/bin/../lib/julia/libLLVM-6.0.so (unknown line)
CreateLoad at /buildworker/worker/package_linux64/build/usr/include/llvm/IR/IRBuilder.h:1175
emit_varinfo at /buildworker/worker/package_linux64/build/src/codegen.cpp:3374
emit_expr at /buildworker/worker/package_linux64/build/src/codegen.cpp:3455
emit_call at /buildworker/worker/package_linux64/build/src/codegen.cpp:3140
emit_expr at /buildworker/worker/package_linux64/build/src/codegen.cpp:3902
interpret_symbol_arg at /buildworker/worker/package_linux64/build/src/ccall.cpp:675
emit_ccall at /buildworker/worker/package_linux64/build/src/ccall.cpp:1523
emit_expr at /buildworker/worker/package_linux64/build/src/codegen.cpp:3912
emit_ssaval_assign at /buildworker/worker/package_linux64/build/src/codegen.cpp:3615
emit_stmtpos at /buildworker/worker/package_linux64/build/src/codegen.cpp:3801 [inlined]
emit_function at /buildworker/worker/package_linux64/build/src/codegen.cpp:6254
jl_compile_linfo at /buildworker/worker/package_linux64/build/src/codegen.cpp:1159
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1796
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:324
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:430
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:363 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:682
jl_interpret_toplevel_thunk_callback at /buildworker/worker/package_linux64/build/src/interpreter.c:795
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f20528e4aff)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:804
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:813
jl_parse_eval_all at /buildworker/worker/package_linux64/build/src/ast.c:838
jl_load at /buildworker/worker/package_linux64/build/src/toplevel.c:847
include at ./boot.jl:317 [inlined]
include_relative at ./loading.jl:1041
include at ./sysimg.jl:29
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
include at ./client.jl:388
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:324
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:430
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:363 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:682
jl_interpret_toplevel_thunk_callback at /buildworker/worker/package_linux64/build/src/interpreter.c:795
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f20528e419f)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:804
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:813
jl_toplevel_eval_in at /buildworker/worker/package_linux64/build/src/builtins.c:622
eval at ./boot.jl:319
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
eval_user_input at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:85
macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:117 [inlined]
#28 at ./task.jl:259
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1537 [inlined]
start_task at /buildworker/worker/package_linux64/build/src/task.c:268
unknown function (ip: 0xffffffffffffffff)
Allocations: 132634 (Pool: 132568; Big: 66); GC: 0
Segmentation fault (core dumped)
>

But I now understand the cause of the problem and can work around it, so I can only suggest that the error trapping inside ccall is improved to avoid anyone else getting coming across this issue.

Now I can push on with upgrading the interface to my library from 6.4 to 1.0 and see what other problems I can find :slight_smile:

Julia shouldn’t segfault in this case. Since you have such a nice simple reproducible example, I would suggest opening a Julia issue so that this can get fixed.

A Julia issue has now been opened:
https://github.com/JuliaLang/julia/issues/29602

Thank you!