Skip to content

Commit fcb6a7c

Browse files
authored
Use @pyregion when loading Python objects from arrays (#843)
This branch calls incref(u) to increment the objects refcount, which without @pyregion would be a data race if other threads accessed it at the same time.
1 parent 28ab334 commit fcb6a7c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎src/Wrap/PyArray.jl‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,11 @@ function pyarray_load(::Type{T}, p::Ptr{R}) where {T,R}
652652
if R == T
653653
unsafe_load(p)
654654
elseif R == C.PyPtr
655-
u = unsafe_load(p)
656-
o = u == C_NULL ? pynew(Py(nothing)) : pynew(incref(u))
657-
T == Py ? o : pyconvert(T, o)
655+
@pyregion begin
656+
u = unsafe_load(p)
657+
o = u == C_NULL ? pynew(Py(nothing)) : pynew(incref(u))
658+
T == Py ? o : pyconvert(T, o)
659+
end
658660
else
659661
convert(T, unsafe_load(p))
660662
end

0 commit comments

Comments
 (0)