Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1986)

Unified Diff: Objects/complexobject.c

Issue 660042: Compatible numeric hashes Base URL: http://svn.python.org/view/*checkout*/python/branches/py3k/
Patch Set: Add details about complex hash computation; reorganize sys.hash_info Created 13 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Objects/complexobject.c
===================================================================
--- Objects/complexobject.c (revision 81464)
+++ Objects/complexobject.c (working copy)
@@ -403,12 +403,12 @@
static long
complex_hash(PyComplexObject *v)
{
- long hashreal, hashimag, combined;
- hashreal = _Py_HashDouble(v->cval.real);
- if (hashreal == -1)
+ unsigned long hashreal, hashimag, combined;
+ hashreal = (unsigned long)_Py_HashDouble(v->cval.real);
+ if (hashreal == (unsigned long)-1)
return -1;
- hashimag = _Py_HashDouble(v->cval.imag);
- if (hashimag == -1)
+ hashimag = (unsigned long)_Py_HashDouble(v->cval.imag);
+ if (hashimag == (unsigned long)-1)
return -1;
/* Note: if the imaginary part is 0, hashimag is 0 now,
* so the following returns hashreal unchanged. This is
@@ -416,10 +416,10 @@
* compare equal must have the same hash value, so that
* hash(x + 0*j) must equal hash(x).
*/
- combined = hashreal + 1000003 * hashimag;
- if (combined == -1)
- combined = -2;
- return combined;
+ combined = hashreal + _PyHASH_IMAG * hashimag;
+ if (combined == (unsigned long)-1)
+ combined = (unsigned long)-2;
+ return (long)combined;
}
/* This macro may return! */
« Doc/library/stdtypes.rst ('K') | « Lib/test/test_sys.py ('k') | Objects/longobject.c » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b