Skip to content

Commit

Permalink
add back unsafe_convert to pointer for arrays (#53589)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
KristofferC and vtjnash authored Mar 5, 2024
1 parent 892c491 commit d3ee213
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))")
Expand Down
2 changes: 2 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d3ee213

Please sign in to comment.