File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -285,16 +285,23 @@ cdef class Gen(Gen_base):
285
285
>>> L = pari("[42, 2/3, 3.14]")
286
286
>>> hash(L) == hash(L.__copy__())
287
287
True
288
+ >>> hash(pari.isprime(4)) == hash(pari(0))
289
+ True
288
290
"""
289
291
# There is a bug in PARI/GP where the hash value depends on the
290
292
# CLONE bit. So we remove that bit before hashing. See
291
293
# https://pari.math.u-bordeaux.fr/cgi-bin/bugreport.cgi?bug=2091
292
294
cdef ulong* G = < ulong* > self .g
293
295
cdef ulong G0 = G[0 ]
294
- G[0 ] &= ~ < ulong> CLONEBIT
296
+ cdef ulong G0clean = G0 & ~ < ulong> CLONEBIT
297
+ if G0 != G0clean:
298
+ # Only write if we actually need to change something, as
299
+ # G may point to read-only memory
300
+ G[0 ] = G0clean
295
301
h = hash_GEN(self .g)
296
- # Restore CLONE bit
297
- G[0 ] = G0
302
+ if G0 != G0clean:
303
+ # Restore CLONE bit
304
+ G[0 ] = G0
298
305
return h
299
306
300
307
def __iter__ (self ):
You can’t perform that action at this time.
0 commit comments