Skip to content

Commit 1172c34

Browse files
fix mingw malloc test
1 parent 49b89b5 commit 1172c34

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/test/func/malloc/malloc.cc

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
#define SNMALLOC_NAME_MANGLE(a) our_##a
55
#include "../../../override/malloc.cc"
66

7+
#if defined(_WIN32) && !defined(_MSC_VER)
8+
# define ST_FMT "I"
9+
#else
10+
# define ST_FMT "z"
11+
#endif
12+
713
using namespace snmalloc;
814

915
void check_result(size_t size, size_t align, void* p, int err, bool null)
@@ -25,23 +31,25 @@ void check_result(size_t size, size_t align, void* p, int err, bool null)
2531
if ((align == 1) && (alloc_size != expected_size))
2632
{
2733
printf(
28-
"Usable size is %zu, but required to be %zu.\n",
34+
"Usable size is %" ST_FMT "u, but required to be %" ST_FMT "u.\n",
2935
alloc_size,
3036
expected_size);
3137
abort();
3238
}
3339
if ((align != 1) && (alloc_size < expected_size))
3440
{
3541
printf(
36-
"Usable size is %zu, but required to be at least %zu.\n",
42+
"Usable size is %" ST_FMT "u, but required to be at least %" ST_FMT
43+
"u.\n",
3744
alloc_size,
3845
expected_size);
3946
abort();
4047
}
4148
if (static_cast<size_t>(reinterpret_cast<uintptr_t>(p) % align) != 0)
4249
{
4350
printf(
44-
"Address is 0x%zx, but required to be aligned to 0x%zx.\n",
51+
"Address is 0x%" ST_FMT "x, but required to be aligned to 0x%" ST_FMT
52+
"x.\n",
4553
reinterpret_cast<uintptr_t>(p),
4654
align);
4755
abort();
@@ -52,7 +60,7 @@ void check_result(size_t size, size_t align, void* p, int err, bool null)
5260

5361
void test_calloc(size_t nmemb, size_t size, int err, bool null)
5462
{
55-
fprintf(stderr, "calloc(%zu, %zu)\n", nmemb, size);
63+
fprintf(stderr, "calloc(%" ST_FMT "u, %" ST_FMT "u)\n", nmemb, size);
5664
errno = 0;
5765
void* p = our_calloc(nmemb, size);
5866

@@ -73,7 +81,8 @@ void test_realloc(void* p, size_t size, int err, bool null)
7381
if (p != nullptr)
7482
old_size = our_malloc_usable_size(p);
7583

76-
fprintf(stderr, "realloc(%p(%zu), %zu)\n", p, old_size, size);
84+
fprintf(
85+
stderr, "realloc(%p(%" ST_FMT "u), %" ST_FMT "u)\n", p, old_size, size);
7786
errno = 0;
7887
auto new_p = our_realloc(p, size);
7988
// Realloc failure case, deallocate original block
@@ -84,15 +93,16 @@ void test_realloc(void* p, size_t size, int err, bool null)
8493

8594
void test_posix_memalign(size_t size, size_t align, int err, bool null)
8695
{
87-
fprintf(stderr, "posix_memalign(&p, %zu, %zu)\n", align, size);
96+
fprintf(
97+
stderr, "posix_memalign(&p, %" ST_FMT "u, %" ST_FMT "u)\n", align, size);
8898
void* p = nullptr;
8999
errno = our_posix_memalign(&p, align, size);
90100
check_result(size, align, p, err, null);
91101
}
92102

93103
void test_memalign(size_t size, size_t align, int err, bool null)
94104
{
95-
fprintf(stderr, "memalign(%zu, %zu)\n", align, size);
105+
fprintf(stderr, "memalign(%" ST_FMT "u, %" ST_FMT "u)\n", align, size);
96106
errno = 0;
97107
void* p = our_memalign(align, size);
98108
check_result(size, align, p, err, null);
@@ -112,7 +122,7 @@ int main(int argc, char** argv)
112122
for (sizeclass_t sc = 0; sc < (SUPERSLAB_BITS + 4); sc++)
113123
{
114124
const size_t size = 1ULL << sc;
115-
printf("malloc: %zu\n", size);
125+
printf("malloc: %" ST_FMT "u\n", size);
116126
check_result(size, 1, our_malloc(size), SUCCESS, false);
117127
check_result(size + 1, 1, our_malloc(size + 1), SUCCESS, false);
118128
}
@@ -160,7 +170,7 @@ int main(int argc, char** argv)
160170
for (sizeclass_t sc2 = 0; sc2 < (SUPERSLAB_BITS + 4); sc2++)
161171
{
162172
const size_t size2 = 1ULL << sc2;
163-
printf("size1: %zu, size2:%zu\n", size, size2);
173+
printf("size1: %" ST_FMT "u, size2:%" ST_FMT "u\n", size, size2);
164174
test_realloc(our_malloc(size), size2, SUCCESS, false);
165175
test_realloc(our_malloc(size + 1), size2, SUCCESS, false);
166176
}

0 commit comments

Comments
 (0)