Update brace style.

Add braces around single-line blocks, and remove line breaks before
function-opening braces.

This resolves #537.
This commit is contained in:
Jason Evans
2017-01-15 16:56:30 -08:00
parent 5154ff32ee
commit c4c2592c83
119 changed files with 2971 additions and 3572 deletions

View File

@@ -11,8 +11,7 @@ static bool have_dss =
;
void *
thd_start(void *arg)
{
thd_start(void *arg) {
unsigned thread_ind = (unsigned)(uintptr_t)arg;
unsigned arena_ind;
void *p;
@@ -45,8 +44,7 @@ thd_start(void *arg)
return (NULL);
}
TEST_BEGIN(test_MALLOCX_ARENA)
{
TEST_BEGIN(test_MALLOCX_ARENA) {
thd_t thds[NTHREADS];
unsigned i;
@@ -55,14 +53,14 @@ TEST_BEGIN(test_MALLOCX_ARENA)
(void *)(uintptr_t)i);
}
for (i = 0; i < NTHREADS; i++)
for (i = 0; i < NTHREADS; i++) {
thd_join(thds[i], NULL);
}
}
TEST_END
int
main(void)
{
main(void) {
return (test(
test_MALLOCX_ARENA));
}

View File

@@ -8,14 +8,12 @@
* potential OOM on e.g. 32-bit Windows.
*/
static void
purge(void)
{
purge(void) {
assert_d_eq(mallctl("arena.0.purge", NULL, NULL, NULL, 0), 0,
"Unexpected mallctl error");
}
TEST_BEGIN(test_alignment_errors)
{
TEST_BEGIN(test_alignment_errors) {
size_t alignment;
void *p;
@@ -36,8 +34,7 @@ TEST_BEGIN(test_alignment_errors)
}
TEST_END
TEST_BEGIN(test_oom_errors)
{
TEST_BEGIN(test_oom_errors) {
size_t alignment, size;
void *p;
@@ -81,15 +78,15 @@ TEST_BEGIN(test_oom_errors)
}
TEST_END
TEST_BEGIN(test_alignment_and_size)
{
TEST_BEGIN(test_alignment_and_size) {
#define NITER 4
size_t alignment, size, total;
unsigned i;
void *ps[NITER];
for (i = 0; i < NITER; i++)
for (i = 0; i < NITER; i++) {
ps[i] = NULL;
}
for (alignment = 8;
alignment <= MAXALIGN;
@@ -110,8 +107,9 @@ TEST_BEGIN(test_alignment_and_size)
alignment, size, size, buf);
}
total += malloc_usable_size(ps[i]);
if (total >= (MAXALIGN << 1))
if (total >= (MAXALIGN << 1)) {
break;
}
}
for (i = 0; i < NITER; i++) {
if (ps[i] != NULL) {
@@ -127,8 +125,7 @@ TEST_BEGIN(test_alignment_and_size)
TEST_END
int
main(void)
{
main(void) {
return (test(
test_alignment_errors,
test_oom_errors,

View File

@@ -9,8 +9,7 @@ static const bool config_stats =
;
void *
thd_start(void *arg)
{
thd_start(void *arg) {
int err;
void *p;
uint64_t a0, a1, d0, d1;
@@ -19,15 +18,17 @@ thd_start(void *arg)
sz = sizeof(a0);
if ((err = mallctl("thread.allocated", (void *)&a0, &sz, NULL, 0))) {
if (err == ENOENT)
if (err == ENOENT) {
goto label_ENOENT;
}
test_fail("%s(): Error in mallctl(): %s", __func__,
strerror(err));
}
sz = sizeof(ap0);
if ((err = mallctl("thread.allocatedp", (void *)&ap0, &sz, NULL, 0))) {
if (err == ENOENT)
if (err == ENOENT) {
goto label_ENOENT;
}
test_fail("%s(): Error in mallctl(): %s", __func__,
strerror(err));
}
@@ -37,16 +38,18 @@ thd_start(void *arg)
sz = sizeof(d0);
if ((err = mallctl("thread.deallocated", (void *)&d0, &sz, NULL, 0))) {
if (err == ENOENT)
if (err == ENOENT) {
goto label_ENOENT;
}
test_fail("%s(): Error in mallctl(): %s", __func__,
strerror(err));
}
sz = sizeof(dp0);
if ((err = mallctl("thread.deallocatedp", (void *)&dp0, &sz, NULL,
0))) {
if (err == ENOENT)
if (err == ENOENT) {
goto label_ENOENT;
}
test_fail("%s(): Error in mallctl(): %s", __func__,
strerror(err));
}
@@ -96,14 +99,12 @@ label_ENOENT:
return (NULL);
}
TEST_BEGIN(test_main_thread)
{
TEST_BEGIN(test_main_thread) {
thd_start(NULL);
}
TEST_END
TEST_BEGIN(test_subthread)
{
TEST_BEGIN(test_subthread) {
thd_t thd;
thd_create(&thd, thd_start, NULL);
@@ -112,8 +113,7 @@ TEST_BEGIN(test_subthread)
TEST_END
int
main(void)
{
main(void) {
/* Run tests multiple times to check for bad interactions. */
return (test(
test_main_thread,

View File

@@ -1,8 +1,7 @@
#include <memory>
#include "test/jemalloc_test.h"
TEST_BEGIN(test_basic)
{
TEST_BEGIN(test_basic) {
auto foo = new long(4);
assert_ptr_not_null(foo, "Unexpected new[] failure");
delete foo;
@@ -20,8 +19,7 @@ TEST_BEGIN(test_basic)
TEST_END
int
main()
{
main() {
return (test(
test_basic));
}

View File

@@ -7,8 +7,7 @@ const char *malloc_conf = "junk:false";
#include "test/extent_hooks.h"
static void
test_extent_body(unsigned arena_ind)
{
test_extent_body(unsigned arena_ind) {
void *p;
size_t large0, large1, large2, sz;
size_t purge_mib[3];
@@ -67,15 +66,17 @@ test_extent_body(unsigned arena_ind)
xallocx_success_b = (xallocx(p, large0, 0, flags) == large0);
assert_d_eq(mallctlbymib(purge_mib, purge_miblen, NULL, NULL, NULL, 0),
0, "Unexpected arena.%u.purge error", arena_ind);
if (xallocx_success_b)
if (xallocx_success_b) {
assert_true(did_split, "Expected split");
}
xallocx_success_c = (xallocx(p, large0 * 2, 0, flags) == large0 * 2);
if (did_split) {
assert_b_eq(did_decommit, did_commit,
"Expected decommit/commit match");
}
if (xallocx_success_b && xallocx_success_c)
if (xallocx_success_b && xallocx_success_c) {
assert_true(did_merge, "Expected merge");
}
dallocx(p, flags);
try_dalloc = true;
try_decommit = false;
@@ -86,8 +87,7 @@ test_extent_body(unsigned arena_ind)
dallocx(p, flags);
}
TEST_BEGIN(test_extent_manual_hook)
{
TEST_BEGIN(test_extent_manual_hook) {
unsigned arena_ind;
size_t old_size, new_size, sz;
size_t hooks_mib[3];
@@ -155,8 +155,7 @@ TEST_BEGIN(test_extent_manual_hook)
}
TEST_END
TEST_BEGIN(test_extent_auto_hook)
{
TEST_BEGIN(test_extent_auto_hook) {
unsigned arena_ind;
size_t new_size, sz;
extent_hooks_t *new_hooks;
@@ -174,8 +173,7 @@ TEST_BEGIN(test_extent_auto_hook)
TEST_END
int
main(void)
{
main(void) {
return (test(
test_extent_manual_hook,
test_extent_auto_hook));

View File

@@ -5,8 +5,7 @@ const char *malloc_conf = "junk:false";
#endif
static unsigned
get_nsizes_impl(const char *cmd)
{
get_nsizes_impl(const char *cmd) {
unsigned ret;
size_t z;
@@ -18,14 +17,12 @@ get_nsizes_impl(const char *cmd)
}
static unsigned
get_nlarge(void)
{
get_nlarge(void) {
return (get_nsizes_impl("arenas.nlextents"));
}
static size_t
get_size_impl(const char *cmd, size_t ind)
{
get_size_impl(const char *cmd, size_t ind) {
size_t ret;
size_t z;
size_t mib[4];
@@ -43,8 +40,7 @@ get_size_impl(const char *cmd, size_t ind)
}
static size_t
get_large_size(size_t ind)
{
get_large_size(size_t ind) {
return (get_size_impl("arenas.lextent.0.size", ind));
}
@@ -54,14 +50,12 @@ get_large_size(size_t ind)
* potential OOM on e.g. 32-bit Windows.
*/
static void
purge(void)
{
purge(void) {
assert_d_eq(mallctl("arena.0.purge", NULL, NULL, NULL, 0), 0,
"Unexpected mallctl error");
}
TEST_BEGIN(test_overflow)
{
TEST_BEGIN(test_overflow) {
size_t largemax;
largemax = get_large_size(get_nlarge()-1);
@@ -81,8 +75,7 @@ TEST_BEGIN(test_overflow)
}
TEST_END
TEST_BEGIN(test_oom)
{
TEST_BEGIN(test_oom) {
size_t largemax;
bool oom;
void *ptrs[3];
@@ -96,15 +89,17 @@ TEST_BEGIN(test_oom)
oom = false;
for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) {
ptrs[i] = mallocx(largemax, 0);
if (ptrs[i] == NULL)
if (ptrs[i] == NULL) {
oom = true;
}
}
assert_true(oom,
"Expected OOM during series of calls to mallocx(size=%zu, 0)",
largemax);
for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) {
if (ptrs[i] != NULL)
if (ptrs[i] != NULL) {
dallocx(ptrs[i], 0);
}
}
purge();
@@ -122,8 +117,7 @@ TEST_BEGIN(test_oom)
}
TEST_END
TEST_BEGIN(test_basic)
{
TEST_BEGIN(test_basic) {
#define MAXSZ (((size_t)1) << 23)
size_t sz;
@@ -160,16 +154,16 @@ TEST_BEGIN(test_basic)
}
TEST_END
TEST_BEGIN(test_alignment_and_size)
{
TEST_BEGIN(test_alignment_and_size) {
#define MAXALIGN (((size_t)1) << 23)
#define NITER 4
size_t nsz, rsz, sz, alignment, total;
unsigned i;
void *ps[NITER];
for (i = 0; i < NITER; i++)
for (i = 0; i < NITER; i++) {
ps[i] = NULL;
}
for (alignment = 8;
alignment <= MAXALIGN;
@@ -202,8 +196,9 @@ TEST_BEGIN(test_alignment_and_size)
" alignment=%zu, size=%zu", ps[i],
alignment, sz);
total += rsz;
if (total >= (MAXALIGN << 1))
if (total >= (MAXALIGN << 1)) {
break;
}
}
for (i = 0; i < NITER; i++) {
if (ps[i] != NULL) {
@@ -220,8 +215,7 @@ TEST_BEGIN(test_alignment_and_size)
TEST_END
int
main(void)
{
main(void) {
return (test(
test_overflow,
test_oom,

View File

@@ -1,7 +1,6 @@
#include "test/jemalloc_test.h"
TEST_BEGIN(test_overflow)
{
TEST_BEGIN(test_overflow) {
unsigned nlextents;
size_t mib[4];
size_t sz, miblen, max_size_class;
@@ -41,8 +40,7 @@ TEST_BEGIN(test_overflow)
TEST_END
int
main(void)
{
main(void) {
return (test(
test_overflow));
}

View File

@@ -8,14 +8,12 @@
* potential OOM on e.g. 32-bit Windows.
*/
static void
purge(void)
{
purge(void) {
assert_d_eq(mallctl("arena.0.purge", NULL, NULL, NULL, 0), 0,
"Unexpected mallctl error");
}
TEST_BEGIN(test_alignment_errors)
{
TEST_BEGIN(test_alignment_errors) {
size_t alignment;
void *p;
@@ -34,8 +32,7 @@ TEST_BEGIN(test_alignment_errors)
}
TEST_END
TEST_BEGIN(test_oom_errors)
{
TEST_BEGIN(test_oom_errors) {
size_t alignment, size;
void *p;
@@ -73,16 +70,16 @@ TEST_BEGIN(test_oom_errors)
}
TEST_END
TEST_BEGIN(test_alignment_and_size)
{
TEST_BEGIN(test_alignment_and_size) {
#define NITER 4
size_t alignment, size, total;
unsigned i;
int err;
void *ps[NITER];
for (i = 0; i < NITER; i++)
for (i = 0; i < NITER; i++) {
ps[i] = NULL;
}
for (alignment = 8;
alignment <= MAXALIGN;
@@ -104,8 +101,9 @@ TEST_BEGIN(test_alignment_and_size)
alignment, size, size, buf);
}
total += malloc_usable_size(ps[i]);
if (total >= (MAXALIGN << 1))
if (total >= (MAXALIGN << 1)) {
break;
}
}
for (i = 0; i < NITER; i++) {
if (ps[i] != NULL) {
@@ -121,8 +119,7 @@ TEST_BEGIN(test_alignment_and_size)
TEST_END
int
main(void)
{
main(void) {
return (test(
test_alignment_errors,
test_oom_errors,

View File

@@ -1,8 +1,7 @@
#include "test/jemalloc_test.h"
static unsigned
get_nsizes_impl(const char *cmd)
{
get_nsizes_impl(const char *cmd) {
unsigned ret;
size_t z;
@@ -14,14 +13,12 @@ get_nsizes_impl(const char *cmd)
}
static unsigned
get_nlarge(void)
{
get_nlarge(void) {
return (get_nsizes_impl("arenas.nlextents"));
}
static size_t
get_size_impl(const char *cmd, size_t ind)
{
get_size_impl(const char *cmd, size_t ind) {
size_t ret;
size_t z;
size_t mib[4];
@@ -39,13 +36,11 @@ get_size_impl(const char *cmd, size_t ind)
}
static size_t
get_large_size(size_t ind)
{
get_large_size(size_t ind) {
return (get_size_impl("arenas.lextent.0.size", ind));
}
TEST_BEGIN(test_grow_and_shrink)
{
TEST_BEGIN(test_grow_and_shrink) {
void *p, *q;
size_t tsz;
#define NCYCLES 3
@@ -90,8 +85,7 @@ TEST_BEGIN(test_grow_and_shrink)
TEST_END
static bool
validate_fill(const void *p, uint8_t c, size_t offset, size_t len)
{
validate_fill(const void *p, uint8_t c, size_t offset, size_t len) {
bool ret = false;
const uint8_t *buf = (const uint8_t *)p;
size_t i;
@@ -109,8 +103,7 @@ validate_fill(const void *p, uint8_t c, size_t offset, size_t len)
return (ret);
}
TEST_BEGIN(test_zero)
{
TEST_BEGIN(test_zero) {
void *p, *q;
size_t psz, qsz, i, j;
size_t start_sizes[] = {1, 3*1024, 63*1024, 4095*1024};
@@ -154,8 +147,7 @@ TEST_BEGIN(test_zero)
}
TEST_END
TEST_BEGIN(test_align)
{
TEST_BEGIN(test_align) {
void *p, *q;
size_t align;
#define MAX_ALIGN (ZU(1) << 25)
@@ -179,8 +171,7 @@ TEST_BEGIN(test_align)
}
TEST_END
TEST_BEGIN(test_lg_align_and_zero)
{
TEST_BEGIN(test_lg_align_and_zero) {
void *p, *q;
unsigned lg_align;
size_t sz;
@@ -217,8 +208,7 @@ TEST_BEGIN(test_lg_align_and_zero)
}
TEST_END
TEST_BEGIN(test_overflow)
{
TEST_BEGIN(test_overflow) {
size_t largemax;
void *p;
@@ -245,8 +235,7 @@ TEST_BEGIN(test_overflow)
TEST_END
int
main(void)
{
main(void) {
return (test(
test_grow_and_shrink,
test_zero,

View File

@@ -3,21 +3,20 @@
#define MAXALIGN (((size_t)1) << 22)
#define NITER 3
TEST_BEGIN(test_basic)
{
TEST_BEGIN(test_basic) {
void *ptr = mallocx(64, 0);
sdallocx(ptr, 64, 0);
}
TEST_END
TEST_BEGIN(test_alignment_and_size)
{
TEST_BEGIN(test_alignment_and_size) {
size_t nsz, sz, alignment, total;
unsigned i;
void *ps[NITER];
for (i = 0; i < NITER; i++)
for (i = 0; i < NITER; i++) {
ps[i] = NULL;
}
for (alignment = 8;
alignment <= MAXALIGN;
@@ -32,8 +31,9 @@ TEST_BEGIN(test_alignment_and_size)
ps[i] = mallocx(sz, MALLOCX_ALIGN(alignment) |
MALLOCX_ZERO);
total += nsz;
if (total >= (MAXALIGN << 1))
if (total >= (MAXALIGN << 1)) {
break;
}
}
for (i = 0; i < NITER; i++) {
if (ps[i] != NULL) {
@@ -48,8 +48,7 @@ TEST_BEGIN(test_alignment_and_size)
TEST_END
int
main(void)
{
main(void) {
return (test(
test_basic,
test_alignment_and_size));

View File

@@ -3,8 +3,7 @@
#define NTHREADS 10
void *
thd_start(void *arg)
{
thd_start(void *arg) {
unsigned main_arena_ind = *(unsigned *)arg;
void *p;
unsigned arena_ind;
@@ -38,8 +37,7 @@ thd_start(void *arg)
return (NULL);
}
TEST_BEGIN(test_thread_arena)
{
TEST_BEGIN(test_thread_arena) {
void *p;
unsigned arena_ind;
size_t size;
@@ -73,8 +71,7 @@ TEST_BEGIN(test_thread_arena)
TEST_END
int
main(void)
{
main(void) {
return (test(
test_thread_arena));
}

View File

@@ -9,8 +9,7 @@ static const bool config_tcache =
;
void *
thd_start(void *arg)
{
thd_start(void *arg) {
int err;
size_t sz;
bool e0, e1;
@@ -84,14 +83,12 @@ label_ENOENT:
return (NULL);
}
TEST_BEGIN(test_main_thread)
{
TEST_BEGIN(test_main_thread) {
thd_start(NULL);
}
TEST_END
TEST_BEGIN(test_subthread)
{
TEST_BEGIN(test_subthread) {
thd_t thd;
thd_create(&thd, thd_start, NULL);
@@ -100,8 +97,7 @@ TEST_BEGIN(test_subthread)
TEST_END
int
main(void)
{
main(void) {
/* Run tests multiple times to check for bad interactions. */
return (test(
test_main_thread,

View File

@@ -10,8 +10,7 @@ const char *malloc_conf = "junk:false";
* xallocx() would ordinarily be able to extend.
*/
static unsigned
arena_ind(void)
{
arena_ind(void) {
static unsigned ind = 0;
if (ind == 0) {
@@ -23,8 +22,7 @@ arena_ind(void)
return (ind);
}
TEST_BEGIN(test_same_size)
{
TEST_BEGIN(test_same_size) {
void *p;
size_t sz, tsz;
@@ -39,8 +37,7 @@ TEST_BEGIN(test_same_size)
}
TEST_END
TEST_BEGIN(test_extra_no_move)
{
TEST_BEGIN(test_extra_no_move) {
void *p;
size_t sz, tsz;
@@ -55,8 +52,7 @@ TEST_BEGIN(test_extra_no_move)
}
TEST_END
TEST_BEGIN(test_no_move_fail)
{
TEST_BEGIN(test_no_move_fail) {
void *p;
size_t sz, tsz;
@@ -72,8 +68,7 @@ TEST_BEGIN(test_no_move_fail)
TEST_END
static unsigned
get_nsizes_impl(const char *cmd)
{
get_nsizes_impl(const char *cmd) {
unsigned ret;
size_t z;
@@ -85,20 +80,17 @@ get_nsizes_impl(const char *cmd)
}
static unsigned
get_nsmall(void)
{
get_nsmall(void) {
return (get_nsizes_impl("arenas.nbins"));
}
static unsigned
get_nlarge(void)
{
get_nlarge(void) {
return (get_nsizes_impl("arenas.nlextents"));
}
static size_t
get_size_impl(const char *cmd, size_t ind)
{
get_size_impl(const char *cmd, size_t ind) {
size_t ret;
size_t z;
size_t mib[4];
@@ -116,19 +108,16 @@ get_size_impl(const char *cmd, size_t ind)
}
static size_t
get_small_size(size_t ind)
{
get_small_size(size_t ind) {
return (get_size_impl("arenas.bin.0.size", ind));
}
static size_t
get_large_size(size_t ind)
{
get_large_size(size_t ind) {
return (get_size_impl("arenas.lextent.0.size", ind));
}
TEST_BEGIN(test_size)
{
TEST_BEGIN(test_size) {
size_t small0, largemax;
void *p;
@@ -157,8 +146,7 @@ TEST_BEGIN(test_size)
}
TEST_END
TEST_BEGIN(test_size_extra_overflow)
{
TEST_BEGIN(test_size_extra_overflow) {
size_t small0, largemax;
void *p;
@@ -189,8 +177,7 @@ TEST_BEGIN(test_size_extra_overflow)
}
TEST_END
TEST_BEGIN(test_extra_small)
{
TEST_BEGIN(test_extra_small) {
size_t small0, small1, largemax;
void *p;
@@ -221,8 +208,7 @@ TEST_BEGIN(test_extra_small)
}
TEST_END
TEST_BEGIN(test_extra_large)
{
TEST_BEGIN(test_extra_large) {
int flags = MALLOCX_ARENA(arena_ind());
size_t smallmax, large1, large2, large3, largemax;
void *p;
@@ -292,8 +278,7 @@ TEST_BEGIN(test_extra_large)
TEST_END
static void
print_filled_extents(const void *p, uint8_t c, size_t len)
{
print_filled_extents(const void *p, uint8_t c, size_t len) {
const uint8_t *pc = (const uint8_t *)p;
size_t i, range0;
uint8_t c0;
@@ -312,26 +297,26 @@ print_filled_extents(const void *p, uint8_t c, size_t len)
}
static bool
validate_fill(const void *p, uint8_t c, size_t offset, size_t len)
{
validate_fill(const void *p, uint8_t c, size_t offset, size_t len) {
const uint8_t *pc = (const uint8_t *)p;
bool err;
size_t i;
for (i = offset, err = false; i < offset+len; i++) {
if (pc[i] != c)
if (pc[i] != c) {
err = true;
}
}
if (err)
if (err) {
print_filled_extents(p, c, offset + len);
}
return (err);
}
static void
test_zero(size_t szmin, size_t szmax)
{
test_zero(size_t szmin, size_t szmax) {
int flags = MALLOCX_ARENA(arena_ind()) | MALLOCX_ZERO;
size_t sz, nsz;
void *p;
@@ -378,8 +363,7 @@ test_zero(size_t szmin, size_t szmax)
dallocx(p, flags);
}
TEST_BEGIN(test_zero_large)
{
TEST_BEGIN(test_zero_large) {
size_t large0, large1;
/* Get size classes. */
@@ -391,8 +375,7 @@ TEST_BEGIN(test_zero_large)
TEST_END
int
main(void)
{
main(void) {
return (test(
test_same_size,
test_extra_no_move,