Skip to content

Conversation

@nhz2
Copy link
Member

@nhz2 nhz2 commented Jan 2, 2026

This PR also documents cconvert as part of the strided array interface because it may be needed if the default cconvert cannot work.

Here is an example of the bug this change fixes, which is closely related to the bug in #59685

struct MyVec <: AbstractVector{UInt8} end
Base.size(::MyVec) = (8,)
Base.getindex(::MyVec, i::Int) = UInt8(i)
struct MyWrapper x::UInt64 end
Base.cconvert(::Type{Ptr{UInt8}}, ::MyVec) = Base.cconvert(Ref{MyWrapper}, MyWrapper(htol(0x0807060504030201)))
Base.unsafe_convert(::Type{Ptr{UInt8}}, x::Ref{MyWrapper}) = Ptr{UInt8}(Base.unsafe_convert(Ref{MyWrapper}, x))
Base.elsize(::Type{MyVec}) = 1
Base.strides(::MyVec) = (1,)
function has_4(v)
    r = @ccall memchr(v::Ptr{UInt8}, 0x04::Cint, length(v)::Csize_t)::Ptr{Nothing}
    r !== C_NULL
end
has_4(MyVec())
# true
has_4(view(MyVec(), 2:5))
# false

@nhz2 nhz2 added arrays [a, r, r, a, y, s] docs This change adds or pertains to documentation bugfix This change fixes an existing bug labels Jan 2, 2026
@nhz2 nhz2 marked this pull request as draft January 3, 2026 17:41
@nhz2 nhz2 marked this pull request as ready for review January 4, 2026 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrays [a, r, r, a, y, s] bugfix This change fixes an existing bug docs This change adds or pertains to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants