File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -90,16 +90,25 @@ tags[:unionall] = d -> UnionAll(d[:var], d[:body])
90
90
lower (x:: Vector{Any} ) = copy (x)
91
91
lower (x:: Vector{UInt8} ) = x
92
92
93
+ const WARN_PADDING = Ref (true )
94
+
93
95
function reinterpret_ (:: Type{T} , x) where T
94
96
r = reinterpret (T, x)
95
97
if r isa Base. ReinterpretArray && ! (r. readable)
96
98
# 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
99
+ # in that case make use unsafe_wrap() to map the data
98
100
# 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
+ WARN_PADDING[] && @warn """
102
+ Storing structure with padding, data might not be restorable.\n
103
+ To suppress this warning, set BSON.WARN_PADDING[] = false.
104
+ """
105
+ GC. @preserve x begin
106
+ a = unsafe_wrap (Vector{T}, Ptr {T} (pointer (x)), sizeof (x) ÷ sizeof (T))
107
+ T[_x for _x in a]
108
+ end
109
+ else
110
+ T[_x for _x in r]
101
111
end
102
- T[_x for _x in r]
103
112
end
104
113
105
114
function lower (x:: Array )
You can’t perform that action at this time.
0 commit comments