From c1e41aadd81387db193fd19290fca453a04938b7 Mon Sep 17 00:00:00 2001 From: Chris Foster Date: Thu, 27 Feb 2020 16:25:42 +1000 Subject: [PATCH] setindex! for non-isbits MArrays Implement this for the sake of people using MArray in generic code, even though it's unlikely to be fast. --- src/MArray.jl | 4 +--- test/MArray.jl | 9 ++++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/MArray.jl b/src/MArray.jl index a9f452e8e..1345ab530 100644 --- a/src/MArray.jl +++ b/src/MArray.jl @@ -94,9 +94,7 @@ end if isbitstype(T) GC.@preserve v unsafe_store!(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), convert(T, val), i) else - # This one is unsafe (#27) - # unsafe_store!(Base.unsafe_convert(Ptr{Ptr{Nothing}}, pointer_from_objref(v.data)), pointer_from_objref(val), i) - error("setindex!() with non-isbitstype eltype is not supported by StaticArrays. Consider using SizedArray.") + @inbounds v.data = setindex(v.data, val, i) end return val diff --git a/test/MArray.jl b/test/MArray.jl index 3a15eda8e..e6273d752 100644 --- a/test/MArray.jl +++ b/test/MArray.jl @@ -142,9 +142,12 @@ @test_throws BoundsError setindex!(mm, 4, -1) @test_throws BoundsError setindex!(mm, 4, 82) - # setindex with non-elbits type - m = MArray{Tuple{2,2,2}, String}(undef) - @test_throws ErrorException setindex!(m, "a", 1, 1, 1) + # setindex with non-bits eltype + m = fill(MMatrix{2,2, String}, "a") + m[1,1] = "b" + m[1,2] = "c" + @test m == ["b" "c"; + "a" "a"] end @testset "promotion" begin