diff options
author | Georg Brandl <georg@python.org> | 2012-02-20 23:33:36 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2012-02-20 23:33:36 (GMT) |
commit | 2fb477c0f0284439d40cb3f46eea45ef42446e53 (patch) | |
tree | c8df3747d511256d56ca4af046db7915b5c06096 /Objects/object.c | |
parent | b5c793a0b349cb02003433c30a410595b224079f (diff) | |
parent | 9edceb3e591063f382ae82e14313813ffc1af0bf (diff) | |
download | cpython-2fb477c0f0284439d40cb3f46eea45ef42446e53.zip cpython-2fb477c0f0284439d40cb3f46eea45ef42446e53.tar.gz cpython-2fb477c0f0284439d40cb3f46eea45ef42446e53.tar.bz2 |
Merge 3.2: Issue #13703 plus some related test suite fixes.
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Objects/object.c b/Objects/object.c index 8134825..bb18d47 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -759,10 +759,19 @@ _Py_HashBytes(unsigned char *p, Py_ssize_t len) Py_uhash_t x; Py_ssize_t i; - x = (Py_uhash_t) *p << 7; + /* + We make the hash of the empty string be 0, rather than using + (prefix ^ suffix), since this slightly obfuscates the hash secret + */ + if (len == 0) { + return 0; + } + x = (Py_uhash_t) _Py_HashSecret.prefix; + x ^= (Py_uhash_t) *p << 7; for (i = 0; i < len; i++) x = (_PyHASH_MULTIPLIER * x) ^ (Py_uhash_t) *p++; x ^= (Py_uhash_t) len; + x ^= (Py_uhash_t) _Py_HashSecret.suffix; if (x == -1) x = -2; return x; @@ -776,6 +785,8 @@ PyObject_HashNotImplemented(PyObject *v) return -1; } +_Py_HashSecret_t _Py_HashSecret; + Py_hash_t PyObject_Hash(PyObject *v) { |