diff --git a/CHANGE_LOG b/CHANGE_LOG index 48302728..52bb4238 100644 --- a/CHANGE_LOG +++ b/CHANGE_LOG @@ -7,7 +7,8 @@ * retire `bitcount_lookup[256]` table * improve `util.count_n()` error messages * avoid `util` module tests from being run more than once in each - call to `bitarray.test()` when called multiple times + call to `bitarray.test()` when called multiple times in the same + Python process, see #6e52e49a * improve testing diff --git a/README.rst b/README.rst index c2b2f30e..1c7f888e 100644 --- a/README.rst +++ b/README.rst @@ -742,7 +742,7 @@ This sub-module was added in version 1.2. ``count_n(a, n, value=1, /)`` -> int Return lowest index ``i`` for which ``a[:i].count(value) == n``. - Raises ``ValueError``, when n exceeds total count (``a.count(value)``). + Raises ``ValueError`` when ``n`` exceeds total count (``a.count(value)``). New in version 2.3.6: optional value argument. diff --git a/bitarray/_bitarray.c b/bitarray/_bitarray.c index 740512f8..ac71ef70 100644 --- a/bitarray/_bitarray.c +++ b/bitarray/_bitarray.c @@ -416,7 +416,7 @@ setrange(bitarrayobject *self, Py_ssize_t a, Py_ssize_t b, int vi) assert(self->readonly == 0); if (b >= a + 8) { - const Py_ssize_t byte_a = BYTES(a); + const Py_ssize_t byte_a = BYTES(a); /* byte range(byte_a, byte_b) */ const Py_ssize_t byte_b = b / 8; assert(a + 8 > 8 * byte_a && 8 * byte_b + 8 > b); @@ -455,7 +455,7 @@ count(bitarrayobject *self, Py_ssize_t a, Py_ssize_t b) cnt += count(self, 64 * wb, b); } else if (n >= 8) { - const Py_ssize_t byte_a = BYTES(a); + const Py_ssize_t byte_a = BYTES(a); /* byte range(byte_a, byte_b) */ const Py_ssize_t byte_b = b / 8; assert(8 * byte_a - a < 8 && b - 8 * byte_b < 8); @@ -494,25 +494,25 @@ find_bit(bitarrayobject *self, int vi, Py_ssize_t a, Py_ssize_t b) Note that we cannot check for n >= 64 here as the function could then go into an infinite recursive loop when a word is found. */ if (n > 64) { - const Py_ssize_t word_a = (a + 63) / 64; - const Py_ssize_t word_b = b / 64; + const Py_ssize_t wa = (a + 63) / 64; /* word range(wa, wb) */ + const Py_ssize_t wb = b / 64; const uint64_t *wbuff = WBUFF(self); const uint64_t w = vi ? 0 : ~0; - if ((res = find_bit(self, vi, a, 64 * word_a)) >= 0) + if ((res = find_bit(self, vi, a, 64 * wa)) >= 0) return res; - for (i = word_a; i < word_b; i++) { /* skip uint64 words */ + for (i = wa; i < wb; i++) { /* skip uint64 words */ assert_byte_in_range(self, 8 * i + 7); if (w ^ wbuff[i]) return find_bit(self, vi, 64 * i, 64 * i + 64); } - return find_bit(self, vi, 64 * word_b, b); + return find_bit(self, vi, 64 * wb, b); } /* For the same reason as above, we cannot check for n >= 8 here. */ if (n > 8) { - const Py_ssize_t byte_a = BYTES(a); + const Py_ssize_t byte_a = BYTES(a); /* byte range(byte_a, byte_b) */ const Py_ssize_t byte_b = b / 8; const char *buff = self->ob_item; const char c = vi ? 0 : ~0; diff --git a/bitarray/_util.c b/bitarray/_util.c index 8d0e9cb9..659b6a99 100644 --- a/bitarray/_util.c +++ b/bitarray/_util.c @@ -188,23 +188,23 @@ find_last(bitarrayobject *self, int vi, Py_ssize_t a, Py_ssize_t b) /* the logic here is the same as in find_bit() in _bitarray.c */ if (n > 64) { - const Py_ssize_t word_a = (a + 63) / 64; - const Py_ssize_t word_b = b / 64; + const Py_ssize_t wa = (a + 63) / 64; /* word range(wa, wb) */ + const Py_ssize_t wb = b / 64; const uint64_t *wbuff = WBUFF(self); const uint64_t w = vi ? 0 : ~0; - if ((res = find_last(self, vi, 64 * word_b, b)) >= 0) + if ((res = find_last(self, vi, 64 * wb, b)) >= 0) return res; - for (i = word_b - 1; i >= word_a; i--) { /* skip uint64 words */ + for (i = wb - 1; i >= wa; i--) { /* skip uint64 words */ if (w ^ wbuff[i]) return find_last(self, vi, 64 * i, 64 * i + 64); } - return find_last(self, vi, a, 64 * word_a); + return find_last(self, vi, a, 64 * wa); } if (n > 8) { - const Py_ssize_t byte_a = BYTES(a); + const Py_ssize_t byte_a = BYTES(a); /* byte range(byte_a, byte_b) */ const Py_ssize_t byte_b = b / 8; const char *buff = self->ob_item; const char c = vi ? 0 : ~0;