I believe that this is a bug in the nightly build but wanted to check before submitting an issue.
When using the @cfunction
macro within a closure with keyword arguments, I get an error message from Julia if the keyword arguments are not specified. Namely, in the following example
function foo()::Cint
return 1
end
function test_no_kw(fn)
callback = @cfunction $fn Cint ()
end
function test_kw(fn; dummy = 1)
callback = @cfunction $fn Cint ()
end
These two calls produce no error messages:
# No error
let
test_no_kw(foo)
end
# No error
let
test_kw(foo; dummy = 1)
end
But when the keyword arguments are not specified:
# error message
let
test_kw(foo)
end
I get the following error messages:
Internal error: encountered unexpected error in runtime:
BoundsError(a=Array{Bool, (2,)}[false, false], i=(4,))
rec_backtrace at /Users/osx/buildbot/slave/package_osx64/build/src/stackwalk.c:94
record_backtrace at /Users/osx/buildbot/slave/package_osx64/build/src/task.c:246 [inlined]
jl_throw at /Users/osx/buildbot/slave/package_osx64/build/src/task.c:577
jl_bounds_error_ints at /Users/osx/buildbot/slave/package_osx64/build/src/rtutils.c:187
setindex! at ./array.jl:707 [inlined]
_widen_all_consts! at ./compiler/optimize.jl:677
_widen_all_consts! at ./compiler/optimize.jl:662
widen_all_consts! at ./compiler/optimize.jl:695
optimize at ./compiler/optimize.jl:331
typeinf at ./compiler/typeinfer.jl:440
typeinf_frame at ./compiler/typeinfer.jl:96 [inlined]
typeinf_code at ./compiler/typeinfer.jl:191
typeinf_ext at ./compiler/typeinfer.jl:233
jfptr_typeinf_ext_12.clone_1 at /Applications/Julia-0.7.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
jl_apply at /Users/osx/buildbot/slave/package_osx64/build/src/./julia.h:1540 [inlined]
jl_apply_with_saved_exception_state at /Users/osx/buildbot/slave/package_osx64/build/src/rtutils.c:257
jl_type_infer at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:274
jl_compile_method_internal at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1771
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1815
do_call at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:324
eval_body at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:559
jl_interpret_toplevel_thunk_callback at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:798
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x11548042f)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:807
jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:856
jl_toplevel_eval_in at /Users/osx/buildbot/slave/package_osx64/build/src/builtins.c:631
eval at ./boot.jl:317 [inlined]
eval at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/REPL/src/REPL.jl:5
eval_user_input at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/REPL/src/REPL.jl:85
macro expansion at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/REPL/src/REPL.jl:116 [inlined]
#28 at ./event.jl:92
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1816
jl_apply at /Users/osx/buildbot/slave/package_osx64/build/src/./julia.h:1540 [inlined]
start_task at /Users/osx/buildbot/slave/package_osx64/build/src/task.c:268
Base.CFunction(Ptr{Nothing} @0x000000012ba7af40, foo, Ptr{Nothing} @0x0000000000000000, Ptr{Nothing} @0x0000000000000000)
The for more complex examples, e.g., qsort
, the function pointer returned in the error prone case seems to be fine, but I have not exstensively tested this.
Here is my versioninfo()
Julia Version 0.7.0-DEV.5105
Commit a1a62f98e7 (2018-05-15 09:52 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin14.5.0)
CPU: Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, haswell)