Skip to content

Commit 664146a

Browse files
committed
add test
1 parent 4c7bee1 commit 664146a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/ccalls.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ useful for functions that may block, so that the GC isn't blocked from running,
105105
be required to prevent deadlocks (see JuliaGPU/CUDA.jl#2261).
106106
107107
Note that this is generally only safe with non-Julia C functions that do not call back into
108-
Julia. When using callbacks, the code should make sure to transition back into GC-unsafe
109-
mode using the `@gcunsafe` macro.
108+
the Julia directly.
110109
"""
111110
macro gcsafe_ccall end
112111

test/runtests.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,19 @@ using GPUToolbox
4242
@test !(sv2 > sv2) # Default
4343
end
4444

45-
# TODO: @debug_ccall and @gcsafe_ccall tests
45+
@testset "gcsafe_ccall" begin
46+
function gc_safe_ccall()
47+
# jl_rand is marked as JL_NOTSAFEPOINT
48+
@gcsafe_ccall gc_safe=true jl_rand()::UInt64
49+
end
50+
51+
let llvm = sprint(code_llvm, gc_safe_ccall, ())
52+
# check that the call works
53+
@test gc_safe_ccall() isa UInt64
54+
# check for the gc_safe store
55+
@test occursin("store atomic i8 2", llvm)
56+
end
57+
end
58+
59+
# TODO: @debug_ccall tests
4660
end

0 commit comments

Comments
 (0)