Skip to content

Commit 083c06b

Browse files
committed
fix padding error
1 parent 0522fdc commit 083c06b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/extensions.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,17 @@ tags[:unionall] = d -> UnionAll(d[:var], d[:body])
9090
lower(x::Vector{Any}) = copy(x)
9191
lower(x::Vector{UInt8}) = x
9292

93-
reinterpret_(::Type{T}, x) where T =
94-
T[_x for _x in reinterpret(T, x)]
93+
function reinterpret_(::Type{T}, x) where T
94+
r = reinterpret(T, x)
95+
if r isa Base.ReinterpretArray && !(r.readable)
96+
# type mapping was successful, but the array is not readable due to padding
97+
# in that case make r a type-cast view of the original array
98+
# the data might not be restorable on a different machine with different padding or with a different version of Julia
99+
@warn "storing structure with padding, data might not be restorable"
100+
r = unsafe_wrap(Vector{T}, Ptr{T}(pointer(x)), sizeof(x))
101+
end
102+
T[_x for _x in r]
103+
end
95104

96105
function lower(x::Array)
97106
ndims(x) == 1 && !isbitstype(eltype(x)) && return Any[x...]

0 commit comments

Comments
 (0)