Skip to content

Commit

Permalink
Merge pull request #15 from nalimilan/nl/0.7
Browse files Browse the repository at this point in the history
Fix most deprecations on Julia 0.7
  • Loading branch information
oxinabox authored May 11, 2018
2 parents ecb7d92 + 0eed73e commit 0b9aa8e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.6
Compat 0.52
7 changes: 3 additions & 4 deletions src/InternedStrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ Licensed under MIT License, see LICENSE.md
"""
module InternedStrings

using Compat

export @i_str, intern

Base.@deprecate_binding(InternedString, String, true)

@static if VERSION < v"0.7.0-DEV"
const Nothing = Void
const ht_keyindex2! = Base.ht_keyindex2
add_finalizer(fun::Function, obj) = Base.finalizer(obj, fun)
else
using Base: ht_keyindex2!
const add_finalizer = Base.finalizer
end

########################
Expand All @@ -43,7 +42,7 @@ end
# Not found, so add it,
# and mark it as a reference we track to delete!
kk::K = convert(K, key)
add_finalizer(wkd.finalizer, kk) # finalizer is set on the strong ref
@compat finalizer(wkd.finalizer, kk) # finalizer is set on the strong ref
@inbounds Base._setindex!(wkd.ht, nothing, WeakRef(kk), -index)
unlock(wkd.lock)
return kk # Return the strong ref
Expand Down
1 change: 1 addition & 0 deletions test/all_kinds_of_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ end
s1 = "ex"
s2 = "ex"
ex1 = @inferred intern(String, WeakRefString(unsafe_wrap(Vector{UInt8}, s1)))
@test ex1=="ex"
@test !addr_eq(ex1, s1)
@test ex1 isa String
ex2 = @inferred intern(String, WeakRefString(unsafe_wrap(Vector{UInt8}, s2)))
Expand Down
15 changes: 9 additions & 6 deletions test/corefunctionality.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ end
end
end

using Compat.GC
@testset "Garbage Collection 1" begin let
empty!(InternedStrings.pool)
@test length(InternedStrings.pool)==0
ai = intern("Hello My Friends3")
ai = [44] #remove the reference
gc();
GC.gc();
@test 0<=length(InternedStrings.pool)<=1 #May or may not have been collected yet
end end

Expand All @@ -79,25 +80,27 @@ end end
@test length(InternedStrings.pool)==1
use(ai,bi)
ai = [44]
gc()
GC.gc()
@test length(InternedStrings.pool)==1 #don't collect when only one reference is gone
use(bi)
bi=[32]
gc()
GC.gc()
@test 0<=length(InternedStrings.pool)<=1
end end


using Compat.Random
srand(1)
@testset "Garbage Collection stress test" begin let
empty!(InternedStrings.pool)
oldpoolsize = length(InternedStrings.pool)
function checkpool(op)
gc()
GC.gc()
@test op(length(InternedStrings.pool), oldpoolsize)
oldpoolsize = length(InternedStrings.pool)
end

originals = [randstring(rand(1:1024)) for _ in 1:10^5]
originals = [Random.randstring(rand(1:1024)) for _ in 1:10^5]
n_orginals = length(originals)

interns = intern.(originals);
Expand All @@ -111,7 +114,7 @@ srand(1)
checkpool(==)

for ii in 1:30
shuffle!(interns)
Random.shuffle!(interns)
for jj in 1:1000
pop!(interns)
end
Expand Down

0 comments on commit 0b9aa8e

Please sign in to comment.