Skip to content

Commit 819dbc6

Browse files
authored
Specialize cconvert instead of unsafe_convert (#1236)
* Specialize cconvert instead of unsafe_convert * Add test
1 parent 980432c commit 819dbc6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/SizedArray.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ end
9494

9595
Base.parent(sa::SizedArray) = sa.data
9696

97-
Base.unsafe_convert(::Type{Ptr{T}}, sa::SizedArray) where {T} = Base.unsafe_convert(Ptr{T}, sa.data)
97+
Base.cconvert(P::Type{Ptr{T}}, sa::SizedArray) where {T} = Base.cconvert(P, sa.data)
98+
if VERSION < v"1.11-"
99+
Base.unsafe_convert(::Type{Ptr{T}}, sa::SizedArray) where {T} = Base.unsafe_convert(Ptr{T}, sa.data)
100+
end
98101
Base.elsize(::Type{SizedArray{S,T,M,N,A}}) where {S,T,M,N,A} = Base.elsize(A)
99102

100103
Base.dataids(sa::SizedArray) = Base.dataids(sa.data)

test/SizedArray.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110

111111
# pointer
112112
@testset "pointer" begin
113+
@test Base.cconvert(Ptr{Int}, sa) === Base.cconvert(Ptr{Int}, sa.data)
113114
@test pointer(sa) === pointer(sa.data)
114115

115116
A = MMatrix{32,3,Float64}(undef);

0 commit comments

Comments
 (0)