From 3ffedc78e73accb9f7b57960d4f096017f653c1b Mon Sep 17 00:00:00 2001 From: jverzani Date: Mon, 18 Sep 2023 17:03:37 -0400 Subject: [PATCH 1/3] add 2-arg hash function --- Project.toml | 2 +- src/PyCall.jl | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 413c2820..54661294 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PyCall" uuid = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" authors = ["Steven G. Johnson ", "Yichao Yu ", "Takafumi Arakaki ", "Simon Kornblith ", "Páll Haraldsson ", "Jon Malmaud ", "Jake Bolewski ", "Keno Fischer ", "Joel Mason ", "Jameson Nash ", "The JuliaPy development team"] -version = "1.96.1" +version = "1.96.2" [deps] Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d" diff --git a/src/PyCall.jl b/src/PyCall.jl index f1987a29..7fc9f2a8 100644 --- a/src/PyCall.jl +++ b/src/PyCall.jl @@ -273,20 +273,20 @@ end const pysalt = hash("PyCall.PyObject") # "salt" to mix in to PyObject hashes hashsalt(x) = hash(x, pysalt) -function hash(o::PyObject) +function hash(o::PyObject, salt::UInt64=pysalt) if ispynull(o) - hashsalt(C_NULL) + hash(C_NULL, salt) elseif is_pyjlwrap(o) # call native Julia hash directly on wrapped Julia objects, # since on 64-bit Windows the Python 2.x hash is only 32 bits - hashsalt(unsafe_pyjlwrap_to_objref(o)) + hash(unsafe_pyjlwrap_to_objref(o), salt) else h = ccall((@pysym :PyObject_Hash), Py_hash_t, (PyPtr,), o) if h == -1 # error pyerr_clear() - return hashsalt(PyPtr(o)) + return hash(PyPtr(o), salt) end - hashsalt(h) + hash(h, salt) end end From 887458511122db05b59d982b0c17c129f2705e2e Mon Sep 17 00:00:00 2001 From: jverzani Date: Wed, 20 Sep 2023 08:47:51 -0400 Subject: [PATCH 2/3] rm hashsalt --- src/PyCall.jl | 4 ++-- src/precompile.jl | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/PyCall.jl b/src/PyCall.jl index 7fc9f2a8..a92cce8f 100644 --- a/src/PyCall.jl +++ b/src/PyCall.jl @@ -271,9 +271,9 @@ end # computing hashes of PyObjects const pysalt = hash("PyCall.PyObject") # "salt" to mix in to PyObject hashes -hashsalt(x) = hash(x, pysalt) -function hash(o::PyObject, salt::UInt64=pysalt) +function hash(o::PyObject, salt::UInt=zero(UInt)) + salt ⊻= pysalt if ispynull(o) hash(C_NULL, salt) elseif is_pyjlwrap(o) diff --git a/src/precompile.jl b/src/precompile.jl index cdd75906..3cf0aac3 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -372,7 +372,6 @@ precompile(Tuple{typeof(getproperty), PyDict{Int64, String, true}, Symbol}) precompile(Tuple{typeof(getproperty), PyError, Symbol}) precompile(Tuple{typeof(getproperty), PyObject, String}) precompile(Tuple{typeof(hash), PyObject}) -precompile(Tuple{typeof(hashsalt), Function}) precompile(Tuple{typeof(hasproperty), PyObject, String}) precompile(Tuple{typeof(hasproperty), PyObject, Symbol}) precompile(Tuple{typeof(hassym), Ptr{Nothing}, Symbol}) @@ -528,4 +527,4 @@ precompile(Tuple{typeof(unsafe_load), Ptr{Ptr{PyObject_struct}}}) precompile(Tuple{typeof(weakref_callback), Ptr{PyObject_struct}, Ptr{PyObject_struct}}) precompile(Tuple{typeof(xor), Int64, PyObject}) precompile(Tuple{typeof(xor), PyObject, Int64}) -precompile(Tuple{typeof(xor), PyObject, PyObject}) \ No newline at end of file +precompile(Tuple{typeof(xor), PyObject, PyObject}) From 3c7a753b77540a904e5d30fe3b4b63f134e7329a Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Mon, 8 Jan 2024 14:25:01 -0500 Subject: [PATCH 3/3] Update src/PyCall.jl --- src/PyCall.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PyCall.jl b/src/PyCall.jl index a92cce8f..a5d5738f 100644 --- a/src/PyCall.jl +++ b/src/PyCall.jl @@ -272,7 +272,7 @@ end const pysalt = hash("PyCall.PyObject") # "salt" to mix in to PyObject hashes -function hash(o::PyObject, salt::UInt=zero(UInt)) +function hash(o::PyObject, salt::UInt) salt ⊻= pysalt if ispynull(o) hash(C_NULL, salt)