Skip to content

Commit aa56069

Browse files
authored
Merge pull request #147 from JuliaArrays/ambiguous-unsafe-convert
Clean up and fix pointer code
2 parents 3962686 + d7edc9d commit aa56069

File tree

7 files changed

+8
-24
lines changed

7 files changed

+8
-24
lines changed

src/FieldVector.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ abstract type FieldVector{N, T} <: StaticVector{N, T} end
2323
@propagate_inbounds setindex!(v::FieldVector, x, i::Int) = setfield!(v, i, x)
2424

2525
# See #53
26-
Base.cconvert{T}(::Type{Ptr{T}}, v::FieldVector) = Ref(v)
27-
Base.unsafe_convert{T, FV <: FieldVector}(::Type{Ptr{T}}, m::Ref{FV}) =
26+
Base.cconvert{T}(::Type{Ptr{T}}, v::FieldVector) = Base.RefValue(v)
27+
Base.unsafe_convert{T, FV <: FieldVector}(::Type{Ptr{T}}, m::Base.RefValue{FV}) =
2828
_unsafe_convert(Ptr{T}, eltype(FV), m)
29-
_unsafe_convert{T, FV <: FieldVector}(::Type{Ptr{T}}, ::Type{T}, m::Ref{FV}) =
29+
_unsafe_convert{T, FV <: FieldVector}(::Type{Ptr{T}}, ::Type{T}, m::Base.RefValue{FV}) =
3030
Ptr{T}(Base.unsafe_convert(Ptr{FV}, m))

src/MMatrix.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ end
101101

102102
@inline Tuple(v::MMatrix) = v.data
103103

104-
@inline function Base.unsafe_convert{N,M,T}(::Type{Ptr{T}}, m::MMatrix{N,M,T})
105-
Base.unsafe_convert(Ptr{T}, Base.data_pointer_from_objref(m))
106-
end
107-
108104
macro MMatrix(ex)
109105
if !isa(ex, Expr)
110106
error("Bad input for @MMatrix")

src/MVector.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ end
5555

5656
@inline Tuple(v::MVector) = v.data
5757

58-
@inline function Base.unsafe_convert{N,T}(::Type{Ptr{T}}, v::MVector{N,T})
59-
Base.unsafe_convert(Ptr{T}, Base.data_pointer_from_objref(v))
60-
end
61-
6258
macro MVector(ex)
6359
if isa(ex, Expr) && ex.head == :vect
6460
return esc(Expr(:call, MVector{length(ex.args)}, Expr(:tuple, ex.args...)))

src/SArray.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ end
7373
@inline Tuple(v::SArray) = v.data
7474

7575
# See #53
76-
Base.cconvert{T}(::Type{Ptr{T}}, a::SArray) = Ref(a)
77-
Base.unsafe_convert{S,T,D,L}(::Type{Ptr{T}}, a::Ref{SArray{S,T,D,L}}) =
76+
Base.cconvert{T}(::Type{Ptr{T}}, a::SArray) = Base.RefValue(a)
77+
Base.unsafe_convert{S,T,D,L}(::Type{Ptr{T}}, a::Base.RefValue{SArray{S,T,D,L}}) =
7878
Ptr{T}(Base.unsafe_convert(Ptr{SArray{S,T,D,L}}, a))
7979

8080
macro SArray(ex)

src/SMatrix.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ end
7474

7575
@inline Tuple(v::SMatrix) = v.data
7676

77-
# See #53
78-
Base.cconvert{T}(::Type{Ptr{T}}, m::SMatrix) = Ref(m)
79-
Base.unsafe_convert{N,M,T,L}(::Type{Ptr{T}}, m::Ref{SMatrix{N,M,T,L}}) =
80-
Ptr{T}(Base.unsafe_convert(Ptr{SMatrix{N,M,T,L}}, m))
81-
82-
8377
macro SMatrix(ex)
8478
if !isa(ex, Expr)
8579
error("Bad input for @SMatrix")

src/SVector.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ end
3939

4040
@inline Tuple(v::SVector) = v.data
4141

42-
# See #53
43-
Base.cconvert{T}(::Type{Ptr{T}}, v::SVector) = Ref(v)
44-
Base.unsafe_convert{N,T}(::Type{Ptr{T}}, v::Ref{SVector{N,T}}) =
45-
Ptr{T}(Base.unsafe_convert(Ptr{SVector{N,T}}, v))
46-
4742
# Converting a CartesianIndex to an SVector
4843
convert(::Type{SVector}, I::CartesianIndex) = SVector(I.I)
4944
convert{N}(::Type{SVector{N}}, I::CartesianIndex{N}) = SVector{N}(I.I)

test/FieldVector.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
@test @inferred(similar_type(Point3D, Float32)) == SVector{3,Float32}
3434
@test @inferred(similar_type(Point3D, Size(4))) == SVector{4,Float64}
3535
@test @inferred(similar_type(Point3D, Float32, Size(4))) == SVector{4,Float32}
36+
37+
# Issue 146
38+
@test [[Point3D(1.0,2.0,3.0)]; [Point3D(4.0,5.0,6.0)]]::Vector{Point3D} == [Point3D(1.0,2.0,3.0), Point3D(4.0,5.0,6.0)]
3639
end
3740

3841
@testset "Mutable Point2D" begin

0 commit comments

Comments
 (0)