From 1d3d115a79b9002e72164b576a7bb697ce10666b Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 4 Aug 2016 23:35:28 +0200 Subject: [PATCH] Fix `@threadcall` argument passing. Fixes #17819. Also document not being allowed to call back into Julia. (cherry picked from commit aea8180b086c819d216ece16a03913d6ff8b291f) ref #18016 --- base/threadcall.jl | 1 + src/ccalltest.c | 10 ++++++++++ test/ccall.jl | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/base/threadcall.jl b/base/threadcall.jl index be3e99f324cb8..da877d9707109 100644 --- a/base/threadcall.jl +++ b/base/threadcall.jl @@ -75,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/src/ccalltest.c b/src/ccalltest.c index e01aafa300fb2..ccd7e1cd57fde 100644 --- a/src/ccalltest.c +++ b/src/ccalltest.c @@ -21,6 +21,7 @@ int verbose = 1; int c_int = 0; + ////////////////////////////////// // Test for proper argument register truncation @@ -520,6 +521,7 @@ JL_DLLEXPORT void finalizer_cptr(void* v) set_c_int(-1); } + ////////////////////////////////// // Turn off verbose for automated tests, leave on for debugging @@ -527,6 +529,10 @@ JL_DLLEXPORT void set_verbose(int level) { verbose = level; } + +////////////////////////////////// +// Other tests + JL_DLLEXPORT void *test_echo_p(void *p) { return p; } @@ -723,3 +729,7 @@ JL_DLLEXPORT float32x4_t test_ppc64_vec2(int64_t d1, float32x4_t a, float32x4_t } #endif + +JL_DLLEXPORT int threadcall_args(int a, int b) { + return a + b; +} diff --git a/test/ccall.jl b/test/ccall.jl index 7f0792a87fdd5..56a6b1bf3f5be 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 +# issue 17819 +# NOTE: can't use cfunction or reuse ccalltest Struct methods, as those call into the runtime +@test @threadcall((:threadcall_args, libccalltest), Cint, (Cint, Cint), 1, 2) == 3 + let n=3 tids = Culong[] @sync for i in 1:10^n