mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-06-20 10:55:39 +03:00
Reformat the codebase with the clang-format 18.
This commit is contained in:
parent
0a6215c171
commit
f1bba4a87c
346 changed files with 18286 additions and 17770 deletions
107
test/unit/junk.c
107
test/unit/junk.c
|
|
@ -1,9 +1,9 @@
|
|||
#include "test/jemalloc_test.h"
|
||||
|
||||
#define arraylen(arr) (sizeof(arr)/sizeof(arr[0]))
|
||||
#define arraylen(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
static size_t ptr_ind;
|
||||
static void *volatile ptrs[100];
|
||||
static void *last_junked_ptr;
|
||||
static void *last_junked_ptr;
|
||||
static size_t last_junked_usize;
|
||||
|
||||
static void
|
||||
|
|
@ -21,17 +21,17 @@ test_junk(void *ptr, size_t usize) {
|
|||
|
||||
static void
|
||||
do_allocs(size_t size, bool zero, size_t lg_align) {
|
||||
#define JUNK_ALLOC(...) \
|
||||
do { \
|
||||
assert(ptr_ind + 1 < arraylen(ptrs)); \
|
||||
void *ptr = __VA_ARGS__; \
|
||||
assert_ptr_not_null(ptr, ""); \
|
||||
ptrs[ptr_ind++] = ptr; \
|
||||
if (opt_junk_alloc && !zero) { \
|
||||
expect_ptr_eq(ptr, last_junked_ptr, ""); \
|
||||
expect_zu_eq(last_junked_usize, \
|
||||
TEST_MALLOC_SIZE(ptr), ""); \
|
||||
} \
|
||||
#define JUNK_ALLOC(...) \
|
||||
do { \
|
||||
assert(ptr_ind + 1 < arraylen(ptrs)); \
|
||||
void *ptr = __VA_ARGS__; \
|
||||
assert_ptr_not_null(ptr, ""); \
|
||||
ptrs[ptr_ind++] = ptr; \
|
||||
if (opt_junk_alloc && !zero) { \
|
||||
expect_ptr_eq(ptr, last_junked_ptr, ""); \
|
||||
expect_zu_eq( \
|
||||
last_junked_usize, TEST_MALLOC_SIZE(ptr), ""); \
|
||||
} \
|
||||
} while (0)
|
||||
if (!zero && lg_align == 0) {
|
||||
JUNK_ALLOC(malloc(size));
|
||||
|
|
@ -51,21 +51,20 @@ do_allocs(size_t size, bool zero, size_t lg_align) {
|
|||
#endif
|
||||
int zero_flag = zero ? MALLOCX_ZERO : 0;
|
||||
JUNK_ALLOC(mallocx(size, zero_flag | MALLOCX_LG_ALIGN(lg_align)));
|
||||
JUNK_ALLOC(mallocx(size, zero_flag | MALLOCX_LG_ALIGN(lg_align)
|
||||
| MALLOCX_TCACHE_NONE));
|
||||
JUNK_ALLOC(mallocx(size,
|
||||
zero_flag | MALLOCX_LG_ALIGN(lg_align) | MALLOCX_TCACHE_NONE));
|
||||
if (lg_align >= LG_SIZEOF_PTR) {
|
||||
void *memalign_result;
|
||||
int err = posix_memalign(&memalign_result, (1 << lg_align),
|
||||
size);
|
||||
int err = posix_memalign(
|
||||
&memalign_result, (1 << lg_align), size);
|
||||
assert_d_eq(err, 0, "");
|
||||
JUNK_ALLOC(memalign_result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_junk_alloc_free) {
|
||||
bool zerovals[] = {false, true};
|
||||
size_t sizevals[] = {
|
||||
1, 8, 100, 1000, 100*1000
|
||||
bool zerovals[] = {false, true};
|
||||
size_t sizevals[] = {1, 8, 100, 1000, 100 * 1000
|
||||
/*
|
||||
* Memory allocation failure is a real possibility in 32-bit mode.
|
||||
* Rather than try to check in the face of resource exhaustion, we just
|
||||
|
|
@ -75,49 +74,49 @@ TEST_BEGIN(test_junk_alloc_free) {
|
|||
* mechanisms; but this is in fact the case.
|
||||
*/
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
, 10 * 1000 * 1000
|
||||
,
|
||||
10 * 1000 * 1000
|
||||
#endif
|
||||
};
|
||||
size_t lg_alignvals[] = {
|
||||
0, 4, 10, 15, 16, LG_PAGE
|
||||
size_t lg_alignvals[] = {0, 4, 10, 15, 16, LG_PAGE
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
, 20, 24
|
||||
,
|
||||
20, 24
|
||||
#endif
|
||||
};
|
||||
|
||||
#define JUNK_FREE(...) \
|
||||
do { \
|
||||
do_allocs(size, zero, lg_align); \
|
||||
for (size_t n = 0; n < ptr_ind; n++) { \
|
||||
void *ptr = ptrs[n]; \
|
||||
__VA_ARGS__; \
|
||||
if (opt_junk_free) { \
|
||||
assert_ptr_eq(ptr, last_junked_ptr, \
|
||||
""); \
|
||||
assert_zu_eq(usize, last_junked_usize, \
|
||||
""); \
|
||||
} \
|
||||
reset(); \
|
||||
} \
|
||||
#define JUNK_FREE(...) \
|
||||
do { \
|
||||
do_allocs(size, zero, lg_align); \
|
||||
for (size_t n = 0; n < ptr_ind; n++) { \
|
||||
void *ptr = ptrs[n]; \
|
||||
__VA_ARGS__; \
|
||||
if (opt_junk_free) { \
|
||||
assert_ptr_eq(ptr, last_junked_ptr, ""); \
|
||||
assert_zu_eq(usize, last_junked_usize, ""); \
|
||||
} \
|
||||
reset(); \
|
||||
} \
|
||||
} while (0)
|
||||
for (size_t i = 0; i < arraylen(zerovals); i++) {
|
||||
for (size_t j = 0; j < arraylen(sizevals); j++) {
|
||||
for (size_t k = 0; k < arraylen(lg_alignvals); k++) {
|
||||
bool zero = zerovals[i];
|
||||
bool zero = zerovals[i];
|
||||
size_t size = sizevals[j];
|
||||
size_t lg_align = lg_alignvals[k];
|
||||
size_t usize = nallocx(size,
|
||||
MALLOCX_LG_ALIGN(lg_align));
|
||||
size_t usize = nallocx(
|
||||
size, MALLOCX_LG_ALIGN(lg_align));
|
||||
|
||||
JUNK_FREE(free(ptr));
|
||||
JUNK_FREE(dallocx(ptr, 0));
|
||||
JUNK_FREE(dallocx(ptr, MALLOCX_TCACHE_NONE));
|
||||
JUNK_FREE(dallocx(ptr, MALLOCX_LG_ALIGN(
|
||||
lg_align)));
|
||||
JUNK_FREE(sdallocx(ptr, usize, MALLOCX_LG_ALIGN(
|
||||
lg_align)));
|
||||
JUNK_FREE(
|
||||
dallocx(ptr, MALLOCX_LG_ALIGN(lg_align)));
|
||||
JUNK_FREE(sdallocx(
|
||||
ptr, usize, MALLOCX_LG_ALIGN(lg_align)));
|
||||
JUNK_FREE(sdallocx(ptr, usize,
|
||||
MALLOCX_TCACHE_NONE | MALLOCX_LG_ALIGN(lg_align)));
|
||||
MALLOCX_TCACHE_NONE
|
||||
| MALLOCX_LG_ALIGN(lg_align)));
|
||||
if (opt_zero_realloc_action
|
||||
== zero_realloc_action_free) {
|
||||
JUNK_FREE(realloc(ptr, 0));
|
||||
|
|
@ -138,24 +137,24 @@ TEST_BEGIN(test_realloc_expand) {
|
|||
ptr = malloc(SC_SMALL_MAXCLASS);
|
||||
expanded = realloc(ptr, SC_LARGE_MINCLASS);
|
||||
expect_ptr_eq(last_junked_ptr, &expanded[SC_SMALL_MAXCLASS], "");
|
||||
expect_zu_eq(last_junked_usize,
|
||||
SC_LARGE_MINCLASS - SC_SMALL_MAXCLASS, "");
|
||||
expect_zu_eq(
|
||||
last_junked_usize, SC_LARGE_MINCLASS - SC_SMALL_MAXCLASS, "");
|
||||
free(expanded);
|
||||
|
||||
/* rallocx(..., 0) */
|
||||
ptr = malloc(SC_SMALL_MAXCLASS);
|
||||
expanded = rallocx(ptr, SC_LARGE_MINCLASS, 0);
|
||||
expect_ptr_eq(last_junked_ptr, &expanded[SC_SMALL_MAXCLASS], "");
|
||||
expect_zu_eq(last_junked_usize,
|
||||
SC_LARGE_MINCLASS - SC_SMALL_MAXCLASS, "");
|
||||
expect_zu_eq(
|
||||
last_junked_usize, SC_LARGE_MINCLASS - SC_SMALL_MAXCLASS, "");
|
||||
free(expanded);
|
||||
|
||||
/* rallocx(..., nonzero) */
|
||||
ptr = malloc(SC_SMALL_MAXCLASS);
|
||||
expanded = rallocx(ptr, SC_LARGE_MINCLASS, MALLOCX_TCACHE_NONE);
|
||||
expect_ptr_eq(last_junked_ptr, &expanded[SC_SMALL_MAXCLASS], "");
|
||||
expect_zu_eq(last_junked_usize,
|
||||
SC_LARGE_MINCLASS - SC_SMALL_MAXCLASS, "");
|
||||
expect_zu_eq(
|
||||
last_junked_usize, SC_LARGE_MINCLASS - SC_SMALL_MAXCLASS, "");
|
||||
free(expanded);
|
||||
|
||||
/* rallocx(..., MALLOCX_ZERO) */
|
||||
|
|
@ -189,7 +188,5 @@ main(void) {
|
|||
* We check the last pointer junked. If a reentrant call happens, that
|
||||
* might be an internal allocation.
|
||||
*/
|
||||
return test_no_reentrancy(
|
||||
test_junk_alloc_free,
|
||||
test_realloc_expand);
|
||||
return test_no_reentrancy(test_junk_alloc_free, test_realloc_expand);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue