Skip to content

Commit c793367

Browse files
PatrickHaeckerKristofferC
authored andcommitted
Base.summarysize for Memory with Union (#57508)
Fixes the double accounting of the union byte array in `Base.summarysize` as described in #57506. If this is the correct fix, can it be backported to 1.11? Fix #57506 (cherry picked from commit 7b7ba33)
1 parent 9833def commit c793367

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

base/summarysize.jl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,8 @@ function (ss::SummarySize)(obj::GenericMemory)
149149
datakey = unsafe_convert(Ptr{Cvoid}, obj)
150150
if !haskey(ss.seen, datakey)
151151
ss.seen[datakey] = true
152-
dsize = sizeof(obj)
152+
size += sizeof(obj)
153153
T = eltype(obj)
154-
if isbitsunion(T)
155-
# add 1 union selector byte for each element
156-
dsize += length(obj)
157-
end
158-
size += dsize
159154
if !isempty(obj) && T !== Symbol && (!Base.allocatedinline(T) || (T isa DataType && !Base.datatype_pointerfree(T)))
160155
push!(ss.frontier_x, obj)
161156
push!(ss.frontier_i, 1)

test/misc.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,11 @@ let z = Z53061[Z53061(S53061(rand(), (rand(),rand())), 0) for _ in 1:10^4]
598598
@test abs(summarysize(z) - 640000)/640000 <= 0.01 broken = Sys.WORD_SIZE == 32 && Sys.islinux()
599599
end
600600

601+
# issue #57506
602+
let len = 100, m1 = Memory{UInt8}(1:len), m2 = Memory{Union{Nothing,UInt8}}(1:len)
603+
@test summarysize(m2) == summarysize(m1) + len
604+
end
605+
601606
## test conversion from UTF-8 to UTF-16 (for Windows APIs)
602607

603608
# empty arrays

0 commit comments

Comments
 (0)