@@ -124,7 +124,7 @@ function pyarray_make(::Type{A}, x::Py, info::PyArraySource, ::Type{PyArray{T0,N
124124 if R0 == R1
125125 R = R1
126126 R == R′ || error (" incorrect R, got $R , should be $R′ " )
127- elseif T0 == T1 && T1 in (Bool, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Float16, Float32, Float64, Complex{Float16}, Complex{Float32}, Complex{Float64} )
127+ elseif T0 == T1 && T1 in (Bool, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Float16, Float32, Float64, ComplexF16, ComplexF32, ComplexF64 )
128128 R = T1
129129 R == R′ || error (" incorrect R, got $R , should be $R′ " )
130130 R <: R1 || error (" R out of bounds, got $R , should be <: $R1 " )
@@ -431,19 +431,20 @@ pyarray_offset(x::PyArray{T,N}, i::Vararg{Int,N}) where {T,N} = sum((i .- 1) .*
431431pyarray_offset (x:: PyArray{T,0} ) where {T} = 0
432432
433433pyarray_load (:: Type{R} , p:: Ptr{R} ) where {R} = unsafe_load (p)
434- pyarray_load (:: Type{Py} , p:: Ptr{UnsafePyObject} ) = begin
435- o = unsafe_load (p)
436- o. ptr == C_NULL ? Py (nothing ) : pynew (incref (o. ptr))
434+ pyarray_load (:: Type{T} , p:: Ptr{UnsafePyObject} ) where {T} = begin
435+ u = unsafe_load (p)
436+ o = u. ptr == C_NULL ? Py (nothing ) : pynew (incref (u. ptr))
437+ T == Py ? o : pyconvert_and_del (T, o)
437438end
438439
439440pyarray_store! (p:: Ptr{R} , x:: R ) where {R} = unsafe_store! (p, x)
440- pyarray_store! (p:: Ptr{UnsafePyObject} , x:: Py ) = begin
441+ pyarray_store! (p:: Ptr{UnsafePyObject} , x) = @autopy x begin
441442 decref (unsafe_load (p). ptr)
442- unsafe_store! (p, UnsafePyObject (GC . @preserve x incref (getptr (x ))))
443+ unsafe_store! (p, UnsafePyObject (incref (getptr (x_ ))))
443444end
444445
445446pyarray_get_T (:: Type{R} , :: Type{T0} , :: Type{T1} ) where {R,T0,T1} = T0 <: R <: T1 ? R : error (" not possible" )
446- pyarray_get_T (:: Type{UnsafePyObject} , :: Type{T0} , :: Type{T1} ) where {T0,T1} = T0 <: Py <: T1 ? Py : T0 <: UnsafePyObject <: T1 ? UnsafePyObject : error ( " not possible " )
447+ pyarray_get_T (:: Type{UnsafePyObject} , :: Type{T0} , :: Type{T1} ) where {T0,T1} = T0 <: Py <: T1 ? Py : T1
447448
448449pyarray_check_T (:: Type{T} , :: Type{R} ) where {T,R} = T == R ? nothing : error (" invalid eltype T=$T for raw eltype R=$R " )
449- pyarray_check_T (:: Type{Py } , :: Type{UnsafePyObject} ) = nothing
450+ pyarray_check_T (:: Type{T } , :: Type{UnsafePyObject} ) where {T} = nothing
0 commit comments