From 03ba013e2b178e706dd0fa2a60824e7cbb1872aa Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Thu, 6 Dec 2018 18:10:26 -0500 Subject: [PATCH 1/3] Fix 29545: Implement unaliascopy for ReinterpretArray --- base/reinterpretarray.jl | 1 + test/reinterpretarray.jl | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/base/reinterpretarray.jl b/base/reinterpretarray.jl index 2ea21ec981b56..f72766490c3ba 100644 --- a/base/reinterpretarray.jl +++ b/base/reinterpretarray.jl @@ -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) diff --git a/test/reinterpretarray.jl b/test/reinterpretarray.jl index c053bb5ef13ca..e82674fca6766 100644 --- a/test/reinterpretarray.jl +++ b/test/reinterpretarray.jl @@ -160,3 +160,14 @@ let a = [0.1 0.2; 0.3 0.4], at = reshape([(i,i+1) for i = 1:2:8], 2, 2) r = reinterpret(Int, vt) @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(Int, @view buffer[1:mid]) + x2 = reinterpret(Int, @view buffer[mid+1:end]) + x1 .= x2 + @test x1 == x2 == [2] + @test x1[] === x2[] === 2 +end + From 4120791951f509a9ec4a73506685fbdf883fdc2f Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Fri, 7 Dec 2018 10:35:52 -0600 Subject: [PATCH 2/3] Use Int64 instead of Int --- test/reinterpretarray.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/reinterpretarray.jl b/test/reinterpretarray.jl index e82674fca6766..eab3c774a95b2 100644 --- a/test/reinterpretarray.jl +++ b/test/reinterpretarray.jl @@ -164,8 +164,8 @@ 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(Int, @view buffer[1:mid]) - x2 = reinterpret(Int, @view buffer[mid+1:end]) + x1 = reinterpret(Int64, @view buffer[1:mid]) + x2 = reinterpret(Int64, @view buffer[mid+1:end]) x1 .= x2 @test x1 == x2 == [2] @test x1[] === x2[] === 2 From e21c1b6dfc0dd8837bf55f8614935c2ea50e5364 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Fri, 7 Dec 2018 10:36:21 -0600 Subject: [PATCH 3/3] =?UTF-8?q?=E2=80=A6=20and=20here=20too?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/reinterpretarray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/reinterpretarray.jl b/test/reinterpretarray.jl index eab3c774a95b2..de88145cbd393 100644 --- a/test/reinterpretarray.jl +++ b/test/reinterpretarray.jl @@ -168,6 +168,6 @@ end x2 = reinterpret(Int64, @view buffer[mid+1:end]) x1 .= x2 @test x1 == x2 == [2] - @test x1[] === x2[] === 2 + @test x1[] === x2[] === Int64(2) end