Skip to content

Commit 1c074e2

Browse files
jverzanistevengj
andauthored
add 2-arg hash function (#1054)
* add 2-arg hash function * rm hashsalt * Update src/PyCall.jl --------- Co-authored-by: Steven G. Johnson <[email protected]>
1 parent e54c4ee commit 1c074e2

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/PyCall.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,22 +271,22 @@ end
271271
# computing hashes of PyObjects
272272

273273
const pysalt = hash("PyCall.PyObject") # "salt" to mix in to PyObject hashes
274-
hashsalt(x) = hash(x, pysalt)
275274

276-
function hash(o::PyObject)
275+
function hash(o::PyObject, salt::UInt)
276+
salt ⊻= pysalt
277277
if ispynull(o)
278-
hashsalt(C_NULL)
278+
hash(C_NULL, salt)
279279
elseif is_pyjlwrap(o)
280280
# call native Julia hash directly on wrapped Julia objects,
281281
# since on 64-bit Windows the Python 2.x hash is only 32 bits
282-
hashsalt(unsafe_pyjlwrap_to_objref(o))
282+
hash(unsafe_pyjlwrap_to_objref(o), salt)
283283
else
284284
h = ccall((@pysym :PyObject_Hash), Py_hash_t, (PyPtr,), o)
285285
if h == -1 # error
286286
pyerr_clear()
287-
return hashsalt(PyPtr(o))
287+
return hash(PyPtr(o), salt)
288288
end
289-
hashsalt(h)
289+
hash(h, salt)
290290
end
291291
end
292292

src/precompile.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ precompile(Tuple{typeof(getproperty), PyDict{Int64, String, true}, Symbol})
372372
precompile(Tuple{typeof(getproperty), PyError, Symbol})
373373
precompile(Tuple{typeof(getproperty), PyObject, String})
374374
precompile(Tuple{typeof(hash), PyObject})
375-
precompile(Tuple{typeof(hashsalt), Function})
376375
precompile(Tuple{typeof(hasproperty), PyObject, String})
377376
precompile(Tuple{typeof(hasproperty), PyObject, Symbol})
378377
precompile(Tuple{typeof(hassym), Ptr{Nothing}, Symbol})
@@ -528,4 +527,4 @@ precompile(Tuple{typeof(unsafe_load), Ptr{Ptr{PyObject_struct}}})
528527
precompile(Tuple{typeof(weakref_callback), Ptr{PyObject_struct}, Ptr{PyObject_struct}})
529528
precompile(Tuple{typeof(xor), Int64, PyObject})
530529
precompile(Tuple{typeof(xor), PyObject, Int64})
531-
precompile(Tuple{typeof(xor), PyObject, PyObject})
530+
precompile(Tuple{typeof(xor), PyObject, PyObject})

0 commit comments

Comments
 (0)