diff options
author | Benjamin Peterson <benjamin@python.org> | 2017-12-09 20:18:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-09 20:18:56 (GMT) |
commit | 83620773eef7380178ba84217a26fe22d1636474 (patch) | |
tree | 943b957124e99dd74eb5864aa346239555bd4591 /Python/import.c | |
parent | 4e3e156391e70cd23cae18f2629ec323b3b1e7de (diff) | |
download | cpython-83620773eef7380178ba84217a26fe22d1636474.zip cpython-83620773eef7380178ba84217a26fe22d1636474.tar.gz cpython-83620773eef7380178ba84217a26fe22d1636474.tar.bz2 |
fix my byte-swapping implementation (#4772)
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/Python/import.c b/Python/import.c index b2d7511..892f3d1 100644 --- a/Python/import.c +++ b/Python/import.c @@ -2197,21 +2197,21 @@ static PyObject * _imp_source_hash_impl(PyObject *module, long key, Py_buffer *source) /*[clinic end generated code: output=edb292448cf399ea input=9aaad1e590089789]*/ { - uint64_t hash = _Py_KeyedHash((uint64_t)key, source->buf, source->len); + union { + uint64_t x; + char data[sizeof(uint64_t)]; + } hash; + hash.x = _Py_KeyedHash((uint64_t)key, source->buf, source->len); #if !PY_LITTLE_ENDIAN // Force to little-endian. There really ought to be a succinct standard way // to do this. - union { - uint64_t x; - unsigned char data[sizeof(uint64_t)]; - } pun; - pun.x = hash; - for (size_t i = 0; i < sizeof(pun.data); i++) { - pun.data[sizeof(pun.data) - i - 1] = pun.data[i]; + for (size_t i = 0; i < sizeof(hash.data)/2; i++) { + char tmp = hash.data[i]; + hash.data[i] = hash.data[sizeof(hash.data) - i - 1]; + hash.data[sizeof(hash.data) - i - 1] = tmp; } - hash = pun.x; #endif - return PyBytes_FromStringAndSize((const char *)&hash, sizeof(hash)); + return PyBytes_FromStringAndSize(hash.data, sizeof(hash.data)); } |