Mercurial > cpython-lru_cache-weakref
diff Objects/object.c @ 75097:ed76dc34b39d
Merge 3.2: Issue #13703 plus some related test suite fixes.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Tue, 21 Feb 2012 00:33:36 +0100 |
| parents | 78f93eb7dd75 4a31f6b11e7a |
| children | e0d451e24c43 |
line wrap: on
line diff
--- a/Objects/object.c Mon Feb 20 22:06:59 2012 +0100 +++ b/Objects/object.c Tue Feb 21 00:33:36 2012 +0100 @@ -759,10 +759,19 @@ 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 @@ return -1; } +_Py_HashSecret_t _Py_HashSecret; + Py_hash_t PyObject_Hash(PyObject *v) {
