Skip to content

Commit

Permalink
Fix deepcopy for Base.GenericCondition (#46406)
Browse files Browse the repository at this point in the history
(cherry picked from commit 99e8953)
  • Loading branch information
DilumAluthge authored and KristofferC committed Aug 26, 2022
1 parent 5842378 commit bc457f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/deepcopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function deepcopy_internal(x::GenericCondition, stackdict::IdDict)
if haskey(stackdict, x)
return stackdict[x]
end
y = typeof(x)(deepcopy_internal(x.lock))
y = typeof(x)(deepcopy_internal(x.lock, stackdict))
stackdict[x] = y
return y
end
16 changes: 16 additions & 0 deletions test/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,19 @@ end
a = [1:3;]
@test copyto!(a, 2:3, 1:1, a, 1:2, 1:1) == [1;1:2;]
end

@testset "`deepcopy` a `GenericCondition`" begin
a = Base.GenericCondition(ReentrantLock())
@test !islocked(a.lock)
lock(a.lock)
@test islocked(a.lock)
b = deepcopy(a)
@test typeof(a) === typeof(b)
@test a != b
@test a !== b
@test typeof(a.lock) === typeof(b.lock)
@test a.lock != b.lock
@test a.lock !== b.lock
@test islocked(a.lock)
@test !islocked(b.lock)
end

0 comments on commit bc457f6

Please sign in to comment.