From fe02b0b6c56970725d7c144db5f4d33ccc558229 Mon Sep 17 00:00:00 2001 From: JamesWrigley Date: Tue, 20 Oct 2026 11:28:12 +0200 Subject: [PATCH] Use @pyregion when loading Python objects from arrays 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. --- src/Wrap/PyArray.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Wrap/PyArray.jl b/src/Wrap/PyArray.jl index 64bb3176..86912e25 100644 --- a/src/Wrap/PyArray.jl +++ b/src/Wrap/PyArray.jl @@ -646,9 +646,11 @@ function pyarray_load(::Type{T}, p::Ptr{R}) where {T,R} if R == T unsafe_load(p) elseif R == C.PyPtr - u = unsafe_load(p) - o = u == C_NULL ? pynew(Py(nothing)) : pynew(incref(u)) - T == Py ? o : pyconvert(T, o) + @pyregion begin + u = unsafe_load(p) + o = u == C_NULL ? pynew(Py(nothing)) : pynew(incref(u)) + T == Py ? o : pyconvert(T, o) + end else convert(T, unsafe_load(p)) end