Skip to content

Commit d3ee213

Browse files
KristofferCvtjnash
andauthored
add back unsafe_convert to pointer for arrays (#53589)
This caused a pretty big breakage in the ecosystem (~50 packages) and is according to Jameson "Too breaking for no necessary reason". So let's add it back. --------- Co-authored-by: Jameson Nash <vtjnash@gmail.com>
1 parent 892c491 commit d3ee213

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

base/pointer.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ unsafe_convert(::Type{Ptr{Int8}}, s::String) = ccall(:jl_string_ptr, Ptr{Int8},
6464

6565
cconvert(::Type{<:Ptr}, a::Array) = getfield(a, :ref)
6666
unsafe_convert(::Type{Ptr{S}}, a::AbstractArray{T}) where {S,T} = convert(Ptr{S}, unsafe_convert(Ptr{T}, a))
67+
unsafe_convert(::Type{Ptr{T}}, a::Array{T}) where {T} = unsafe_convert(Ptr{T}, a.ref)
6768
unsafe_convert(::Type{Ptr{T}}, a::AbstractArray{T}) where {T} = error("conversion to pointer not defined for $(typeof(a))")
6869
# TODO: add this deprecation to give a better error:
6970
# cconvert(::Type{<:Ptr}, a::AbstractArray) = error("conversion to pointer not defined for $(typeof(a))")

test/core.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8127,3 +8127,5 @@ let M = @__MODULE__
81278127
@test Core.set_binding_type!(M, :a_typed_global) === nothing
81288128
@test Core.get_binding_type(M, :a_typed_global) === Tuple{Union{Integer,Nothing}}
81298129
end
8130+
8131+
@test Base.unsafe_convert(Ptr{Int}, [1]) !== C_NULL

0 commit comments

Comments
 (0)