Skip to content

pointer fallback for AbstrctArrays broken on master when using old idiom #51962

Open
@chriselrod

Description

@chriselrod

It was common to define

Base.unsafe_convert(::Ptr{T}, A::MyArray) = unsafe_convert(Ptr{T}, parent(A))

e.g.
https://github.com/JuliaArrays/OffsetArrays.jl/blob/a2e68178c5a3233f3d1a7aba39f2a659509574f8/src/OffsetArrays.jl#L464
but the change in behavior of unsafe_convert breaks both old methods of getting a pointer:
pointer and unsafe_convert.

We used to have

pointer(x::AbstractArray{T}) where {T} = unsafe_convert(Ptr{T}, x)

in Base, but it is now implemented as

pointer(x::AbstractArray{T}) where {T} = unsafe_convert(Ptr{T}, cconvert(Ptr{T}, x))

so it seems like unsafe_convert was considered internal and isn't a supported means of getting pointers.

What is the recommended solution?

This causes breakages such as FluxML/NNlib.jl#540 (comment)
I can update packages that called unsafe_convert as an end user, such as LayoutPointers.jl and TriangularSolve.jl, but updating all the packages defining their own pointer methods in terms of unsafe_convert could be a taller order.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions