From: Benjamin Peterson Date: Tue, 21 Feb 2012 16:12:14 +0000 (-0500) Subject: merge 3.2 X-Git-Tag: v3.3.0a1~112 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d9a3591ed154158adeded5d52c25c7bee4dadfbd;p=thirdparty%2FPython%2Fcpython.git merge 3.2 --- d9a3591ed154158adeded5d52c25c7bee4dadfbd diff --cc Objects/object.c index bb18d471912f,84ec2f34f582..2665d2135fc4 --- a/Objects/object.c +++ b/Objects/object.c @@@ -753,30 -746,6 +753,31 @@@ _Py_HashPointer(void *p return x; } +Py_hash_t +_Py_HashBytes(unsigned char *p, Py_ssize_t len) +{ + Py_uhash_t x; + Py_ssize_t i; + + /* + We make the hash of the empty string be 0, rather than using + (prefix ^ suffix), since this slightly obfuscates the hash secret + */ ++ assert(_Py_HashSecret_Initialized); + 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; +} + Py_hash_t PyObject_HashNotImplemented(PyObject *v) { diff --cc Objects/unicodeobject.c index 75e9923f0d77,b70666106d27..a42aad9ade23 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@@ -11207,18 -7665,18 +11207,19 @@@ unicode_getitem(PyObject *self, Py_ssiz } /* Believe it or not, this produces the same value for ASCII strings - as string_hash(). */ + as bytes_hash(). */ static Py_hash_t -unicode_hash(PyUnicodeObject *self) +unicode_hash(PyObject *self) { Py_ssize_t len; - Py_UNICODE *p; - Py_hash_t x; + Py_uhash_t x; + assert(_Py_HashSecret_Initialized); - if (self->hash != -1) - return self->hash; - len = Py_SIZE(self); + if (_PyUnicode_HASH(self) != -1) + return _PyUnicode_HASH(self); + if (PyUnicode_READY(self) == -1) + return -1; + len = PyUnicode_GET_LENGTH(self); /* We make the hash of the empty string be 0, rather than using (prefix ^ suffix), since this slightly obfuscates the hash secret