Skip to content

Commit

Permalink
Fix @threadcall argument passing.
Browse files Browse the repository at this point in the history
Fixes JuliaLang#17819. Also document not being allowed to call back into Julia.
  • Loading branch information
maleadt authored and mfasi committed Sep 5, 2016
1 parent 9e04023 commit 223f311
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/threadcall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/ccalltest.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ int verbose = 1;

int c_int = 0;


//////////////////////////////////
// Test for proper argument register truncation

Expand Down Expand Up @@ -520,13 +521,18 @@ JL_DLLEXPORT void finalizer_cptr(void* v)
set_c_int(-1);
}


//////////////////////////////////
// Turn off verbose for automated tests, leave on for debugging

JL_DLLEXPORT void set_verbose(int level) {
verbose = level;
}


//////////////////////////////////
// Other tests

JL_DLLEXPORT void *test_echo_p(void *p) {
return p;
}
Expand Down Expand Up @@ -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;
}
4 changes: 4 additions & 0 deletions test/ccall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 223f311

Please sign in to comment.