From: Benjamin Peterson Date: Mon, 9 Apr 2012 19:04:39 +0000 (-0400) Subject: merge 3.2 (#14509) X-Git-Tag: v3.3.0a3~269^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=64ed576de8102fc26a6f550f3cca8dcf2c8b6f38;p=python merge 3.2 (#14509) --- 64ed576de8102fc26a6f550f3cca8dcf2c8b6f38 diff --cc Objects/object.c index 5bafbc00e0,84ec2f34f5..c8c1861a4d --- a/Objects/object.c +++ b/Objects/object.c @@@ -753,31 -746,6 +753,33 @@@ _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 + */ ++#ifdef Py_DEBUG + assert(_Py_HashSecret_Initialized); ++#endif + 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 bff33d9ad0,cd17789f53..7e73bc226c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@@ -11328,19 -7665,20 +11328,21 @@@ 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; + #ifdef Py_DEBUG assert(_Py_HashSecret_Initialized); + #endif - 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