Reformat the codebase with the clang-format 18.

This commit is contained in:
guangli-dai 2025-06-13 12:31:12 -07:00 committed by Guangli Dai
parent 0a6215c171
commit f1bba4a87c
346 changed files with 18286 additions and 17770 deletions

View file

@ -5,21 +5,19 @@
static void
do_test_init(size_t nbits) {
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
fb_group_t *fb = malloc(sz);
/* Junk fb's contents. */
memset(fb, 99, sz);
fb_init(fb, nbits);
for (size_t i = 0; i < nbits; i++) {
expect_false(fb_get(fb, nbits, i),
"bitmap should start empty");
expect_false(fb_get(fb, nbits, i), "bitmap should start empty");
}
free(fb);
}
TEST_BEGIN(test_fb_init) {
#define NB(nbits) \
do_test_init(nbits);
#define NB(nbits) do_test_init(nbits);
NBITS_TAB
#undef NB
}
@ -27,7 +25,7 @@ TEST_END
static void
do_test_get_set_unset(size_t nbits) {
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
fb_group_t *fb = malloc(sz);
fb_init(fb, nbits);
/* Set the bits divisible by 3. */
@ -56,8 +54,7 @@ do_test_get_set_unset(size_t nbits) {
}
TEST_BEGIN(test_get_set_unset) {
#define NB(nbits) \
do_test_get_set_unset(nbits);
#define NB(nbits) do_test_get_set_unset(nbits);
NBITS_TAB
#undef NB
}
@ -65,7 +62,7 @@ TEST_END
static ssize_t
find_3_5_compute(ssize_t i, size_t nbits, bool bit, bool forward) {
for(; i < (ssize_t)nbits && i >= 0; i += (forward ? 1 : -1)) {
for (; i < (ssize_t)nbits && i >= 0; i += (forward ? 1 : -1)) {
bool expected_bit = i % 3 == 0 || i % 5 == 0;
if (expected_bit == bit) {
return i;
@ -76,7 +73,7 @@ find_3_5_compute(ssize_t i, size_t nbits, bool bit, bool forward) {
static void
do_test_search_simple(size_t nbits) {
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
fb_group_t *fb = malloc(sz);
fb_init(fb, nbits);
@ -96,7 +93,7 @@ do_test_search_simple(size_t nbits) {
expect_zu_eq(ffs_compute, ffs_search, "ffs mismatch at %zu", i);
ssize_t fls_compute = find_3_5_compute(i, nbits, true, false);
size_t fls_search = fb_fls(fb, nbits, i);
size_t fls_search = fb_fls(fb, nbits, i);
expect_zu_eq(fls_compute, fls_search, "fls mismatch at %zu", i);
size_t ffu_compute = find_3_5_compute(i, nbits, false, true);
@ -112,8 +109,7 @@ do_test_search_simple(size_t nbits) {
}
TEST_BEGIN(test_search_simple) {
#define NB(nbits) \
do_test_search_simple(nbits);
#define NB(nbits) do_test_search_simple(nbits);
NBITS_TAB
#undef NB
}
@ -145,15 +141,17 @@ expect_exhaustive_results(fb_group_t *mostly_full, fb_group_t *mostly_empty,
"mismatch at %zu, %zu", position, special_bit);
expect_zd_eq(special_bit, fb_fls(mostly_empty, nbits, position),
"mismatch at %zu, %zu", position, special_bit);
expect_zu_eq(position + 1, fb_ffu(mostly_empty, nbits, position),
expect_zu_eq(position + 1,
fb_ffu(mostly_empty, nbits, position),
"mismatch at %zu, %zu", position, special_bit);
expect_zd_eq(position - 1,
fb_flu(mostly_empty, nbits, position),
"mismatch at %zu, %zu", position, special_bit);
expect_zd_eq(position - 1, fb_flu(mostly_empty, nbits,
position), "mismatch at %zu, %zu", position, special_bit);
expect_zu_eq(position + 1, fb_ffs(mostly_full, nbits, position),
"mismatch at %zu, %zu", position, special_bit);
expect_zd_eq(position - 1, fb_fls(mostly_full, nbits,
position), "mismatch at %zu, %zu", position, special_bit);
expect_zd_eq(position - 1, fb_fls(mostly_full, nbits, position),
"mismatch at %zu, %zu", position, special_bit);
expect_zu_eq(position, fb_ffu(mostly_full, nbits, position),
"mismatch at %zu, %zu", position, special_bit);
expect_zd_eq(position, fb_flu(mostly_full, nbits, position),
@ -162,8 +160,8 @@ expect_exhaustive_results(fb_group_t *mostly_full, fb_group_t *mostly_empty,
/* position > special_bit. */
expect_zu_eq(nbits, fb_ffs(mostly_empty, nbits, position),
"mismatch at %zu, %zu", position, special_bit);
expect_zd_eq(special_bit, fb_fls(mostly_empty, nbits,
position), "mismatch at %zu, %zu", position, special_bit);
expect_zd_eq(special_bit, fb_fls(mostly_empty, nbits, position),
"mismatch at %zu, %zu", position, special_bit);
expect_zu_eq(position, fb_ffu(mostly_empty, nbits, position),
"mismatch at %zu, %zu", position, special_bit);
expect_zd_eq(position, fb_flu(mostly_empty, nbits, position),
@ -186,7 +184,7 @@ do_test_search_exhaustive(size_t nbits) {
if (nbits > 1000) {
return;
}
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
fb_group_t *empty = malloc(sz);
fb_init(empty, nbits);
fb_group_t *full = malloc(sz);
@ -209,8 +207,7 @@ do_test_search_exhaustive(size_t nbits) {
}
TEST_BEGIN(test_search_exhaustive) {
#define NB(nbits) \
do_test_search_exhaustive(nbits);
#define NB(nbits) do_test_search_exhaustive(nbits);
NBITS_TAB
#undef NB
}
@ -222,8 +219,8 @@ TEST_BEGIN(test_range_simple) {
* big enough that usages of things like weirdnum (below) near the
* beginning fit comfortably into the beginning of the bitmap.
*/
size_t nbits = 64 * 10;
size_t ngroups = FB_NGROUPS(nbits);
size_t nbits = 64 * 10;
size_t ngroups = FB_NGROUPS(nbits);
fb_group_t *fb = malloc(sizeof(fb_group_t) * ngroups);
fb_init(fb, nbits);
for (size_t i = 0; i < nbits; i++) {
@ -255,7 +252,7 @@ TEST_END
static void
do_test_empty_full_exhaustive(size_t nbits) {
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
fb_group_t *empty = malloc(sz);
fb_init(empty, nbits);
fb_group_t *full = malloc(sz);
@ -273,15 +270,15 @@ do_test_empty_full_exhaustive(size_t nbits) {
expect_false(fb_empty(empty, nbits), "error at bit %zu", i);
if (nbits != 1) {
expect_false(fb_full(empty, nbits),
"error at bit %zu", i);
expect_false(fb_empty(full, nbits),
"error at bit %zu", i);
expect_false(
fb_full(empty, nbits), "error at bit %zu", i);
expect_false(
fb_empty(full, nbits), "error at bit %zu", i);
} else {
expect_true(fb_full(empty, nbits),
"error at bit %zu", i);
expect_true(fb_empty(full, nbits),
"error at bit %zu", i);
expect_true(
fb_full(empty, nbits), "error at bit %zu", i);
expect_true(
fb_empty(full, nbits), "error at bit %zu", i);
}
expect_false(fb_full(full, nbits), "error at bit %zu", i);
@ -294,8 +291,7 @@ do_test_empty_full_exhaustive(size_t nbits) {
}
TEST_BEGIN(test_empty_full) {
#define NB(nbits) \
do_test_empty_full_exhaustive(nbits);
#define NB(nbits) do_test_empty_full_exhaustive(nbits);
NBITS_TAB
#undef NB
}
@ -306,8 +302,8 @@ TEST_END
* built closely on top of it.
*/
TEST_BEGIN(test_iter_range_simple) {
size_t set_limit = 30;
size_t nbits = 100;
size_t set_limit = 30;
size_t nbits = 100;
fb_group_t fb[FB_NGROUPS(100)];
fb_init(fb, nbits);
@ -318,7 +314,7 @@ TEST_BEGIN(test_iter_range_simple) {
*/
size_t begin = (size_t)-1;
size_t len = (size_t)-1;
bool result;
bool result;
/* A set of checks with only the first set_limit bits *set*. */
fb_set_range(fb, nbits, 0, set_limit);
@ -410,7 +406,6 @@ TEST_BEGIN(test_iter_range_simple) {
expect_zu_eq(0, begin, "Incorrect begin at %zu", i);
expect_zu_eq(set_limit, len, "Incorrect len at %zu", i);
}
}
TEST_END
@ -426,11 +421,11 @@ fb_iter_simple(fb_group_t *fb, size_t nbits, size_t start, size_t *r_begin,
ssize_t stride = (forward ? (ssize_t)1 : (ssize_t)-1);
ssize_t range_begin = (ssize_t)start;
for (; range_begin != (ssize_t)nbits && range_begin != -1;
range_begin += stride) {
range_begin += stride) {
if (fb_get(fb, nbits, range_begin) == val) {
ssize_t range_end = range_begin;
for (; range_end != (ssize_t)nbits && range_end != -1;
range_end += stride) {
range_end += stride) {
if (fb_get(fb, nbits, range_end) != val) {
break;
}
@ -470,26 +465,26 @@ fb_range_longest_simple(fb_group_t *fb, size_t nbits, bool val) {
}
static void
expect_iter_results_at(fb_group_t *fb, size_t nbits, size_t pos,
bool val, bool forward) {
bool iter_res;
expect_iter_results_at(
fb_group_t *fb, size_t nbits, size_t pos, bool val, bool forward) {
bool iter_res;
size_t iter_begin JEMALLOC_CC_SILENCE_INIT(0);
size_t iter_len JEMALLOC_CC_SILENCE_INIT(0);
size_t iter_len JEMALLOC_CC_SILENCE_INIT(0);
if (val) {
if (forward) {
iter_res = fb_srange_iter(fb, nbits, pos,
&iter_begin, &iter_len);
iter_res = fb_srange_iter(
fb, nbits, pos, &iter_begin, &iter_len);
} else {
iter_res = fb_srange_riter(fb, nbits, pos,
&iter_begin, &iter_len);
iter_res = fb_srange_riter(
fb, nbits, pos, &iter_begin, &iter_len);
}
} else {
if (forward) {
iter_res = fb_urange_iter(fb, nbits, pos,
&iter_begin, &iter_len);
iter_res = fb_urange_iter(
fb, nbits, pos, &iter_begin, &iter_len);
} else {
iter_res = fb_urange_riter(fb, nbits, pos,
&iter_begin, &iter_len);
iter_res = fb_urange_riter(
fb, nbits, pos, &iter_begin, &iter_len);
}
}
@ -500,15 +495,15 @@ expect_iter_results_at(fb_group_t *fb, size_t nbits, size_t pos,
*/
size_t simple_iter_begin = 0;
size_t simple_iter_len = 0;
simple_iter_res = fb_iter_simple(fb, nbits, pos, &simple_iter_begin,
&simple_iter_len, val, forward);
simple_iter_res = fb_iter_simple(
fb, nbits, pos, &simple_iter_begin, &simple_iter_len, val, forward);
expect_b_eq(iter_res, simple_iter_res, "Result mismatch at %zu", pos);
if (iter_res && simple_iter_res) {
assert_zu_eq(iter_begin, simple_iter_begin,
"Begin mismatch at %zu", pos);
expect_zu_eq(iter_len, simple_iter_len,
"Length mismatch at %zu", pos);
expect_zu_eq(
iter_len, simple_iter_len, "Length mismatch at %zu", pos);
}
}
@ -543,7 +538,7 @@ do_test_iter_range_exhaustive(size_t nbits) {
if (nbits > 1000) {
return;
}
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
fb_group_t *fb = malloc(sz);
fb_init(fb, nbits);
@ -558,7 +553,7 @@ do_test_iter_range_exhaustive(size_t nbits) {
expect_iter_results(fb, nbits);
fb_unset_range(fb, nbits, 0, nbits);
fb_set_range(fb, nbits, 0, nbits / 2 == 0 ? 1: nbits / 2);
fb_set_range(fb, nbits, 0, nbits / 2 == 0 ? 1 : nbits / 2);
expect_iter_results(fb, nbits);
free(fb);
@ -569,8 +564,7 @@ do_test_iter_range_exhaustive(size_t nbits) {
* computation.
*/
TEST_BEGIN(test_iter_range_exhaustive) {
#define NB(nbits) \
do_test_iter_range_exhaustive(nbits);
#define NB(nbits) do_test_iter_range_exhaustive(nbits);
NBITS_TAB
#undef NB
}
@ -581,8 +575,8 @@ TEST_END
* returns the number of set bits in [scount_start, scount_end).
*/
static size_t
scount_contiguous(size_t set_start, size_t set_end, size_t scount_start,
size_t scount_end) {
scount_contiguous(
size_t set_start, size_t set_end, size_t scount_start, size_t scount_end) {
/* No overlap. */
if (set_end <= scount_start || scount_end <= set_start) {
return 0;
@ -611,8 +605,8 @@ scount_contiguous(size_t set_start, size_t set_end, size_t scount_start,
}
static size_t
ucount_contiguous(size_t set_start, size_t set_end, size_t ucount_start,
size_t ucount_end) {
ucount_contiguous(
size_t set_start, size_t set_end, size_t ucount_start, size_t ucount_end) {
/* No overlap. */
if (set_end <= ucount_start || ucount_end <= set_start) {
return ucount_end - ucount_start;
@ -641,34 +635,33 @@ ucount_contiguous(size_t set_start, size_t set_end, size_t ucount_start,
}
static void
expect_count_match_contiguous(fb_group_t *fb, size_t nbits, size_t set_start,
size_t set_end) {
expect_count_match_contiguous(
fb_group_t *fb, size_t nbits, size_t set_start, size_t set_end) {
for (size_t i = 0; i < nbits; i++) {
for (size_t j = i + 1; j <= nbits; j++) {
size_t cnt = j - i;
size_t scount_expected = scount_contiguous(set_start,
set_end, i, j);
size_t scount_expected = scount_contiguous(
set_start, set_end, i, j);
size_t scount_computed = fb_scount(fb, nbits, i, cnt);
expect_zu_eq(scount_expected, scount_computed,
"fb_scount error with nbits=%zu, start=%zu, "
"cnt=%zu, with bits set in [%zu, %zu)",
nbits, i, cnt, set_start, set_end);
size_t ucount_expected = ucount_contiguous(set_start,
set_end, i, j);
size_t ucount_expected = ucount_contiguous(
set_start, set_end, i, j);
size_t ucount_computed = fb_ucount(fb, nbits, i, cnt);
assert_zu_eq(ucount_expected, ucount_computed,
"fb_ucount error with nbits=%zu, start=%zu, "
"cnt=%zu, with bits set in [%zu, %zu)",
nbits, i, cnt, set_start, set_end);
}
}
}
static void
do_test_count_contiguous(size_t nbits) {
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
fb_group_t *fb = malloc(sz);
fb_init(fb, nbits);
@ -688,7 +681,7 @@ do_test_count_contiguous(size_t nbits) {
}
TEST_BEGIN(test_count_contiguous_simple) {
enum {nbits = 300};
enum { nbits = 300 };
fb_group_t fb[FB_NGROUPS(nbits)];
fb_init(fb, nbits);
/* Just an arbitrary number. */
@ -718,10 +711,10 @@ TEST_BEGIN(test_count_contiguous_simple) {
TEST_END
TEST_BEGIN(test_count_contiguous) {
#define NB(nbits) \
/* This test is *particularly* slow in debug builds. */ \
if ((!config_debug && nbits < 300) || nbits < 150) { \
do_test_count_contiguous(nbits); \
#define NB(nbits) \
/* This test is *particularly* slow in debug builds. */ \
if ((!config_debug && nbits < 300) || nbits < 150) { \
do_test_count_contiguous(nbits); \
}
NBITS_TAB
#undef NB
@ -729,15 +722,15 @@ TEST_BEGIN(test_count_contiguous) {
TEST_END
static void
expect_count_match_alternating(fb_group_t *fb_even, fb_group_t *fb_odd,
size_t nbits) {
expect_count_match_alternating(
fb_group_t *fb_even, fb_group_t *fb_odd, size_t nbits) {
for (size_t i = 0; i < nbits; i++) {
for (size_t j = i + 1; j <= nbits; j++) {
size_t cnt = j - i;
size_t odd_scount = cnt / 2
+ (size_t)(cnt % 2 == 1 && i % 2 == 1);
size_t odd_scount_computed = fb_scount(fb_odd, nbits,
i, j - i);
size_t odd_scount_computed = fb_scount(
fb_odd, nbits, i, j - i);
assert_zu_eq(odd_scount, odd_scount_computed,
"fb_scount error with nbits=%zu, start=%zu, "
"cnt=%zu, with alternating bits set.",
@ -745,8 +738,8 @@ expect_count_match_alternating(fb_group_t *fb_even, fb_group_t *fb_odd,
size_t odd_ucount = cnt / 2
+ (size_t)(cnt % 2 == 1 && i % 2 == 0);
size_t odd_ucount_computed = fb_ucount(fb_odd, nbits,
i, j - i);
size_t odd_ucount_computed = fb_ucount(
fb_odd, nbits, i, j - i);
assert_zu_eq(odd_ucount, odd_ucount_computed,
"fb_ucount error with nbits=%zu, start=%zu, "
"cnt=%zu, with alternating bits set.",
@ -754,8 +747,8 @@ expect_count_match_alternating(fb_group_t *fb_even, fb_group_t *fb_odd,
size_t even_scount = cnt / 2
+ (size_t)(cnt % 2 == 1 && i % 2 == 0);
size_t even_scount_computed = fb_scount(fb_even, nbits,
i, j - i);
size_t even_scount_computed = fb_scount(
fb_even, nbits, i, j - i);
assert_zu_eq(even_scount, even_scount_computed,
"fb_scount error with nbits=%zu, start=%zu, "
"cnt=%zu, with alternating bits set.",
@ -763,8 +756,8 @@ expect_count_match_alternating(fb_group_t *fb_even, fb_group_t *fb_odd,
size_t even_ucount = cnt / 2
+ (size_t)(cnt % 2 == 1 && i % 2 == 1);
size_t even_ucount_computed = fb_ucount(fb_even, nbits,
i, j - i);
size_t even_ucount_computed = fb_ucount(
fb_even, nbits, i, j - i);
assert_zu_eq(even_ucount, even_ucount_computed,
"fb_ucount error with nbits=%zu, start=%zu, "
"cnt=%zu, with alternating bits set.",
@ -778,7 +771,7 @@ do_test_count_alternating(size_t nbits) {
if (nbits > 1000) {
return;
}
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
fb_group_t *fb_even = malloc(sz);
fb_group_t *fb_odd = malloc(sz);
@ -800,8 +793,7 @@ do_test_count_alternating(size_t nbits) {
}
TEST_BEGIN(test_count_alternating) {
#define NB(nbits) \
do_test_count_alternating(nbits);
#define NB(nbits) do_test_count_alternating(nbits);
NBITS_TAB
#undef NB
}
@ -809,8 +801,9 @@ TEST_END
static void
do_test_bit_op(size_t nbits, bool (*op)(bool a, bool b),
void (*fb_op)(fb_group_t *dst, fb_group_t *src1, fb_group_t *src2, size_t nbits)) {
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
void (*fb_op)(
fb_group_t *dst, fb_group_t *src1, fb_group_t *src2, size_t nbits)) {
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
fb_group_t *fb1 = malloc(sz);
fb_group_t *fb2 = malloc(sz);
fb_group_t *fb_result = malloc(sz);
@ -853,8 +846,10 @@ do_test_bit_op(size_t nbits, bool (*op)(bool a, bool b),
bool bit2 = ((prng2 & (1ULL << (i % 64))) != 0);
/* Original bitmaps shouldn't change. */
expect_b_eq(bit1, fb_get(fb1, nbits, i), "difference at bit %zu", i);
expect_b_eq(bit2, fb_get(fb2, nbits, i), "difference at bit %zu", i);
expect_b_eq(
bit1, fb_get(fb1, nbits, i), "difference at bit %zu", i);
expect_b_eq(
bit2, fb_get(fb2, nbits, i), "difference at bit %zu", i);
/* New one should be bitwise and. */
expect_b_eq(op(bit1, bit2), fb_get(fb_result, nbits, i),
@ -883,8 +878,7 @@ do_test_bit_and(size_t nbits) {
}
TEST_BEGIN(test_bit_and) {
#define NB(nbits) \
do_test_bit_and(nbits);
#define NB(nbits) do_test_bit_and(nbits);
NBITS_TAB
#undef NB
}
@ -901,8 +895,7 @@ do_test_bit_or(size_t nbits) {
}
TEST_BEGIN(test_bit_or) {
#define NB(nbits) \
do_test_bit_or(nbits);
#define NB(nbits) do_test_bit_or(nbits);
NBITS_TAB
#undef NB
}
@ -915,8 +908,8 @@ binary_not(bool a, bool b) {
}
static void
fb_bit_not_shim(fb_group_t *dst, fb_group_t *src1, fb_group_t *src2,
size_t nbits) {
fb_bit_not_shim(
fb_group_t *dst, fb_group_t *src1, fb_group_t *src2, size_t nbits) {
(void)src2;
fb_bit_not(dst, src1, nbits);
}
@ -927,8 +920,7 @@ do_test_bit_not(size_t nbits) {
}
TEST_BEGIN(test_bit_not) {
#define NB(nbits) \
do_test_bit_not(nbits);
#define NB(nbits) do_test_bit_not(nbits);
NBITS_TAB
#undef NB
}
@ -936,19 +928,9 @@ TEST_END
int
main(void) {
return test_no_reentrancy(
test_fb_init,
test_get_set_unset,
test_search_simple,
test_search_exhaustive,
test_range_simple,
test_empty_full,
test_iter_range_simple,
test_iter_range_exhaustive,
test_count_contiguous_simple,
test_count_contiguous,
test_count_alternating,
test_bit_and,
test_bit_or,
test_bit_not);
return test_no_reentrancy(test_fb_init, test_get_set_unset,
test_search_simple, test_search_exhaustive, test_range_simple,
test_empty_full, test_iter_range_simple, test_iter_range_exhaustive,
test_count_contiguous_simple, test_count_contiguous,
test_count_alternating, test_bit_and, test_bit_or, test_bit_not);
}