From 39a8092b06d1f29ca431171e0ab526e6eb0c3478 Mon Sep 17 00:00:00 2001 From: Kristoffer Date: Tue, 23 Apr 2024 10:48:16 +0200 Subject: [PATCH 1/3] attach finalizer in `mmap` to the correct object --- stdlib/Mmap/src/Mmap.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/Mmap/src/Mmap.jl b/stdlib/Mmap/src/Mmap.jl index 6d328c40cd7b3..e6987582bf511 100644 --- a/stdlib/Mmap/src/Mmap.jl +++ b/stdlib/Mmap/src/Mmap.jl @@ -256,7 +256,7 @@ function mmap(io::IO, end # os-test # convert mmapped region to Julia Array at `ptr + (offset - offset_page)` since file was mapped at offset_page A = unsafe_wrap(Array, convert(Ptr{T}, UInt(ptr) + UInt(offset - offset_page)), dims) - finalizer(A) do x + finalizer(A.ref.mem) do x @static if Sys.isunix() systemerror("munmap", ccall(:munmap, Cint, (Ptr{Cvoid}, Int), ptr, mmaplen) != 0) else From 7d5800d6478665a950b857c1e868836b80475cba Mon Sep 17 00:00:00 2001 From: KristofferC Date: Tue, 21 May 2024 17:46:35 +0200 Subject: [PATCH 2/3] move GC.gC() call --- stdlib/Mmap/test/runtests.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/Mmap/test/runtests.jl b/stdlib/Mmap/test/runtests.jl index ebd16a45ba0ed..2154dfc3e27d3 100644 --- a/stdlib/Mmap/test/runtests.jl +++ b/stdlib/Mmap/test/runtests.jl @@ -336,8 +336,9 @@ open(file, "r+") do s finalize(A); A = nothing; GC.gc() A = mmap(s, Vector{UInt8}, (10,), 1) Mmap.sync!(A) - finalize(A); A = nothing; GC.gc() + finalize(A); A = nothing; end +GC.gc() rm(file) @testset "Docstrings" begin From 000a05dbb26f6b6e01d0a44d3d0a96c5f8470198 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Mon, 27 May 2024 10:28:19 +0200 Subject: [PATCH 3/3] move another GC call --- stdlib/Mmap/test/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/Mmap/test/runtests.jl b/stdlib/Mmap/test/runtests.jl index 2154dfc3e27d3..03e4b48d95f7a 100644 --- a/stdlib/Mmap/test/runtests.jl +++ b/stdlib/Mmap/test/runtests.jl @@ -100,9 +100,9 @@ if !(Sys.ARCH === :powerpc64le || Sys.ARCH === :ppc64le) s = open(file, "r") m = mmap(s) @test_throws ReadOnlyMemoryError m[5] = UInt8('x') # tries to setindex! on read-only array - finalize(m); m=nothing; GC.gc() + finalize(m); m=nothing; end - +GC.gc() write(file, "Hello World\n") s = open(file, "r")