From a66197c70310907f211d2b7eec56699498502fb1 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Thu, 25 Oct 2018 00:27:49 +0200 Subject: [PATCH] Add GC.at-preserve for some pointer calls, fix #529. --- src/MArray.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MArray.jl b/src/MArray.jl index 5cdacd2a..5f7f6d20 100644 --- a/src/MArray.jl +++ b/src/MArray.jl @@ -113,21 +113,21 @@ end #################### @propagate_inbounds function getindex(v::MArray, i::Int) - @boundscheck checkbounds(v,i) + @boundscheck checkbounds(v,i) T = eltype(v) - + if isbitstype(T) - return unsafe_load(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), i) + return GC.@preserve v unsafe_load(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), i) end v.data[i] end @inline function setindex!(v::MArray, val, i::Int) - @boundscheck checkbounds(v,i) + @boundscheck checkbounds(v,i) T = eltype(v) if isbitstype(T) - unsafe_store!(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), convert(T, val), i) + GC.@preserve v unsafe_store!(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), convert(T, val), i) else # This one is unsafe (#27) # unsafe_store!(Base.unsafe_convert(Ptr{Ptr{Nothing}}, pointer_from_objref(v.data)), pointer_from_objref(val), i)