Skip to content

Commit

Permalink
setindex! for non-isbits MArrays
Browse files Browse the repository at this point in the history
Implement this for the sake of people using MArray in generic code, even
though it's unlikely to be fast.
  • Loading branch information
c42f committed Feb 27, 2020
1 parent f330604 commit c1e41aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/MArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions test/MArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c1e41aa

Please sign in to comment.