File tree Expand file tree Collapse file tree 4 files changed +31
-6
lines changed Expand file tree Collapse file tree 4 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -7,15 +7,14 @@ const HAS_CCALL_GCSAFE = VERSION >= v"1.13.0-DEV.70" || v"1.12-DEV.2029" <= VERS
7
7
"""
8
8
@gcsafe_ccall ...
9
9
10
- Call a foreign function just like [`@ccall`](https://docs.julialang.org/en/v1/base/c/#Base.@ccall), but marking it safe for the GC to run. This is
11
- useful for functions that may block, so that the GC isn't blocked from running, but may also
12
- be required to prevent deadlocks (see JuliaGPU/CUDA.jl#2261).
10
+ Call a foreign function just like [`@ccall`](https://docs.julialang.org/en/v1/base/c/#Base.@ccall),
11
+ but marking it safe for the GC to run. This is useful for functions that may block, so that the GC
12
+ isn't blocked from running, but may also be required to prevent deadlocks (see JuliaGPU/CUDA.jl#2261).
13
13
14
- Note that this is generally only safe with non-Julia C functions that do not call back into
15
- the Julia directly.
14
+ Note that this is generally only safe with non-Julia C functions that do not call back into Julia
15
+ directly.
16
16
"""
17
17
macro gcsafe_ccall end
18
- export @gcsafe_ccall
19
18
20
19
if HAS_CCALL_GCSAFE
21
20
macro gcsafe_ccall (expr)
Original file line number Diff line number Diff line change 1
1
[deps ]
2
2
CodecLz4 = " 5ba52731-8f18-5e0d-9241-30f10d1ec561"
3
+ InteractiveUtils = " b77e0a4c-d291-57a0-90e8-8db25a27a240"
3
4
Test = " 8dfed614-e22c-5e08-85e1-65c5234f0b40"
4
5
TestsForCodecPackages = " c2e61002-3542-480d-8b3c-5f05cc4f8554"
5
6
TranscodingStreams = " 3bb67fe8-82b1-5028-8e26-92a6c54297fa"
Original file line number Diff line number Diff line change
1
+ using CodecLz4
2
+ using InteractiveUtils
3
+
4
+ @testset " gcsafe_ccall" begin
5
+ function gc_safe_ccall ()
6
+ # jl_errno is marked as JL_NOTSAFEPOINT
7
+ CodecLz4. @gcsafe_ccall jl_errno ():: Cint
8
+ end
9
+
10
+ let llvm = sprint (code_llvm, gc_safe_ccall, ())
11
+ # check that the call works
12
+ @test gc_safe_ccall () isa Cint
13
+ # v1.10 is hard to test since ccall are just raw runtime pointers
14
+ if VERSION >= v " 1.11"
15
+ if ! CodecLz4. HAS_CCALL_GCSAFE
16
+ # check for the gc_safe store
17
+ @test occursin (" jl_gc_safe_enter" , llvm)
18
+ @test occursin (" jl_gc_safe_leave" , llvm)
19
+ else
20
+ @test occursin (" store atomic i8 2" , llvm)
21
+ end
22
+ end
23
+ end
24
+ end
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ using CodecLz4
2
2
using Test
3
3
4
4
@testset " CodecLz4.jl" begin
5
+ include (" gcsafe_ccall.jl" )
5
6
include (" headers/lz4.jl" )
6
7
include (" headers/lz4frame.jl" )
7
8
include (" headers/lz4hc.jl" )
You can’t perform that action at this time.
0 commit comments