Skip to content

Commit f0a2a7a

Browse files
authored
re-add unsafe_convert for Reinterpret and Reshaped array (#55226)
Fxes #54725
1 parent e439836 commit f0a2a7a

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

base/reinterpretarray.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ has_offset_axes(a::ReinterpretArray) = has_offset_axes(a.parent)
373373

374374
elsize(::Type{<:ReinterpretArray{T}}) where {T} = sizeof(T)
375375
cconvert(::Type{Ptr{T}}, a::ReinterpretArray{T,N,S} where N) where {T,S} = cconvert(Ptr{S}, a.parent)
376+
unsafe_convert(::Type{Ptr{T}}, a::ReinterpretArray{T,N,S} where N) where {T,S} = Ptr{T}(unsafe_convert(Ptr{S},a.parent))
376377

377378
@propagate_inbounds function getindex(a::NonReshapedReinterpretArray{T,0,S}) where {T,S}
378379
if isprimitivetype(T) && isprimitivetype(S)

base/reshapedarray.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ setindex!(A::ReshapedRange, val, index::ReshapedIndex) = _rs_setindex!_err()
324324
@noinline _rs_setindex!_err() = error("indexed assignment fails for a reshaped range; consider calling collect")
325325

326326
cconvert(::Type{Ptr{T}}, a::ReshapedArray{T}) where {T} = cconvert(Ptr{T}, parent(a))
327+
unsafe_convert(::Type{Ptr{T}}, a::ReshapedArray{T}) where {T} = unsafe_convert(Ptr{T}, a.parent)
327328

328329
# Add a few handy specializations to further speed up views of reshaped ranges
329330
const ReshapedUnitRange{T,N,A<:AbstractUnitRange} = ReshapedArray{T,N,A,Tuple{}}

test/ccall.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,10 @@ end
19371937

19381938
# issue #52025
19391939
@test Base.unsafe_convert(Ptr{Ptr{Cchar}}, Base.cconvert(Ptr{Ptr{Cchar}}, map(pointer, ["ab"]))) isa Ptr{Ptr{Cchar}}
1940-
1940+
#issue #54725
1941+
for A in (reinterpret(UInt, [0]), reshape([0, 0], 1, 2))
1942+
@test pointer(A) == Base.unsafe_convert(Ptr{Cvoid}, A) == Base.unsafe_convert(Ptr{Int}, A)
1943+
end
19411944
# Cglobal with non-static symbols doesn't error
19421945
function cglobal_non_static1()
19431946
sym = (:global_var, libccalltest)

0 commit comments

Comments
 (0)