Skip to content

Commit bb8577a

Browse files
authored
Fix Base.elsize(<:Type{<:MArray}) (#1030)
1 parent d72425b commit bb8577a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/MArray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@ function Base.view(
115115
return SizedArray{new_size}(view_from_invoke)
116116
end
117117

118-
Base.elsize(::Type{<:MArray{S,T}}) where {S,T} = sizeof(T)
118+
Base.elsize(::Type{<:MArray{<:Any, T}}) where T = Base.elsize(Vector{T})

test/MArray.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,20 @@
220220
v[] = 2
221221
@test v[] == 2
222222
end
223+
224+
@testset "non-power-of-2 element size" begin
225+
primitive type Test24 24 end
226+
Test24(n) = Base.trunc_int(Test24, n)
227+
a = Test24.(1:4)
228+
m = MVector{4}(a)
229+
@test m == m[:] == m[1:4] == a
230+
@test getindex.(Ref(m), 1:4) == a
231+
@test GC.@preserve m unsafe_load.(pointer(m), 1:4) == a
232+
@test GC.@preserve m unsafe_load.(pointer.(Ref(m), 1:4)) == a
233+
b = Test24.(5:8)
234+
setindex!.(Ref(m), b, 1:4)
235+
@test m == b
236+
end
223237
end
224238

225239
@testset "some special case" begin

0 commit comments

Comments
 (0)