Merge pull request #2187 from ThomasWaldmann/fix-hashindex-contains-bigendian

fix ChunkIndex.__contains__ assertion  for big-endian archs
This commit is contained in:
enkore 2017-02-20 09:30:05 +01:00 committed by GitHub
commit 6dd5f0fbec
1 changed files with 4 additions and 4 deletions

View File

@ -232,7 +232,7 @@ cdef class ChunkIndex(IndexBase):
if not data: if not data:
raise KeyError(key) raise KeyError(key)
cdef uint32_t refcount = _le32toh(data[0]) cdef uint32_t refcount = _le32toh(data[0])
assert refcount <= _MAX_VALUE assert refcount <= _MAX_VALUE, "invalid reference count"
return ChunkIndexEntry(refcount, _le32toh(data[1]), _le32toh(data[2])) return ChunkIndexEntry(refcount, _le32toh(data[1]), _le32toh(data[2]))
def __setitem__(self, key, value): def __setitem__(self, key, value):
@ -250,7 +250,7 @@ cdef class ChunkIndex(IndexBase):
assert len(key) == self.key_size assert len(key) == self.key_size
data = <uint32_t *>hashindex_get(self.index, <char *>key) data = <uint32_t *>hashindex_get(self.index, <char *>key)
if data != NULL: if data != NULL:
assert data[0] <= _MAX_VALUE assert _le32toh(data[0]) <= _MAX_VALUE, "invalid reference count"
return data != NULL return data != NULL
def incref(self, key): def incref(self, key):
@ -328,8 +328,8 @@ cdef class ChunkIndex(IndexBase):
if values: if values:
refcount1 = _le32toh(values[0]) refcount1 = _le32toh(values[0])
refcount2 = _le32toh(data[0]) refcount2 = _le32toh(data[0])
assert refcount1 <= _MAX_VALUE assert refcount1 <= _MAX_VALUE, "invalid reference count"
assert refcount2 <= _MAX_VALUE assert refcount2 <= _MAX_VALUE, "invalid reference count"
result64 = refcount1 + refcount2 result64 = refcount1 + refcount2
values[0] = _htole32(min(result64, _MAX_VALUE)) values[0] = _htole32(min(result64, _MAX_VALUE))
values[1] = data[1] values[1] = data[1]