Skip to content

Commit a66197c

Browse files
committed
Add GC.at-preserve for some pointer calls, fix #529.
1 parent 5afb0c1 commit a66197c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/MArray.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,21 @@ end
113113
####################
114114

115115
@propagate_inbounds function getindex(v::MArray, i::Int)
116-
@boundscheck checkbounds(v,i)
116+
@boundscheck checkbounds(v,i)
117117
T = eltype(v)
118-
118+
119119
if isbitstype(T)
120-
return unsafe_load(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), i)
120+
return GC.@preserve v unsafe_load(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), i)
121121
end
122122
v.data[i]
123123
end
124124

125125
@inline function setindex!(v::MArray, val, i::Int)
126-
@boundscheck checkbounds(v,i)
126+
@boundscheck checkbounds(v,i)
127127
T = eltype(v)
128128

129129
if isbitstype(T)
130-
unsafe_store!(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), convert(T, val), i)
130+
GC.@preserve v unsafe_store!(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), convert(T, val), i)
131131
else
132132
# This one is unsafe (#27)
133133
# unsafe_store!(Base.unsafe_convert(Ptr{Ptr{Nothing}}, pointer_from_objref(v.data)), pointer_from_objref(val), i)

0 commit comments

Comments
 (0)