merge from dev

This commit is contained in:
Daan Leijen 2022-12-19 17:08:45 -08:00
commit 92ffc25d79
65 changed files with 793 additions and 741 deletions

View file

@ -44,7 +44,7 @@ int main() {
p1 = mi_malloc(8);
char* s = strdup("hello\n");
free(p2);
p2 = malloc(16);
p1 = realloc(p1, 32);
free(p1);
@ -56,10 +56,10 @@ int main() {
//free(p1);
//p2 = malloc(32);
//mi_free(p2);
//mi_collect(true);
//mi_stats_print(NULL);
// test_process_info();
return 0;
}
@ -156,7 +156,7 @@ static void test_process_info(void) {
size_t peak_rss = 0;
size_t current_commit = 0;
size_t peak_commit = 0;
size_t page_faults = 0;
size_t page_faults = 0;
for (int i = 0; i < 100000; i++) {
void* p = calloc(100,10);
free(p);
@ -188,7 +188,7 @@ static void negative_stat(void) {
mi_stats_print_out(NULL, NULL);
*p = 100;
mi_free(p);
mi_stats_print_out(NULL, NULL);
mi_stats_print_out(NULL, NULL);
}
static void alloc_huge(void) {

View file

@ -328,7 +328,7 @@ bool check_debug_fill_freed(uint8_t* p, size_t size) {
#if MI_VALGRIND
(void)p; (void)size;
return true; // when compiled with valgrind we don't fill on purpose
#else
#else
if(!p)
return false;
@ -337,6 +337,6 @@ bool check_debug_fill_freed(uint8_t* p, size_t size) {
result &= p[i] == MI_DEBUG_FREED;
}
return result;
#endif
#endif
}
#endif

View file

@ -57,7 +57,7 @@ int main(void) {
// ---------------------------------------------------
CHECK_BODY("malloc-zero") {
void* p = mi_malloc(0);
void* p = mi_malloc(0);
result = (p != NULL);
mi_free(p);
};
@ -83,7 +83,7 @@ int main(void) {
// ---------------------------------------------------
// Extended
// ---------------------------------------------------
// ---------------------------------------------------
CHECK_BODY("posix_memalign1") {
void* p = &p;
int err = mi_posix_memalign(&p, sizeof(void*), 32);
@ -122,7 +122,7 @@ int main(void) {
void* p = mi_malloc_aligned(48,32); result = (p != NULL && (uintptr_t)(p) % 32 == 0); mi_free(p);
};
CHECK_BODY("malloc-aligned3") {
void* p1 = mi_malloc_aligned(48,32); bool result1 = (p1 != NULL && (uintptr_t)(p1) % 32 == 0);
void* p1 = mi_malloc_aligned(48,32); bool result1 = (p1 != NULL && (uintptr_t)(p1) % 32 == 0);
void* p2 = mi_malloc_aligned(48,32); bool result2 = (p2 != NULL && (uintptr_t)(p2) % 32 == 0);
mi_free(p2);
mi_free(p1);
@ -138,9 +138,9 @@ int main(void) {
result = ok;
};
CHECK_BODY("malloc-aligned5") {
void* p = mi_malloc_aligned(4097,4096);
size_t usable = mi_usable_size(p);
result = (usable >= 4097 && usable < 16000);
void* p = mi_malloc_aligned(4097,4096);
size_t usable = mi_usable_size(p);
result = (usable >= 4097 && usable < 16000);
printf("malloc_aligned5: usable size: %zi\n", usable);
mi_free(p);
};
@ -187,18 +187,18 @@ int main(void) {
}
for (int j = 0; j < 8; j++) {
mi_free(p[j]);
}
}
}
result = ok;
};
CHECK_BODY("malloc-aligned10") {
bool ok = true;
void* p[10+1];
int align;
int align;
int j;
for(j = 0, align = 1; j <= 10 && ok; align *= 2, j++ ) {
p[j] = mi_malloc_aligned(43 + align, align);
ok = ((uintptr_t)p[j] % align) == 0;
ok = ((uintptr_t)p[j] % align) == 0;
}
for ( ; j > 0; j--) {
mi_free(p[j-1]);
@ -216,7 +216,7 @@ int main(void) {
};
CHECK_BODY("malloc-aligned-at2") {
void* p = mi_malloc_aligned_at(50,32,8); result = (p != NULL && ((uintptr_t)(p) + 8) % 32 == 0); mi_free(p);
};
};
CHECK_BODY("memalign1") {
void* p;
bool ok = true;
@ -226,7 +226,7 @@ int main(void) {
}
result = ok;
};
// ---------------------------------------------------
// Reallocation
// ---------------------------------------------------

View file

@ -221,7 +221,7 @@ static void test_leak(void) {
}
#endif
int main(int argc, char** argv) {
int main(int argc, char** argv) {
// > mimalloc-test-stress [THREADS] [SCALE] [ITER]
if (argc >= 2) {
char* end;
@ -266,7 +266,7 @@ int main(int argc, char** argv) {
//mi_debug_show_arenas();
#endif
mi_stats_print(NULL);
#endif
#endif
//bench_end_program();
return 0;
}

View file

@ -12,7 +12,7 @@ terms of the MIT license. A copy of the license can be found in the file
> cmake ../.. -DMI_VALGRIND=1
> make -j8
and then compile this file as:
and then compile this file as:
> gcc -g -o test-wrong -I../../include ../../test/test-wrong.c libmimalloc-valgrind-debug.a -lpthread
@ -32,7 +32,7 @@ terms of the MIT license. A copy of the license can be found in the file
int main(int argc, char** argv) {
int* p = (int*)mi(malloc)(3*sizeof(int));
int* r = (int*)mi_malloc_aligned(8,16);
mi_free(r);
@ -47,7 +47,7 @@ int main(int argc, char** argv) {
// illegal int read
printf("invalid: over: %d, under: %d\n", q[1], q[-1]);
*q = 42;
// buffer overflow
@ -55,7 +55,7 @@ int main(int argc, char** argv) {
// buffer underflow
q[-1] = 44;
mi(free)(q);
// double free
@ -66,5 +66,5 @@ int main(int argc, char** argv) {
// leak p
// mi_free(p)
return 0;
return 0;
}

View file

@ -19,12 +19,12 @@ static int failed = 0;
static bool check_result(bool result, const char* testname, const char* fname, long lineno) {
if (!(result)) {
failed++;
failed++;
fprintf(stderr,"\n FAILED: %s: %s:%ld\n", testname, fname, lineno);
/* exit(1); */
}
else {
ok++;
/* exit(1); */
}
else {
ok++;
fprintf(stderr, "ok.\n");
}
return true;