From 58e4249757875fee928efcc23d53a7dd27e30435 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 5 Mar 2024 10:59:32 +0100 Subject: [PATCH] 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 --- base/pointer.jl | 1 + test/core.jl | 2 ++ 2 files changed, 3 insertions(+) diff --git a/base/pointer.jl b/base/pointer.jl index 86513c076ade65..2f67c8a6757cb2 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -64,6 +64,7 @@ unsafe_convert(::Type{Ptr{Int8}}, s::String) = ccall(:jl_string_ptr, Ptr{Int8}, cconvert(::Type{<:Ptr}, a::Array) = getfield(a, :ref) unsafe_convert(::Type{Ptr{S}}, a::AbstractArray{T}) where {S,T} = convert(Ptr{S}, unsafe_convert(Ptr{T}, a)) +unsafe_convert(::Type{Ptr{T}}, a::Array{T}) where {T} = unsafe_convert(Ptr{T}, a.ref) unsafe_convert(::Type{Ptr{T}}, a::AbstractArray{T}) where {T} = error("conversion to pointer not defined for $(typeof(a))") # TODO: add this deprecation to give a better error: # cconvert(::Type{<:Ptr}, a::AbstractArray) = error("conversion to pointer not defined for $(typeof(a))") diff --git a/test/core.jl b/test/core.jl index aa16380c8a866f..0eca2251cd1460 100644 --- a/test/core.jl +++ b/test/core.jl @@ -8127,3 +8127,5 @@ let M = @__MODULE__ @test Core.set_binding_type!(M, :a_typed_global) === nothing @test Core.get_binding_type(M, :a_typed_global) === Tuple{Union{Integer,Nothing}} end + +@test Base.unsafe_convert(Ptr{Int}, [1]) !== C_NULL