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)