Skip to content

Commit

Permalink
Fix 29545: Implement unaliascopy for ReinterpretArray (#30296)
Browse files Browse the repository at this point in the history
* Fix 29545: Implement unaliascopy for ReinterpretArray

(cherry picked from commit f611b46)
  • Loading branch information
mbauman authored and KristofferC committed Apr 20, 2019
1 parent 7fb5541 commit 1d7087d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ IndexStyle(a::ReinterpretArray) = IndexStyle(a.parent)

parent(a::ReinterpretArray) = a.parent
dataids(a::ReinterpretArray) = dataids(a.parent)
unaliascopy(a::ReinterpretArray{T}) where {T} = reinterpret(T, unaliascopy(a.parent))

function size(a::ReinterpretArray{T,N,S} where {N}) where {T,S}
psize = size(a.parent)
Expand Down
10 changes: 10 additions & 0 deletions test/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
@test r == OffsetArray(reshape(1:8, 2, 2, 2), (0, offsetvt...))
end

@testset "potentially aliased copies" begin
buffer = UInt8[1,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0]
mid = length(buffer) ÷ 2
x1 = reinterpret(Int64, @view buffer[1:mid])
x2 = reinterpret(Int64, @view buffer[mid+1:end])
x1 .= x2
@test x1 == x2 == [2]
@test x1[] === x2[] === Int64(2)
end

# Test 0-dimensional Arrays
A = zeros(UInt32)
B = reinterpret(Int32,A)
Expand Down

0 comments on commit 1d7087d

Please sign in to comment.