Skip to content

Commit a30c4c2

Browse files
committed
update code and tests to limit false global sharing
ref #19324
1 parent 0189574 commit a30c4c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1497
-1258
lines changed

base/multimedia.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ for mime in ["application/atom+xml", "application/ecmascript",
154154
"application/x-latex", "application/xhtml+xml", "application/xml",
155155
"application/xml-dtd", "image/svg+xml", "model/vrml",
156156
"model/x3d+vrml", "model/x3d+xml"]
157-
istextmime(::MIME{Symbol(mime)}) = true
157+
global istextmime(::MIME{Symbol(mime)}) = true
158158
end
159159

160160
###########################################################################

base/nullable.jl

+3
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ all(f::typeof(hasvalue), t::Tuple{}) = true
388388

389389
# Note this list does not include sqrt since it can raise a DomainError
390390
for op in (+, -, abs, abs2)
391+
global null_safe_op
391392
null_safe_op(::typeof(op), ::NullSafeTypes) = true
392393
null_safe_op(::typeof(op), ::Type{Complex{S}}) where {S} = null_safe_op(op, S)
393394
null_safe_op(::typeof(op), ::Type{Rational{S}}) where {S} = null_safe_op(op, S)
@@ -404,11 +405,13 @@ null_safe_op(::typeof(!), ::Type{Bool}) = true
404405
for op in (+, -, *, /, &, |, <<, >>, >>>,
405406
scalarmin, scalarmax)
406407
# to fix ambiguities
408+
global null_safe_op
407409
null_safe_op(::typeof(op), ::NullSafeFloats, ::NullSafeFloats) = true
408410
null_safe_op(::typeof(op), ::NullSafeSignedInts, ::NullSafeSignedInts) = true
409411
null_safe_op(::typeof(op), ::NullSafeUnsignedInts, ::NullSafeUnsignedInts) = true
410412
end
411413
for op in (+, -, *, /)
414+
global null_safe_op
412415
null_safe_op(::typeof(op), ::Type{Complex{S}}, ::Type{T}) where {S,T} =
413416
null_safe_op(op, T, S)
414417
null_safe_op(::typeof(op), ::Type{Rational{S}}, ::Type{T}) where {S,T} =

base/test.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ function testset_forloop(args, testloop)
10101010
end
10111011
quote
10121012
arr = Array{Any,1}(0)
1013-
first_iteration = true
1013+
local first_iteration = true
10141014
local ts
10151015
try
10161016
$(Expr(:for, Expr(:block, [esc(v) for v in loopvars]...), blk))

test/abstractarray.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ end
158158
@test ind2sub((0:3,3:5,-101:-100), l) == (i-1, j+2, k-102)
159159
end
160160

161-
A = reshape(collect(1:9), (3,3))
161+
local A = reshape(collect(1:9), (3,3))
162162
@test ind2sub(size(A), 6) == (3,2)
163163
@test sub2ind(size(A), 3, 2) == 6
164164
@test ind2sub(A, 6) == (3,2)

test/arrayops.jl

+71-52
Original file line numberDiff line numberDiff line change
@@ -585,30 +585,34 @@ end
585585

586586
# unique across dim
587587

588-
# All rows and columns unique
589-
A = ones(10, 10)
590-
A[diagind(A)] = shuffle!([1:10;])
591-
@test unique(A, 1) == A
592-
@test unique(A, 2) == A
593-
594-
# 10 repeats of each row
595-
B = A[shuffle!(repmat(1:10, 10)), :]
596-
C = unique(B, 1)
597-
@test sortrows(C) == sortrows(A)
598-
@test unique(B, 2) == B
599-
@test unique(B.', 2).' == C
600-
601-
# Along third dimension
602-
D = cat(3, B, B)
603-
@test unique(D, 1) == cat(3, C, C)
604-
@test unique(D, 3) == cat(3, B)
605-
606588
# With hash collisions
607589
struct HashCollision
608590
x::Float64
609591
end
610592
Base.hash(::HashCollision, h::UInt) = h
611-
@test map(x->x.x, unique(map(HashCollision, B), 1)) == C
593+
594+
# All rows and columns unique
595+
let A, B, C, D
596+
A = ones(10, 10)
597+
A[diagind(A)] = shuffle!([1:10;])
598+
@test unique(A, 1) == A
599+
@test unique(A, 2) == A
600+
601+
# 10 repeats of each row
602+
B = A[shuffle!(repmat(1:10, 10)), :]
603+
C = unique(B, 1)
604+
@test sortrows(C) == sortrows(A)
605+
@test unique(B, 2) == B
606+
@test unique(B.', 2).' == C
607+
608+
# Along third dimension
609+
D = cat(3, B, B)
610+
@test unique(D, 1) == cat(3, C, C)
611+
@test unique(D, 3) == cat(3, B)
612+
613+
# With hash collisions
614+
@test map(x -> x.x, unique(map(HashCollision, B), 1)) == C
615+
end
612616

613617
@testset "large matrices transpose" begin
614618
for i = 1 : 3
@@ -956,7 +960,7 @@ end
956960
end
957961

958962
@testset "mapslices" begin
959-
local a,h,i
963+
local a, b, c, m, h, s
960964
a = rand(5,5)
961965
s = mapslices(sort, a, [1])
962966
S = mapslices(sort, a, [2])
@@ -1124,7 +1128,9 @@ end
11241128
for idx in Any[1, 2, 5, 9, 10, 1:0, 2:1, 1:1, 2:2, 1:2, 2:4, 9:8, 10:9, 9:9, 10:10,
11251129
8:9, 9:10, 6:9, 7:10]
11261130
for repl in Any[[], [11], [11,22], [11,22,33,44,55]]
1127-
a = [1:10;]; acopy = copy(a)
1131+
local a
1132+
a = [1:10;]
1133+
acopy = copy(a)
11281134
@test splice!(a, idx, repl) == acopy[idx]
11291135
@test a == [acopy[1:(first(idx)-1)]; repl; acopy[(last(idx)+1):end]]
11301136
end
@@ -1266,9 +1272,10 @@ end
12661272
end
12671273

12681274
# issue 4228
1269-
A = [[i i; i i] for i=1:2]
1270-
@test cumsum(A) == Any[[1 1; 1 1], [3 3; 3 3]]
1271-
@test cumprod(A) == Any[[1 1; 1 1], [4 4; 4 4]]
1275+
let A = [[i i; i i] for i=1:2]
1276+
@test cumsum(A) == Any[[1 1; 1 1], [3 3; 3 3]]
1277+
@test cumprod(A) == Any[[1 1; 1 1], [4 4; 4 4]]
1278+
end
12721279

12731280
@testset "prepend/append" begin
12741281
# PR #4627
@@ -1293,9 +1300,10 @@ A = [[i i; i i] for i=1:2]
12931300
@test prepend!([1,2], OffsetArray([9,8], (-3,))) == [9,8,1,2]
12941301
end
12951302

1296-
A = [1,2]
1297-
s = Set([1,2,3])
1298-
@test sort(append!(A, s)) == [1,1,2,2,3]
1303+
let A = [1,2]
1304+
s = Set([1,2,3])
1305+
@test sort(append!(A, s)) == [1,1,2,2,3]
1306+
end
12991307

13001308
@testset "cases where shared arrays can/can't be grown" begin
13011309
A = [1 3;2 4]
@@ -1332,8 +1340,10 @@ end
13321340

13331341
# issue #6645 (32-bit)
13341342
let x = Float64[]
1335-
for i=1:5; push!(x, 1.0); end
1336-
@test dot(zeros(5),x) == 0.0
1343+
for i = 1:5
1344+
push!(x, 1.0)
1345+
end
1346+
@test dot(zeros(5), x) == 0.0
13371347
end
13381348

13391349
# issue #6977
@@ -1346,10 +1356,12 @@ end
13461356
@test map(join, ["z", "я"]) == ["z", "я"]
13471357

13481358
# Handle block matrices
1349-
A = [randn(2,2) for i = 1:2, j = 1:2]
1350-
@test issymmetric(A.'A)
1351-
A = [complex.(randn(2,2), randn(2,2)) for i = 1:2, j = 1:2]
1352-
@test ishermitian(A'A)
1359+
let A = [randn(2, 2) for i = 1:2, j = 1:2]
1360+
@test issymmetric(A.'A)
1361+
end
1362+
let A = [complex.(randn(2, 2), randn(2, 2)) for i = 1:2, j = 1:2]
1363+
@test ishermitian(A'A)
1364+
end
13531365

13541366
# issue #7197
13551367
function i7197()
@@ -1794,25 +1806,30 @@ for (a,s) in zip(A, S)
17941806
@test a == s
17951807
end
17961808

1797-
C = copy(B)
1798-
@test A == C
1799-
@test B == C
1809+
let C = copy(B)
1810+
@test A == C
1811+
@test B == C
1812+
end
18001813

18011814
@test vec(A) == vec(B) == vec(S)
18021815
@test minimum(A) == minimum(B) == minimum(S)
18031816
@test maximum(A) == maximum(B) == maximum(S)
18041817

1805-
a, ai = findmin(A)
1806-
b, bi = findmin(B)
1807-
s, si = findmin(S)
1808-
@test a == b == s
1809-
@test ai == bi == si
1818+
let
1819+
a, ai = findmin(A)
1820+
b, bi = findmin(B)
1821+
s, si = findmin(S)
1822+
@test a == b == s
1823+
@test ai == bi == si
1824+
end
18101825

1811-
a, ai = findmax(A)
1812-
b, bi = findmax(B)
1813-
s, si = findmax(S)
1814-
@test a == b == s
1815-
@test ai == bi == si
1826+
let
1827+
a, ai = findmax(A)
1828+
b, bi = findmax(B)
1829+
s, si = findmax(S)
1830+
@test a == b == s
1831+
@test ai == bi == si
1832+
end
18161833

18171834
for X in (A, B, S)
18181835
@test findmin(X) == findmin(Dict(pairs(X)))
@@ -1970,6 +1987,7 @@ end
19701987
end
19711988

19721989
@testset "sign, conj, ~" begin
1990+
local A, B, C
19731991
A = [-10,0,3]
19741992
B = [-10.0,0.0,3.0]
19751993
C = [1,im,0]
@@ -1991,7 +2009,7 @@ end
19912009
end
19922010

19932011
@testset "issue #16247" begin
1994-
A = zeros(3,3)
2012+
local A = zeros(3,3)
19952013
@test size(A[:,0x1:0x2]) == (3, 2)
19962014
@test size(A[:,UInt(1):UInt(2)]) == (3,2)
19972015
@test size(similar(A, UInt(3), 0x3)) == size(similar(A, (UInt(3), 0x3))) == (3,3)
@@ -2007,11 +2025,12 @@ for op in (:+, :*, :÷, :%, :<<, :>>, :-, :/, :\, ://, :^)
20072025
@eval import Base.$(op)
20082026
@eval $(op)(::Foo, ::Foo) = Foo()
20092027
end
2010-
A = fill(Foo(), 10, 10)
2011-
@test typeof(A+A) == Matrix{Foo}
2012-
@test typeof(A-A) == Matrix{Foo}
2013-
for op in (:.+, :.*, :, :.%, :.<<, :.>>, :.-, :./, :.\, :.//, :.^)
2014-
@eval @test typeof($(op)(A,A)) == Matrix{Foo}
2028+
let A = fill(Foo(), 10, 10)
2029+
@test isa(A + A, Matrix{Foo})
2030+
@test isa(A - A, Matrix{Foo})
2031+
for op in (:+, :*, :÷, :%, :<<, :>>, :-, :/, :\, ://, :^)
2032+
@test isa(broadcast(eval(op), A, A), Matrix{Foo})
2033+
end
20152034
end
20162035

20172036
end # module AutoRetType

test/backtrace.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ for l in bt
66
lkup = ccall(:jl_lookup_code_address, Any, (Ptr{Void}, Cint), l, true)
77
if lkup[1][1] == :backtrace
88
@test lkup[1][5] == false # fromC
9-
have_backtrace = true
9+
global have_backtrace = true
1010
break
1111
end
1212
end
@@ -115,10 +115,10 @@ hasbt = hasbt2 = false
115115
for sfs in lkup
116116
for sf in sfs
117117
if sf.func == :bt
118-
hasbt = true
118+
global hasbt = true
119119
end
120120
if sf.func == :bt2
121-
hasbt2 = true
121+
global hasbt2 = true
122122
end
123123
end
124124
end
@@ -138,10 +138,10 @@ hasme = hasbtmacro = false
138138
for sfs in lkup
139139
for sf in sfs
140140
if sf.func == Symbol("macro expansion")
141-
hasme = true
141+
global hasme = true
142142
end
143143
if sf.func == :btmacro
144-
hasbtmacro = true
144+
global hasbtmacro = true
145145
end
146146
end
147147
end

test/bigint.jl

+13-12
Original file line numberDiff line numberDiff line change
@@ -250,21 +250,22 @@ function bigfib(n)
250250
end
251251
@test [bigfib(n) for n=0:10] == [0,1,1,2,3,5,8,13,21,34,55]
252252

253-
n = bigfib(1000001)
254-
@test ndigits(n) == 208988
255-
@test mod(n,big(10)^15) == 359244926937501
256-
@test div(n,big(10)^208973) == 316047687386689
257-
258-
s = string(n)
259-
@test length(s) == 208988
260-
@test endswith(s, "359244926937501")
261-
@test startswith(s, "316047687386689")
253+
let s, n = bigfib(1000001)
254+
@test ndigits(n) == 208988
255+
@test mod(n,big(10)^15) == 359244926937501
256+
@test div(n,big(10)^208973) == 316047687386689
257+
258+
s = string(n)
259+
@test length(s) == 208988
260+
@test endswith(s, "359244926937501")
261+
@test startswith(s, "316047687386689")
262+
end
262263

263264
# serialization (#5133)
264-
let n = parse(BigInt,"359334085968622831041960188598043661065388726959079837")
265+
let n = parse(BigInt, "359334085968622831041960188598043661065388726959079837"),
265266
b = IOBuffer()
266-
serialize(b,n)
267-
seek(b,0)
267+
serialize(b, n)
268+
seek(b, 0)
268269
@test deserialize(b) == n
269270
end
270271

0 commit comments

Comments
 (0)