4
4
#define SNMALLOC_NAME_MANGLE (a ) our_##a
5
5
#include " ../../../override/malloc.cc"
6
6
7
+ #if defined(_WIN32) && !defined(_MSC_VER)
8
+ # define ST_FMT " I"
9
+ #else
10
+ # define ST_FMT " z"
11
+ #endif
12
+
7
13
using namespace snmalloc ;
8
14
9
15
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)
25
31
if ((align == 1 ) && (alloc_size != expected_size))
26
32
{
27
33
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 " ,
29
35
alloc_size,
30
36
expected_size);
31
37
abort ();
32
38
}
33
39
if ((align != 1 ) && (alloc_size < expected_size))
34
40
{
35
41
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 " ,
37
44
alloc_size,
38
45
expected_size);
39
46
abort ();
40
47
}
41
48
if (static_cast <size_t >(reinterpret_cast <uintptr_t >(p) % align) != 0 )
42
49
{
43
50
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 " ,
45
53
reinterpret_cast <uintptr_t >(p),
46
54
align);
47
55
abort ();
@@ -52,7 +60,7 @@ void check_result(size_t size, size_t align, void* p, int err, bool null)
52
60
53
61
void test_calloc (size_t nmemb, size_t size, int err, bool null)
54
62
{
55
- fprintf (stderr, " calloc(%zu , %zu )\n " , nmemb, size);
63
+ fprintf (stderr, " calloc(%" ST_FMT " u , %" ST_FMT " u )\n " , nmemb, size);
56
64
errno = 0 ;
57
65
void * p = our_calloc (nmemb, size);
58
66
@@ -73,7 +81,8 @@ void test_realloc(void* p, size_t size, int err, bool null)
73
81
if (p != nullptr )
74
82
old_size = our_malloc_usable_size (p);
75
83
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);
77
86
errno = 0 ;
78
87
auto new_p = our_realloc (p, size);
79
88
// Realloc failure case, deallocate original block
@@ -84,15 +93,16 @@ void test_realloc(void* p, size_t size, int err, bool null)
84
93
85
94
void test_posix_memalign (size_t size, size_t align, int err, bool null)
86
95
{
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);
88
98
void * p = nullptr ;
89
99
errno = our_posix_memalign (&p, align, size);
90
100
check_result (size, align, p, err, null);
91
101
}
92
102
93
103
void test_memalign (size_t size, size_t align, int err, bool null)
94
104
{
95
- fprintf (stderr, " memalign(%zu , %zu )\n " , align, size);
105
+ fprintf (stderr, " memalign(%" ST_FMT " u , %" ST_FMT " u )\n " , align, size);
96
106
errno = 0 ;
97
107
void * p = our_memalign (align, size);
98
108
check_result (size, align, p, err, null);
@@ -112,7 +122,7 @@ int main(int argc, char** argv)
112
122
for (sizeclass_t sc = 0 ; sc < (SUPERSLAB_BITS + 4 ); sc++)
113
123
{
114
124
const size_t size = 1ULL << sc;
115
- printf (" malloc: %zu \n " , size);
125
+ printf (" malloc: %" ST_FMT " u \n " , size);
116
126
check_result (size, 1 , our_malloc (size), SUCCESS, false );
117
127
check_result (size + 1 , 1 , our_malloc (size + 1 ), SUCCESS, false );
118
128
}
@@ -160,7 +170,7 @@ int main(int argc, char** argv)
160
170
for (sizeclass_t sc2 = 0 ; sc2 < (SUPERSLAB_BITS + 4 ); sc2++)
161
171
{
162
172
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);
164
174
test_realloc (our_malloc (size), size2, SUCCESS, false );
165
175
test_realloc (our_malloc (size + 1 ), size2, SUCCESS, false );
166
176
}
0 commit comments