Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Base.elsize(<:Type{<:MArray}) #1030

Merged
merged 1 commit into from
Jun 1, 2022
Merged

Conversation

vyu
Copy link
Contributor

@vyu vyu commented May 30, 2022

Currently, Base.elsize(<:Type{<:MArray}) is not correct for eltypes for which sizeof is not a multiple of Base.datatype_alignment. This leads to pointer(::MArray, ::Int) giving incorrect addresses. For example:

julia> using StaticArrays

julia> primitive type Test24 24 end

julia> Test24(n) = Base.trunc_int(Test24, n);

julia> a = Test24.(1:4);

julia> m = MVector{4}(a)
4-element MVector{4, Test24} with indices SOneTo(4):
 Test24(0x000001)
 Test24(0x000002)
 Test24(0x000003)
 Test24(0x000004)

julia> GC.@preserve m unsafe_load.(pointer.(Ref(m), 1:4))
4-element Vector{Test24}:
 Test24(0x000001)
 Test24(0x0002be)
 Test24(0x030000)
 Test24(0x000000)

This PR fixes this by calling Base.elsize on the corresponding Vector type. (This issue was previously present in Base JuliaLang/julia#33283.)

Copy link
Collaborator

@thchr thchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@thchr thchr merged commit bb8577a into JuliaArrays:master Jun 1, 2022
@vyu vyu deleted the vyu/elsize branch June 14, 2022 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants