Skip to content

Commit de9b4b8

Browse files
mbaumanKristofferC
authored andcommitted
Fix 29545: Implement unaliascopy for ReinterpretArray (#30296)
* Fix 29545: Implement unaliascopy for ReinterpretArray (cherry picked from commit f611b46)
1 parent 67ba3ca commit de9b4b8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

base/reinterpretarray.jl

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

6969
parent(a::ReinterpretArray) = a.parent
7070
dataids(a::ReinterpretArray) = dataids(a.parent)
71+
unaliascopy(a::ReinterpretArray{T}) where {T} = reinterpret(T, unaliascopy(a.parent))
7172

7273
function size(a::ReinterpretArray{T,N,S} where {N}) where {T,S}
7374
psize = size(a.parent)

test/reinterpretarray.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ let a = [0.1 0.2; 0.3 0.4], at = reshape([(i,i+1) for i = 1:2:8], 2, 2)
161161
@test r == OffsetArray(reshape(1:8, 2, 2, 2), (0, offsetvt...))
162162
end
163163

164+
@testset "potentially aliased copies" begin
165+
buffer = UInt8[1,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0]
166+
mid = length(buffer) ÷ 2
167+
x1 = reinterpret(Int64, @view buffer[1:mid])
168+
x2 = reinterpret(Int64, @view buffer[mid+1:end])
169+
x1 .= x2
170+
@test x1 == x2 == [2]
171+
@test x1[] === x2[] === Int64(2)
172+
end
173+
164174
# Test 0-dimensional Arrays
165175
A = zeros(UInt32)
166176
B = reinterpret(Int32,A)

0 commit comments

Comments
 (0)