Skip to content

Commit

Permalink
Bugfix in argument hashing (fixes #11)
Browse files Browse the repository at this point in the history
  • Loading branch information
zgornel committed Mar 20, 2020
1 parent 6d98d4d commit ac6b4e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
17 changes: 15 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Caching"
uuid = "68ad905a-5087-500a-aae7-0fd6acda2eb1"
authors = ["Corneliu Cofaru <cornel@oxoaresearch.com>"]
version = "0.1.1"
version = "0.1.2"

[deps]
CodecBzip2 = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd"
Expand All @@ -10,5 +10,18 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"

[compat]
julia = "1.0"
CodecBzip2 = "0.5.0, 0.8"
CodecZlib = "0.5.2, 0.8"
DataStructures = "0.15, 1.0.0"
MacroTools = "0.5.0, 1.0.0"
TranscodingStreams = "0.9.3, 1.0.0"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
function arghash(args...; kwargs...)
__hash__ = UInt(0)
for arguments in (args, kwargs)
tmp = UInt(0)
tmp = ""
for arg in arguments
tmp += hash(arg) + hash(typeof(arg))
tmp *= string(hash(arg) + hash(typeof(arg)))
end
__hash__ += hash(tmp)
end
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ _tmpdir = tempdir()
@test dc(i) == foo(i) == i
end
@empty! dc true

# Test for signature args order
# (https://github.com/zgornel/Caching.jl/issues/11)
foo(x, y) = x
foo_c1 = Cache(foo)
@test foo_c1(_an_int, _an_int+1) == _an_int
@test foo_c1(_an_int+1, _an_int) == _an_int+1
end


Expand Down

2 comments on commit ac6b4e2

@atbug
Copy link

@atbug atbug commented on ac6b4e2 Mar 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zgornel Why do you require so many old packages, or are you trying to specify a range of packages? DataStructures = "0.15, 1.0.0" does not mean v0.15-v1.0.0, see https://julialang.github.io/Pkg.jl/dev/compatibility/#compat-pre-1.0-1.

@zgornel
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was a range. Thanks for the heads up, will change later on...

Please sign in to comment.