diff -r 9e8e15993aae Modules/_datetimemodule.c --- a/Modules/_datetimemodule.c Tue Sep 13 20:48:13 2016 +0200 +++ b/Modules/_datetimemodule.c Tue Sep 13 21:43:12 2016 -0700 @@ -2834,21 +2834,19 @@ return clone; } -static Py_hash_t -generic_hash(unsigned char *data, int len) -{ - return _Py_HashBytes(data, len); -} - - static PyObject *date_getstate(PyDateTime_Date *self); static Py_hash_t date_hash(PyDateTime_Date *self) { if (self->hashcode == -1) { - self->hashcode = generic_hash( - (unsigned char *)self->data, _PyDateTime_DATE_DATASIZE); + // Force the 8-byte alignment required by _Py_HashBytes. + union { + unsigned char bytes[sizeof(self->data)]; + uint64_t dummy; + } data; + memcpy(data.bytes, self->data, sizeof(self->data)); + self->hashcode = _Py_HashBytes(data.bytes, sizeof(self->data)); } return self->hashcode; @@ -3883,9 +3881,15 @@ return -1; /* Reduce this to a hash of another object. */ - if (offset == Py_None) - self->hashcode = generic_hash( - (unsigned char *)self->data, _PyDateTime_TIME_DATASIZE); + if (offset == Py_None) { + // Force the 8-byte alignment required by _Py_HashBytes. + union { + unsigned char bytes[sizeof(self->data)]; + uint64_t dummy; + } data; + memcpy(data.bytes, self->data, sizeof(self->data)); + self->hashcode = _Py_HashBytes(data.bytes, sizeof(self->data)); + } else { PyObject *temp1, *temp2; int seconds, microseconds; @@ -4959,9 +4963,15 @@ return -1; /* Reduce this to a hash of another object. */ - if (offset == Py_None) - self->hashcode = generic_hash( - (unsigned char *)self->data, _PyDateTime_DATETIME_DATASIZE); + if (offset == Py_None) { + // Force the 8-byte alignment required by _Py_HashBytes. + union { + unsigned char bytes[sizeof(self->data)]; + uint64_t dummy; + } data; + memcpy(data.bytes, self->data, sizeof(self->data)); + self->hashcode = _Py_HashBytes(data.bytes, sizeof(self->data)); + } else { PyObject *temp1, *temp2; int days, seconds; diff -r 9e8e15993aae Objects/memoryobject.c --- a/Objects/memoryobject.c Tue Sep 13 20:48:13 2016 +0200 +++ b/Objects/memoryobject.c Tue Sep 13 21:43:12 2016 -0700 @@ -2851,7 +2851,8 @@ return -1; } - if (!MV_C_CONTIGUOUS(self->flags)) { + // _Py_HashBytes requires a 8-byte-aligned contiguous buffer. + if (!MV_C_CONTIGUOUS(self->flags) || ((uintptr_t)mem & 0x7) != 0) { mem = PyMem_Malloc(view->len); if (mem == NULL) { PyErr_NoMemory(); diff -r 9e8e15993aae Python/pyhash.c --- a/Python/pyhash.c Tue Sep 13 20:48:13 2016 +0200 +++ b/Python/pyhash.c Tue Sep 13 21:43:12 2016 -0700 @@ -154,6 +154,9 @@ return 0; } + // 8-byte alignment is required. + assert(((uintptr_t)src & 0x7) == 0); + #ifdef Py_HASH_STATS hashstats[(len <= Py_HASH_STATS_MAX) ? len : 0]++; #endif