Skip to content

Commit fe78b04

Browse files
authored
replace many unsafe_convert methods with safer cconvert ones (#51764)
This seems the correct way to define most conversions, since the unsafe logic should typically be isolated to a few areas, and everywhere else just defines conversions to it. This ensures the root is preserved even if the user later makes unexpected changes to the parent object (although the length might have later become inconsistent at that point, so it is not a guaranteed fix for memory issues).
1 parent 19684b4 commit fe78b04

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/adjtrans.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ Base.strides(A::Transpose{<:Any, <:AbstractVector}) = (stride(A.parent, 2), stri
344344
Base.strides(A::Adjoint{<:Real, <:AbstractMatrix}) = reverse(strides(A.parent))
345345
Base.strides(A::Transpose{<:Any, <:AbstractMatrix}) = reverse(strides(A.parent))
346346

347-
Base.unsafe_convert(::Type{Ptr{T}}, A::Adjoint{<:Real, <:AbstractVecOrMat}) where {T} = Base.unsafe_convert(Ptr{T}, A.parent)
348-
Base.unsafe_convert(::Type{Ptr{T}}, A::Transpose{<:Any, <:AbstractVecOrMat}) where {T} = Base.unsafe_convert(Ptr{T}, A.parent)
347+
Base.cconvert(::Type{Ptr{T}}, A::Adjoint{<:Real, <:AbstractVecOrMat}) where {T} = Base.cconvert(Ptr{T}, A.parent)
348+
Base.cconvert(::Type{Ptr{T}}, A::Transpose{<:Any, <:AbstractVecOrMat}) where {T} = Base.cconvert(Ptr{T}, A.parent)
349349

350350
Base.elsize(::Type{<:Adjoint{<:Real, P}}) where {P<:AbstractVecOrMat} = Base.elsize(P)
351351
Base.elsize(::Type{<:Transpose{<:Any, P}}) where {P<:AbstractVecOrMat} = Base.elsize(P)

test/blas.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ Base.getindex(A::WrappedArray, i::Int) = A.A[i]
532532
Base.getindex(A::WrappedArray{T, N}, I::Vararg{Int, N}) where {T, N} = A.A[I...]
533533
Base.setindex!(A::WrappedArray, v, i::Int) = setindex!(A.A, v, i)
534534
Base.setindex!(A::WrappedArray{T, N}, v, I::Vararg{Int, N}) where {T, N} = setindex!(A.A, v, I...)
535-
Base.unsafe_convert(::Type{Ptr{T}}, A::WrappedArray{T}) where T = Base.unsafe_convert(Ptr{T}, A.A)
535+
Base.cconvert(::Type{Ptr{T}}, A::WrappedArray{T}) where T = Base.cconvert(Ptr{T}, A.A)
536536

537537
Base.strides(A::WrappedArray) = strides(A.A)
538538
Base.elsize(::Type{WrappedArray{T,N}}) where {T,N} = Base.elsize(Array{T,N})

0 commit comments

Comments
 (0)