Skip to content

Commit

Permalink
Merge pull request #530 from JuliaArrays/fe/getindex
Browse files Browse the repository at this point in the history
Add GC.at-preserve for some pointer calls, fix #529.
  • Loading branch information
andyferris authored Oct 25, 2018
2 parents 5afb0c1 + a66197c commit 1683f79
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/MArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1683f79

Please sign in to comment.