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

@ -3,7 +3,7 @@
static unsigned
get_nsizes_impl(const char *cmd) {
unsigned ret;
size_t z;
size_t z;
z = sizeof(unsigned);
expect_d_eq(mallctl(cmd, (void *)&ret, &z, NULL, 0), 0,
@ -25,12 +25,12 @@ get_size_impl(const char *cmd, size_t ind) {
size_t miblen = 4;
z = sizeof(size_t);
expect_d_eq(mallctlnametomib(cmd, mib, &miblen),
0, "Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
expect_d_eq(mallctlnametomib(cmd, mib, &miblen), 0,
"Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
mib[2] = ind;
z = sizeof(size_t);
expect_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0),
0, "Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
expect_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0), 0,
"Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
return ret;
}
@ -58,25 +58,26 @@ TEST_BEGIN(test_grow_and_shrink) {
szs[0] = sallocx(p, 0);
for (i = 0; i < NCYCLES; i++) {
for (j = 1; j < NSZS && szs[j-1] < MAXSZ; j++) {
q = rallocx(p, szs[j-1]+1, 0);
for (j = 1; j < NSZS && szs[j - 1] < MAXSZ; j++) {
q = rallocx(p, szs[j - 1] + 1, 0);
expect_ptr_not_null(q,
"Unexpected rallocx() error for size=%zu-->%zu",
szs[j-1], szs[j-1]+1);
szs[j - 1], szs[j - 1] + 1);
szs[j] = sallocx(q, 0);
expect_zu_ne(szs[j], szs[j-1]+1,
"Expected size to be at least: %zu", szs[j-1]+1);
expect_zu_ne(szs[j], szs[j - 1] + 1,
"Expected size to be at least: %zu",
szs[j - 1] + 1);
p = q;
}
for (j--; j > 0; j--) {
q = rallocx(p, szs[j-1], 0);
q = rallocx(p, szs[j - 1], 0);
expect_ptr_not_null(q,
"Unexpected rallocx() error for size=%zu-->%zu",
szs[j], szs[j-1]);
szs[j], szs[j - 1]);
tsz = sallocx(q, 0);
expect_zu_eq(tsz, szs[j-1],
"Expected size=%zu, got size=%zu", szs[j-1], tsz);
expect_zu_eq(tsz, szs[j - 1],
"Expected size=%zu, got size=%zu", szs[j - 1], tsz);
p = q;
}
}
@ -99,11 +100,12 @@ validate_fill(void *p, uint8_t c, size_t offset, size_t len) {
size_t i;
for (i = 0; i < len; i++) {
uint8_t b = buf[offset+i];
uint8_t b = buf[offset + i];
if (b != c) {
test_fail("Allocation at %p (len=%zu) contains %#x "
"rather than %#x at offset %zu", p, len, b, c,
offset+i);
test_fail(
"Allocation at %p (len=%zu) contains %#x "
"rather than %#x at offset %zu",
p, len, b, c, offset + i);
ret = true;
}
}
@ -118,35 +120,37 @@ TEST_BEGIN(test_zero) {
*/
void *volatile p, *volatile q;
size_t psz, qsz, i, j;
size_t start_sizes[] = {1, 3*1024, 63*1024, 4095*1024};
size_t start_sizes[] = {1, 3 * 1024, 63 * 1024, 4095 * 1024};
#define FILL_BYTE 0xaaU
#define RANGE 2048
for (i = 0; i < sizeof(start_sizes)/sizeof(size_t); i++) {
for (i = 0; i < sizeof(start_sizes) / sizeof(size_t); i++) {
size_t start_size = start_sizes[i];
p = mallocx(start_size, MALLOCX_ZERO);
expect_ptr_not_null(p, "Unexpected mallocx() error");
psz = sallocx(p, 0);
expect_false(validate_fill(p, 0, 0, psz),
"Expected zeroed memory");
expect_false(
validate_fill(p, 0, 0, psz), "Expected zeroed memory");
memset(p, FILL_BYTE, psz);
expect_false(validate_fill(p, FILL_BYTE, 0, psz),
"Expected filled memory");
for (j = 1; j < RANGE; j++) {
q = rallocx(p, start_size+j, MALLOCX_ZERO);
q = rallocx(p, start_size + j, MALLOCX_ZERO);
expect_ptr_not_null(q, "Unexpected rallocx() error");
qsz = sallocx(q, 0);
if (q != p || qsz != psz) {
expect_false(validate_fill(q, FILL_BYTE, 0,
psz), "Expected filled memory");
expect_false(validate_fill(q, 0, psz, qsz-psz),
expect_false(
validate_fill(q, FILL_BYTE, 0, psz),
"Expected filled memory");
expect_false(
validate_fill(q, 0, psz, qsz - psz),
"Expected zeroed memory");
}
if (psz != qsz) {
memset((void *)((uintptr_t)q+psz), FILL_BYTE,
qsz-psz);
memset((void *)((uintptr_t)q + psz), FILL_BYTE,
qsz - psz);
psz = qsz;
}
p = q;
@ -160,7 +164,7 @@ TEST_BEGIN(test_zero) {
TEST_END
TEST_BEGIN(test_align) {
void *p, *q;
void *p, *q;
size_t align;
#define MAX_ALIGN (ZU(1) << 25)
@ -170,12 +174,10 @@ TEST_BEGIN(test_align) {
for (align <<= 1; align <= MAX_ALIGN; align <<= 1) {
q = rallocx(p, 1, MALLOCX_ALIGN(align));
expect_ptr_not_null(q,
"Unexpected rallocx() error for align=%zu", align);
expect_ptr_null(
(void *)((uintptr_t)q & (align-1)),
"%p inadequately aligned for align=%zu",
q, align);
expect_ptr_not_null(
q, "Unexpected rallocx() error for align=%zu", align);
expect_ptr_null((void *)((uintptr_t)q & (align - 1)),
"%p inadequately aligned for align=%zu", q, align);
p = q;
}
dallocx(p, 0);
@ -191,19 +193,19 @@ TEST_BEGIN(test_align_enum) {
for (size_t lg_size = LG_MIN; lg_size <= LG_MAX; ++lg_size) {
size_t size = 1 << lg_size;
for (size_t lg_align_next = LG_MIN;
lg_align_next <= LG_MAX; ++lg_align_next) {
int flags = MALLOCX_LG_ALIGN(lg_align);
lg_align_next <= LG_MAX; ++lg_align_next) {
int flags = MALLOCX_LG_ALIGN(lg_align);
void *p = mallocx(1, flags);
assert_ptr_not_null(p,
"Unexpected mallocx() error");
assert_ptr_not_null(
p, "Unexpected mallocx() error");
assert_zu_eq(nallocx(1, flags),
TEST_MALLOC_SIZE(p),
"Wrong mallocx() usable size");
int flags_next =
MALLOCX_LG_ALIGN(lg_align_next);
int flags_next = MALLOCX_LG_ALIGN(
lg_align_next);
p = rallocx(p, size, flags_next);
assert_ptr_not_null(p,
"Unexpected rallocx() error");
assert_ptr_not_null(
p, "Unexpected rallocx() error");
expect_zu_eq(nallocx(size, flags_next),
TEST_MALLOC_SIZE(p),
"Wrong rallocx() usable size");
@ -223,20 +225,20 @@ TEST_BEGIN(test_lg_align_and_zero) {
*/
void *volatile p, *volatile q;
unsigned lg_align;
size_t sz;
size_t sz;
#define MAX_LG_ALIGN 25
#define MAX_VALIDATE (ZU(1) << 22)
lg_align = 0;
p = mallocx(1, MALLOCX_LG_ALIGN(lg_align)|MALLOCX_ZERO);
p = mallocx(1, MALLOCX_LG_ALIGN(lg_align) | MALLOCX_ZERO);
expect_ptr_not_null(p, "Unexpected mallocx() error");
for (lg_align++; lg_align <= MAX_LG_ALIGN; lg_align++) {
q = rallocx(p, 1, MALLOCX_LG_ALIGN(lg_align)|MALLOCX_ZERO);
expect_ptr_not_null(q,
"Unexpected rallocx() error for lg_align=%u", lg_align);
q = rallocx(p, 1, MALLOCX_LG_ALIGN(lg_align) | MALLOCX_ZERO);
expect_ptr_not_null(
q, "Unexpected rallocx() error for lg_align=%u", lg_align);
expect_ptr_null(
(void *)((uintptr_t)q & ((ZU(1) << lg_align)-1)),
(void *)((uintptr_t)q & ((ZU(1) << lg_align) - 1)),
"%p inadequately aligned for lg_align=%u", q, lg_align);
sz = sallocx(q, 0);
if ((sz << 1) <= MAX_VALIDATE) {
@ -245,9 +247,10 @@ TEST_BEGIN(test_lg_align_and_zero) {
} else {
expect_false(validate_fill(q, 0, 0, MAX_VALIDATE),
"Expected zeroed memory");
expect_false(validate_fill(
(void *)((uintptr_t)q+sz-MAX_VALIDATE),
0, 0, MAX_VALIDATE), "Expected zeroed memory");
expect_false(validate_fill((void *)((uintptr_t)q + sz
- MAX_VALIDATE),
0, 0, MAX_VALIDATE),
"Expected zeroed memory");
}
p = q;
}
@ -269,25 +272,25 @@ JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN
TEST_BEGIN(test_overflow) {
size_t largemax;
void *p;
void *p;
largemax = get_large_size(get_nlarge()-1);
largemax = get_large_size(get_nlarge() - 1);
p = mallocx(1, 0);
expect_ptr_not_null(p, "Unexpected mallocx() failure");
expect_ptr_null(rallocx(p, largemax+1, 0),
"Expected OOM for rallocx(p, size=%#zx, 0)", largemax+1);
expect_ptr_null(rallocx(p, largemax + 1, 0),
"Expected OOM for rallocx(p, size=%#zx, 0)", largemax + 1);
expect_ptr_null(rallocx(p, ZU(PTRDIFF_MAX)+1, 0),
"Expected OOM for rallocx(p, size=%#zx, 0)", ZU(PTRDIFF_MAX)+1);
expect_ptr_null(rallocx(p, ZU(PTRDIFF_MAX) + 1, 0),
"Expected OOM for rallocx(p, size=%#zx, 0)", ZU(PTRDIFF_MAX) + 1);
expect_ptr_null(rallocx(p, SIZE_T_MAX, 0),
"Expected OOM for rallocx(p, size=%#zx, 0)", SIZE_T_MAX);
expect_ptr_null(rallocx(p, 1, MALLOCX_ALIGN(ZU(PTRDIFF_MAX)+1)),
expect_ptr_null(rallocx(p, 1, MALLOCX_ALIGN(ZU(PTRDIFF_MAX) + 1)),
"Expected OOM for rallocx(p, size=1, MALLOCX_ALIGN(%#zx))",
ZU(PTRDIFF_MAX)+1);
ZU(PTRDIFF_MAX) + 1);
dallocx(p, 0);
}
@ -298,11 +301,6 @@ JEMALLOC_DIAGNOSTIC_POP
int
main(void) {
return test(
test_grow_and_shrink,
test_zero,
test_align,
test_align_enum,
test_lg_align_and_zero,
test_overflow);
return test(test_grow_and_shrink, test_zero, test_align,
test_align_enum, test_lg_align_and_zero, test_overflow);
}