fixes for mingw (#215)

* fix mingw

* fix mingw malloc test
This commit is contained in:
Schrodinger ZHU Yifan
2020-06-23 14:05:06 +08:00
committed by GitHub
parent e16f2aff6f
commit 8f6b8db4ed
2 changed files with 20 additions and 9 deletions

View File

@@ -6,6 +6,7 @@
#ifdef _WIN32
# ifndef _MSC_VER
# include <cstdio>
# include <utility>
# endif
# define WIN32_LEAN_AND_MEAN
# ifndef NOMINMAX

View File

@@ -4,6 +4,12 @@
#define SNMALLOC_NAME_MANGLE(a) our_##a
#include "../../../override/malloc.cc"
#if defined(_WIN32) && !defined(_MSC_VER)
# define ST_FMT "I"
#else
# define ST_FMT "z"
#endif
using namespace snmalloc;
void check_result(size_t size, size_t align, void* p, int err, bool null)
@@ -25,7 +31,7 @@ void check_result(size_t size, size_t align, void* p, int err, bool null)
if ((align == 1) && (alloc_size != expected_size))
{
printf(
"Usable size is %zu, but required to be %zu.\n",
"Usable size is %" ST_FMT "u, but required to be %" ST_FMT "u.\n",
alloc_size,
expected_size);
abort();
@@ -33,7 +39,8 @@ void check_result(size_t size, size_t align, void* p, int err, bool null)
if ((align != 1) && (alloc_size < expected_size))
{
printf(
"Usable size is %zu, but required to be at least %zu.\n",
"Usable size is %" ST_FMT "u, but required to be at least %" ST_FMT
"u.\n",
alloc_size,
expected_size);
abort();
@@ -41,7 +48,8 @@ void check_result(size_t size, size_t align, void* p, int err, bool null)
if (static_cast<size_t>(reinterpret_cast<uintptr_t>(p) % align) != 0)
{
printf(
"Address is 0x%zx, but required to be aligned to 0x%zx.\n",
"Address is 0x%" ST_FMT "x, but required to be aligned to 0x%" ST_FMT
"x.\n",
reinterpret_cast<uintptr_t>(p),
align);
abort();
@@ -52,7 +60,7 @@ void check_result(size_t size, size_t align, void* p, int err, bool null)
void test_calloc(size_t nmemb, size_t size, int err, bool null)
{
fprintf(stderr, "calloc(%zu, %zu)\n", nmemb, size);
fprintf(stderr, "calloc(%" ST_FMT "u, %" ST_FMT "u)\n", nmemb, size);
errno = 0;
void* p = our_calloc(nmemb, size);
@@ -73,7 +81,8 @@ void test_realloc(void* p, size_t size, int err, bool null)
if (p != nullptr)
old_size = our_malloc_usable_size(p);
fprintf(stderr, "realloc(%p(%zu), %zu)\n", p, old_size, size);
fprintf(
stderr, "realloc(%p(%" ST_FMT "u), %" ST_FMT "u)\n", p, old_size, size);
errno = 0;
auto new_p = our_realloc(p, size);
// Realloc failure case, deallocate original block
@@ -84,7 +93,8 @@ void test_realloc(void* p, size_t size, int err, bool null)
void test_posix_memalign(size_t size, size_t align, int err, bool null)
{
fprintf(stderr, "posix_memalign(&p, %zu, %zu)\n", align, size);
fprintf(
stderr, "posix_memalign(&p, %" ST_FMT "u, %" ST_FMT "u)\n", align, size);
void* p = nullptr;
errno = our_posix_memalign(&p, align, size);
check_result(size, align, p, err, null);
@@ -92,7 +102,7 @@ void test_posix_memalign(size_t size, size_t align, int err, bool null)
void test_memalign(size_t size, size_t align, int err, bool null)
{
fprintf(stderr, "memalign(%zu, %zu)\n", align, size);
fprintf(stderr, "memalign(%" ST_FMT "u, %" ST_FMT "u)\n", align, size);
errno = 0;
void* p = our_memalign(align, size);
check_result(size, align, p, err, null);
@@ -112,7 +122,7 @@ int main(int argc, char** argv)
for (sizeclass_t sc = 0; sc < (SUPERSLAB_BITS + 4); sc++)
{
const size_t size = 1ULL << sc;
printf("malloc: %zu\n", size);
printf("malloc: %" ST_FMT "u\n", size);
check_result(size, 1, our_malloc(size), SUCCESS, false);
check_result(size + 1, 1, our_malloc(size + 1), SUCCESS, false);
}
@@ -160,7 +170,7 @@ int main(int argc, char** argv)
for (sizeclass_t sc2 = 0; sc2 < (SUPERSLAB_BITS + 4); sc2++)
{
const size_t size2 = 1ULL << sc2;
printf("size1: %zu, size2:%zu\n", size, size2);
printf("size1: %" ST_FMT "u, size2:%" ST_FMT "u\n", size, size2);
test_realloc(our_malloc(size), size2, SUCCESS, false);
test_realloc(our_malloc(size + 1), size2, SUCCESS, false);
}