From 9d80aa09537ef9a716677d1001e03619c86aa9fb Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 4 Aug 2016 23:35:28 +0200 Subject: [PATCH] Fix `@llvmcall` argument passing. Fixes #17819. Also document not being allowed to call back into Julia. --- base/threadcall.jl | 3 +++ test/ccall.jl | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/base/threadcall.jl b/base/threadcall.jl index c9da92c5a49eac..da877d97071090 100644 --- a/base/threadcall.jl +++ b/base/threadcall.jl @@ -23,6 +23,8 @@ function without causing the main `julia` thread to become blocked. Concurrency is limited by size of the libuv thread pool, which defaults to 4 threads but can be increased by setting the `UV_THREADPOOL_SIZE` environment variable and restarting the `julia` process. + +Note that the called function should never call back into Julia. """ macro threadcall(f, rettype, argtypes, argvals...) # check for usage errors @@ -73,6 +75,7 @@ function do_threadcall(wrapper::Function, rettype::Type, argtypes::Vector, argva y = cconvert(T, x) push!(roots, y) unsafe_store!(convert(Ptr{T}, ptr), unsafe_convert(T, y)) + ptr += sizeof(T) end # create return buffer diff --git a/test/ccall.jl b/test/ccall.jl index 7f0792a87fdd51..e5cf4709d6d124 100644 --- a/test/ccall.jl +++ b/test/ccall.jl @@ -589,6 +589,10 @@ threadcall_test_func(x) = @test threadcall_test_func(3) == 1 @test threadcall_test_func(259) == 1 +f17819(a,b) = Cint(a+b) +cf17819 = cfunction(f17819, Cint, (Cint,Cint)) +@test @threadcall(cf17819, Cint, (Cint, Cint), 1, 2) == 3 + let n=3 tids = Culong[] @sync for i in 1:10^n