Skip to content

Commit 0eed73e

Browse files
committed
Fix most deprecations on Julia 0.7
1 parent ecb7d92 commit 0eed73e

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
julia 0.6
2+
Compat 0.52

src/InternedStrings.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ Licensed under MIT License, see LICENSE.md
77
"""
88
module InternedStrings
99

10+
using Compat
11+
1012
export @i_str, intern
1113

1214
Base.@deprecate_binding(InternedString, String, true)
1315

1416
@static if VERSION < v"0.7.0-DEV"
15-
const Nothing = Void
1617
const ht_keyindex2! = Base.ht_keyindex2
17-
add_finalizer(fun::Function, obj) = Base.finalizer(obj, fun)
1818
else
1919
using Base: ht_keyindex2!
20-
const add_finalizer = Base.finalizer
2120
end
2221

2322
########################
@@ -43,7 +42,7 @@ end
4342
# Not found, so add it,
4443
# and mark it as a reference we track to delete!
4544
kk::K = convert(K, key)
46-
add_finalizer(wkd.finalizer, kk) # finalizer is set on the strong ref
45+
@compat finalizer(wkd.finalizer, kk) # finalizer is set on the strong ref
4746
@inbounds Base._setindex!(wkd.ht, nothing, WeakRef(kk), -index)
4847
unlock(wkd.lock)
4948
return kk # Return the strong ref

test/all_kinds_of_types.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ end
3838
s1 = "ex"
3939
s2 = "ex"
4040
ex1 = @inferred intern(String, WeakRefString(unsafe_wrap(Vector{UInt8}, s1)))
41+
@test ex1=="ex"
4142
@test !addr_eq(ex1, s1)
4243
@test ex1 isa String
4344
ex2 = @inferred intern(String, WeakRefString(unsafe_wrap(Vector{UInt8}, s2)))

test/corefunctionality.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ end
6161
end
6262
end
6363

64+
using Compat.GC
6465
@testset "Garbage Collection 1" begin let
6566
empty!(InternedStrings.pool)
6667
@test length(InternedStrings.pool)==0
6768
ai = intern("Hello My Friends3")
6869
ai = [44] #remove the reference
69-
gc();
70+
GC.gc();
7071
@test 0<=length(InternedStrings.pool)<=1 #May or may not have been collected yet
7172
end end
7273

@@ -79,25 +80,27 @@ end end
7980
@test length(InternedStrings.pool)==1
8081
use(ai,bi)
8182
ai = [44]
82-
gc()
83+
GC.gc()
8384
@test length(InternedStrings.pool)==1 #don't collect when only one reference is gone
8485
use(bi)
8586
bi=[32]
86-
gc()
87+
GC.gc()
8788
@test 0<=length(InternedStrings.pool)<=1
8889
end end
8990

91+
92+
using Compat.Random
9093
srand(1)
9194
@testset "Garbage Collection stress test" begin let
9295
empty!(InternedStrings.pool)
9396
oldpoolsize = length(InternedStrings.pool)
9497
function checkpool(op)
95-
gc()
98+
GC.gc()
9699
@test op(length(InternedStrings.pool), oldpoolsize)
97100
oldpoolsize = length(InternedStrings.pool)
98101
end
99102

100-
originals = [randstring(rand(1:1024)) for _ in 1:10^5]
103+
originals = [Random.randstring(rand(1:1024)) for _ in 1:10^5]
101104
n_orginals = length(originals)
102105

103106
interns = intern.(originals);
@@ -111,7 +114,7 @@ srand(1)
111114
checkpool(==)
112115

113116
for ii in 1:30
114-
shuffle!(interns)
117+
Random.shuffle!(interns)
115118
for jj in 1:1000
116119
pop!(interns)
117120
end

0 commit comments

Comments
 (0)