Skip to content

Commit

Permalink
Specialize cconvert instead of unsafe_convert (#1236)
Browse files Browse the repository at this point in the history
* Specialize cconvert instead of unsafe_convert

* Add test
  • Loading branch information
jishnub authored Jan 25, 2024
1 parent 980432c commit 819dbc6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/SizedArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ end

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

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

Base.dataids(sa::SizedArray) = Base.dataids(sa.data)
Expand Down
1 change: 1 addition & 0 deletions test/SizedArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@

# pointer
@testset "pointer" begin
@test Base.cconvert(Ptr{Int}, sa) === Base.cconvert(Ptr{Int}, sa.data)
@test pointer(sa) === pointer(sa.data)

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

0 comments on commit 819dbc6

Please sign in to comment.