Skip to content

Commit 329f53f

Browse files
committed
Add beginnings of a test
1 parent a0b4ad0 commit 329f53f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/precompile.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,5 +1554,35 @@ precompile_test_harness("issue #46296") do load_path
15541554
(@eval (using CodeInstancePrecompile))
15551555
end
15561556

1557+
precompile_test_harness("foreign types") do path
1558+
write(joinpath(load_path, "Foreign.jl"),
1559+
"""
1560+
module Foreign
1561+
1562+
export FObj
1563+
1564+
const FObj = ccall(:jl_new_foreign_type, Any, (Symbol, Module, Any, Any, Any, Cint, Cint),
1565+
:FObj, Foreign, Any, C_NULL, C_NULL, 0, 0)
1566+
1567+
FObj() = ccall(:jl_new_struct_uninit, Any, (Any,), FObj)
1568+
1569+
const nmark = Ref(0)
1570+
const nsweep = Ref(0)
1571+
inc_nmark() = (nmark[] += 1; return nothing)
1572+
inc_nsweep() = (nsweep[] += 1; return nothing)
1573+
1574+
function __init__()
1575+
ccall(:jl_reinit_foreign_type, Cint, (Any, Any, Any),
1576+
FObj, @cfunction(inc_nmark, Cvoid, ()), @cfunction(inc_nsweep, Cvoid, ()))
1577+
end
1578+
1579+
end # module Foreign
1580+
""")
1581+
(@eval (using Foreign))
1582+
x = [FObj() for _ in 1:1000]
1583+
GC.gc(true)
1584+
@test_broken Foreign.nmark[] > 0 || Foreign.nsweep[] > 0
1585+
end
1586+
15571587
empty!(Base.DEPOT_PATH)
15581588
append!(Base.DEPOT_PATH, original_depot_path)

0 commit comments

Comments
 (0)