Skip to content

Commit cbb3367

Browse files
JeffBezansonKristofferC
authored andcommitted
fix #40773, bug in summarysize on arrays of inlined structs with pointers (#41492)
(cherry picked from commit c49153d)
1 parent 5401722 commit cbb3367

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

base/summarysize.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,13 @@ function (ss::SummarySize)(obj::Array)
120120
if !haskey(ss.seen, datakey)
121121
ss.seen[datakey] = true
122122
dsize = Core.sizeof(obj)
123-
if isbitsunion(eltype(obj))
123+
T = eltype(obj)
124+
if isbitsunion(T)
124125
# add 1 union selector byte for each element
125126
dsize += length(obj)
126127
end
127128
size += dsize
128-
if !isempty(obj) && !Base.allocatedinline(eltype(obj))
129+
if !isempty(obj) && (!Base.allocatedinline(T) || (T isa DataType && !Base.datatype_pointerfree(T)))
129130
push!(ss.frontier_x, obj)
130131
push!(ss.frontier_i, 1)
131132
end

test/misc.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ let vec = vcat(missing, ones(100000))
302302
@test length(unique(summarysize(vec) for i = 1:20)) == 1
303303
end
304304

305+
# issue #40773
306+
let s = Set(1:100)
307+
@test summarysize([s]) > summarysize(s)
308+
end
309+
305310
# issue #13021
306311
let ex = try
307312
Main.x13021 = 0

0 commit comments

Comments
 (0)