From 7f45714eda5862a67322ed135554a3ed4f7c6e9c Mon Sep 17 00:00:00 2001 From: Kristoffer Date: Mon, 4 Mar 2024 15:17:12 +0100 Subject: [PATCH 1/2] add back `unsafe_convert` to pointer for arrays --- base/pointer.jl | 1 + test/core.jl | 2 ++ 2 files changed, 3 insertions(+) diff --git a/base/pointer.jl b/base/pointer.jl index 86513c076ade6..7303144cf9979 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} = ccall(:jl_array_ptr, Ptr{T}, (Any,), a) 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 aa16380c8a866..0eca2251cd146 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 From 0cfb8a42de37cbef0626c2a0b36439b9b7d61ef2 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Mon, 4 Mar 2024 17:01:24 +0100 Subject: [PATCH 2/2] Update base/pointer.jl Co-authored-by: Jameson Nash --- base/pointer.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/pointer.jl b/base/pointer.jl index 7303144cf9979..2f67c8a6757cb 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -64,7 +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} = ccall(:jl_array_ptr, Ptr{T}, (Any,), 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))")