2019-06-27 13:36:19 -07:00
|
|
|
/* ----------------------------------------------------------------------------
|
2021-04-24 16:35:11 +00:00
|
|
|
Copyright (c) 2018-2020, Microsoft Research, Daan Leijen
|
2019-06-27 13:36:19 -07:00
|
|
|
This is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the MIT license. A copy of the license can be found in the file
|
|
|
|
"LICENSE" at the root of this distribution.
|
|
|
|
-----------------------------------------------------------------------------*/
|
2021-10-20 16:17:13 +01:00
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
2021-10-19 15:13:01 -07:00
|
|
|
#pragma GCC diagnostic ignored "-Walloc-size-larger-than="
|
2021-10-20 16:17:13 +01:00
|
|
|
#endif
|
2019-06-27 13:36:19 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
Testing allocators is difficult as bugs may only surface after particular
|
|
|
|
allocation patterns. The main approach to testing _mimalloc_ is therefore
|
|
|
|
to have extensive internal invariant checking (see `page_is_valid` in `page.c`
|
2020-01-17 19:59:55 -08:00
|
|
|
for example), which is enabled in debug mode with `-DMI_DEBUG_FULL=ON`.
|
2019-06-27 13:36:19 -07:00
|
|
|
The main testing is then to run `mimalloc-bench` [1] using full invariant checking
|
|
|
|
to catch any potential problems over a wide range of intensive allocation bench
|
|
|
|
marks.
|
|
|
|
|
|
|
|
However, this does not test well for the entire API surface. In this test file
|
|
|
|
we therefore test the API over various inputs. Please add more tests :-)
|
|
|
|
|
|
|
|
[1] https://github.com/daanx/mimalloc-bench
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <errno.h>
|
2020-01-06 16:44:55 -08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2020-01-06 16:18:22 -08:00
|
|
|
#include <vector>
|
2020-01-06 16:44:55 -08:00
|
|
|
#endif
|
|
|
|
|
2019-06-27 13:36:19 -07:00
|
|
|
#include "mimalloc.h"
|
2023-03-20 10:37:39 -07:00
|
|
|
// #include "mimalloc/internal.h"
|
2024-03-24 10:57:02 -07:00
|
|
|
#include "mimalloc/types.h" // for MI_DEBUG and MI_BLOCK_ALIGNMENT_MAX
|
2019-06-27 13:36:19 -07:00
|
|
|
|
2021-12-21 12:39:17 +01:00
|
|
|
#include "testhelper.h"
|
2019-06-27 13:36:19 -07:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Test functions
|
|
|
|
// ---------------------------------------------------------------------------
|
2021-10-19 10:38:57 +02:00
|
|
|
bool test_heap1(void);
|
|
|
|
bool test_heap2(void);
|
|
|
|
bool test_stl_allocator1(void);
|
|
|
|
bool test_stl_allocator2(void);
|
2019-06-27 13:36:19 -07:00
|
|
|
|
2023-04-22 10:18:57 -07:00
|
|
|
bool mem_is_zero(uint8_t* p, size_t size) {
|
|
|
|
if (p==NULL) return false;
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
|
|
if (p[i] != 0) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-27 13:36:19 -07:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Main testing
|
|
|
|
// ---------------------------------------------------------------------------
|
2021-10-19 10:38:57 +02:00
|
|
|
int main(void) {
|
2019-08-20 07:49:40 -07:00
|
|
|
mi_option_disable(mi_option_verbose);
|
2024-03-24 10:57:02 -07:00
|
|
|
|
2019-06-27 13:36:19 -07:00
|
|
|
// ---------------------------------------------------
|
|
|
|
// Malloc
|
|
|
|
// ---------------------------------------------------
|
|
|
|
|
2022-04-19 10:21:41 -07:00
|
|
|
CHECK_BODY("malloc-zero") {
|
2022-12-03 00:23:43 +01:00
|
|
|
void* p = mi_malloc(0);
|
2022-04-19 10:10:10 -07:00
|
|
|
result = (p != NULL);
|
|
|
|
mi_free(p);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("malloc-nomem1") {
|
2021-06-29 21:07:13 +03:00
|
|
|
result = (mi_malloc((size_t)PTRDIFF_MAX + (size_t)1) == NULL);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("malloc-null") {
|
2019-06-27 13:36:19 -07:00
|
|
|
mi_free(NULL);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("calloc-overflow") {
|
2020-01-17 19:59:55 -08:00
|
|
|
// use (size_t)&mi_calloc to get some number without triggering compiler warnings
|
|
|
|
result = (mi_calloc((size_t)&mi_calloc,SIZE_MAX/1000) == NULL);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("calloc0") {
|
2022-10-29 11:43:09 -07:00
|
|
|
void* p = mi_calloc(0,1000);
|
|
|
|
result = (mi_usable_size(p) <= 16);
|
|
|
|
mi_free(p);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("malloc-large") { // see PR #544.
|
2022-02-10 11:46:28 -08:00
|
|
|
void* p = mi_malloc(67108872);
|
|
|
|
mi_free(p);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
2019-06-27 13:36:19 -07:00
|
|
|
|
|
|
|
// ---------------------------------------------------
|
|
|
|
// Extended
|
2022-12-03 00:23:43 +01:00
|
|
|
// ---------------------------------------------------
|
2022-04-19 10:21:41 -07:00
|
|
|
CHECK_BODY("posix_memalign1") {
|
2019-07-07 18:11:21 -07:00
|
|
|
void* p = &p;
|
2020-02-17 09:59:34 -08:00
|
|
|
int err = mi_posix_memalign(&p, sizeof(void*), 32);
|
|
|
|
result = ((err==0 && (uintptr_t)p % sizeof(void*) == 0) || p==&p);
|
2019-06-27 13:36:19 -07:00
|
|
|
mi_free(p);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("posix_memalign_no_align") {
|
2019-07-07 18:11:21 -07:00
|
|
|
void* p = &p;
|
2020-02-17 09:59:34 -08:00
|
|
|
int err = mi_posix_memalign(&p, 3, 32);
|
|
|
|
result = (err==EINVAL && p==&p);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("posix_memalign_zero") {
|
2019-07-07 18:11:21 -07:00
|
|
|
void* p = &p;
|
2020-02-17 09:59:34 -08:00
|
|
|
int err = mi_posix_memalign(&p, sizeof(void*), 0);
|
2019-06-27 13:36:19 -07:00
|
|
|
mi_free(p);
|
|
|
|
result = (err==0);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("posix_memalign_nopow2") {
|
2019-07-07 18:11:21 -07:00
|
|
|
void* p = &p;
|
2020-02-17 09:59:34 -08:00
|
|
|
int err = mi_posix_memalign(&p, 3*sizeof(void*), 32);
|
2019-07-07 18:11:21 -07:00
|
|
|
result = (err==EINVAL && p==&p);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("posix_memalign_nomem") {
|
2019-07-07 18:11:21 -07:00
|
|
|
void* p = &p;
|
2020-02-17 09:59:34 -08:00
|
|
|
int err = mi_posix_memalign(&p, sizeof(void*), SIZE_MAX);
|
2019-07-07 18:11:21 -07:00
|
|
|
result = (err==ENOMEM && p==&p);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
2019-06-27 13:36:19 -07:00
|
|
|
|
|
|
|
// ---------------------------------------------------
|
|
|
|
// Aligned API
|
|
|
|
// ---------------------------------------------------
|
2022-04-19 10:21:41 -07:00
|
|
|
CHECK_BODY("malloc-aligned1") {
|
2019-09-11 17:49:28 -07:00
|
|
|
void* p = mi_malloc_aligned(32,32); result = (p != NULL && (uintptr_t)(p) % 32 == 0); mi_free(p);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("malloc-aligned2") {
|
2019-09-11 17:49:28 -07:00
|
|
|
void* p = mi_malloc_aligned(48,32); result = (p != NULL && (uintptr_t)(p) % 32 == 0); mi_free(p);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("malloc-aligned3") {
|
2022-12-03 00:23:43 +01:00
|
|
|
void* p1 = mi_malloc_aligned(48,32); bool result1 = (p1 != NULL && (uintptr_t)(p1) % 32 == 0);
|
2020-02-02 16:21:06 -08:00
|
|
|
void* p2 = mi_malloc_aligned(48,32); bool result2 = (p2 != NULL && (uintptr_t)(p2) % 32 == 0);
|
|
|
|
mi_free(p2);
|
|
|
|
mi_free(p1);
|
|
|
|
result = (result1&&result2);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("malloc-aligned4") {
|
2020-02-17 09:59:34 -08:00
|
|
|
void* p;
|
|
|
|
bool ok = true;
|
|
|
|
for (int i = 0; i < 8 && ok; i++) {
|
|
|
|
p = mi_malloc_aligned(8, 16);
|
|
|
|
ok = (p != NULL && (uintptr_t)(p) % 16 == 0); mi_free(p);
|
|
|
|
}
|
|
|
|
result = ok;
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("malloc-aligned5") {
|
2022-12-03 00:23:43 +01:00
|
|
|
void* p = mi_malloc_aligned(4097,4096);
|
|
|
|
size_t usable = mi_usable_size(p);
|
|
|
|
result = (usable >= 4097 && usable < 16000);
|
2022-11-01 16:34:17 -07:00
|
|
|
printf("malloc_aligned5: usable size: %zi\n", usable);
|
|
|
|
mi_free(p);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("malloc-aligned6") {
|
2021-12-17 13:18:05 -08:00
|
|
|
bool ok = true;
|
2024-03-24 10:57:02 -07:00
|
|
|
for (size_t align = 1; align <= MI_BLOCK_ALIGNMENT_MAX && ok; align *= 2) {
|
2021-12-18 11:11:44 -08:00
|
|
|
void* ps[8];
|
|
|
|
for (int i = 0; i < 8 && ok; i++) {
|
2023-03-04 14:49:02 -08:00
|
|
|
ps[i] = mi_malloc_aligned(align*13 // size
|
|
|
|
, align);
|
2021-12-18 11:11:44 -08:00
|
|
|
if (ps[i] == NULL || (uintptr_t)(ps[i]) % align != 0) {
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 8 && ok; i++) {
|
|
|
|
mi_free(ps[i]);
|
|
|
|
}
|
2021-12-17 13:18:05 -08:00
|
|
|
}
|
|
|
|
result = ok;
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("malloc-aligned7") {
|
2024-03-24 10:57:02 -07:00
|
|
|
void* p = mi_malloc_aligned(1024,MI_BLOCK_ALIGNMENT_MAX);
|
2022-11-05 14:46:52 -07:00
|
|
|
mi_free(p);
|
2024-03-24 10:57:02 -07:00
|
|
|
result = ((uintptr_t)p % MI_BLOCK_ALIGNMENT_MAX) == 0;
|
2022-11-05 14:46:52 -07:00
|
|
|
};
|
2022-04-19 10:21:41 -07:00
|
|
|
CHECK_BODY("malloc-aligned8") {
|
2022-11-06 08:26:17 -08:00
|
|
|
bool ok = true;
|
|
|
|
for (int i = 0; i < 5 && ok; i++) {
|
|
|
|
int n = (1 << i);
|
2024-03-24 10:57:02 -07:00
|
|
|
void* p = mi_malloc_aligned(1024, n * MI_BLOCK_ALIGNMENT_MAX);
|
|
|
|
ok = ((uintptr_t)p % (n*MI_BLOCK_ALIGNMENT_MAX)) == 0;
|
2022-11-06 08:26:17 -08:00
|
|
|
mi_free(p);
|
|
|
|
}
|
|
|
|
result = ok;
|
|
|
|
};
|
|
|
|
CHECK_BODY("malloc-aligned9") {
|
|
|
|
bool ok = true;
|
2022-11-07 16:41:40 -08:00
|
|
|
void* p[8];
|
2024-03-24 10:57:02 -07:00
|
|
|
size_t sizes[8] = { 8, 512, 1024 * 1024, MI_BLOCK_ALIGNMENT_MAX, MI_BLOCK_ALIGNMENT_MAX + 1, 2 * MI_BLOCK_ALIGNMENT_MAX, 8 * MI_BLOCK_ALIGNMENT_MAX, 0 };
|
2022-11-07 16:41:40 -08:00
|
|
|
for (int i = 0; i < 28 && ok; i++) {
|
|
|
|
int align = (1 << i);
|
|
|
|
for (int j = 0; j < 8 && ok; j++) {
|
|
|
|
p[j] = mi_zalloc_aligned(sizes[j], align);
|
|
|
|
ok = ((uintptr_t)p[j] % align) == 0;
|
|
|
|
}
|
|
|
|
for (int j = 0; j < 8; j++) {
|
|
|
|
mi_free(p[j]);
|
2022-12-03 00:23:43 +01:00
|
|
|
}
|
2022-11-06 08:26:17 -08:00
|
|
|
}
|
|
|
|
result = ok;
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
2022-11-25 14:03:00 -08:00
|
|
|
CHECK_BODY("malloc-aligned10") {
|
|
|
|
bool ok = true;
|
|
|
|
void* p[10+1];
|
2022-12-03 00:23:43 +01:00
|
|
|
int align;
|
2022-11-25 14:03:00 -08:00
|
|
|
int j;
|
|
|
|
for(j = 0, align = 1; j <= 10 && ok; align *= 2, j++ ) {
|
|
|
|
p[j] = mi_malloc_aligned(43 + align, align);
|
2022-12-03 00:23:43 +01:00
|
|
|
ok = ((uintptr_t)p[j] % align) == 0;
|
2022-11-25 14:03:00 -08:00
|
|
|
}
|
|
|
|
for ( ; j > 0; j--) {
|
|
|
|
mi_free(p[j-1]);
|
|
|
|
}
|
|
|
|
result = ok;
|
|
|
|
}
|
2022-11-25 15:44:24 -08:00
|
|
|
CHECK_BODY("malloc_aligned11") {
|
|
|
|
mi_heap_t* heap = mi_heap_new();
|
|
|
|
void* p = mi_heap_malloc_aligned(heap, 33554426, 8);
|
|
|
|
result = mi_heap_contains_block(heap, p);
|
|
|
|
mi_heap_destroy(heap);
|
|
|
|
}
|
2023-04-14 10:02:01 -07:00
|
|
|
CHECK_BODY("mimalloc-aligned12") {
|
|
|
|
void* p = mi_malloc_aligned(0x100, 0x100);
|
|
|
|
result = (((uintptr_t)p % 0x100) == 0); // #602
|
|
|
|
mi_free(p);
|
|
|
|
}
|
2022-04-19 10:21:41 -07:00
|
|
|
CHECK_BODY("malloc-aligned-at1") {
|
2019-09-11 17:49:28 -07:00
|
|
|
void* p = mi_malloc_aligned_at(48,32,0); result = (p != NULL && ((uintptr_t)(p) + 0) % 32 == 0); mi_free(p);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
|
|
|
CHECK_BODY("malloc-aligned-at2") {
|
2019-09-11 17:49:28 -07:00
|
|
|
void* p = mi_malloc_aligned_at(50,32,8); result = (p != NULL && ((uintptr_t)(p) + 8) % 32 == 0); mi_free(p);
|
2022-12-03 00:23:43 +01:00
|
|
|
};
|
2022-04-19 10:21:41 -07:00
|
|
|
CHECK_BODY("memalign1") {
|
2020-02-17 09:59:34 -08:00
|
|
|
void* p;
|
|
|
|
bool ok = true;
|
|
|
|
for (int i = 0; i < 8 && ok; i++) {
|
|
|
|
p = mi_memalign(16,8);
|
|
|
|
ok = (p != NULL && (uintptr_t)(p) % 16 == 0); mi_free(p);
|
|
|
|
}
|
|
|
|
result = ok;
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
2023-04-22 10:18:57 -07:00
|
|
|
CHECK_BODY("zalloc-aligned-small1") {
|
|
|
|
size_t zalloc_size = MI_SMALL_SIZE_MAX / 2;
|
|
|
|
uint8_t* p = (uint8_t*)mi_zalloc_aligned(zalloc_size, MI_MAX_ALIGN_SIZE * 2);
|
|
|
|
result = mem_is_zero(p, zalloc_size);
|
|
|
|
mi_free(p);
|
|
|
|
};
|
|
|
|
CHECK_BODY("rezalloc_aligned-small1") {
|
|
|
|
size_t zalloc_size = MI_SMALL_SIZE_MAX / 2;
|
|
|
|
uint8_t* p = (uint8_t*)mi_zalloc_aligned(zalloc_size, MI_MAX_ALIGN_SIZE * 2);
|
|
|
|
result = mem_is_zero(p, zalloc_size);
|
|
|
|
zalloc_size *= 3;
|
|
|
|
p = (uint8_t*)mi_rezalloc_aligned(p, zalloc_size, MI_MAX_ALIGN_SIZE * 2);
|
|
|
|
result = result && mem_is_zero(p, zalloc_size);
|
|
|
|
mi_free(p);
|
|
|
|
};
|
2022-12-03 00:23:43 +01:00
|
|
|
|
2022-04-19 10:10:10 -07:00
|
|
|
// ---------------------------------------------------
|
|
|
|
// Reallocation
|
|
|
|
// ---------------------------------------------------
|
2022-04-19 10:21:41 -07:00
|
|
|
CHECK_BODY("realloc-null") {
|
2022-04-19 10:10:10 -07:00
|
|
|
void* p = mi_realloc(NULL,4);
|
|
|
|
result = (p != NULL);
|
|
|
|
mi_free(p);
|
|
|
|
};
|
|
|
|
|
2022-04-19 10:21:41 -07:00
|
|
|
CHECK_BODY("realloc-null-sizezero") {
|
2022-04-19 10:10:10 -07:00
|
|
|
void* p = mi_realloc(NULL,0); // <https://en.cppreference.com/w/c/memory/realloc> "If ptr is NULL, the behavior is the same as calling malloc(new_size)."
|
|
|
|
result = (p != NULL);
|
|
|
|
mi_free(p);
|
|
|
|
};
|
|
|
|
|
2022-04-19 10:21:41 -07:00
|
|
|
CHECK_BODY("realloc-sizezero") {
|
|
|
|
void* p = mi_malloc(4);
|
|
|
|
void* q = mi_realloc(p, 0);
|
|
|
|
result = (q != NULL);
|
|
|
|
mi_free(q);
|
|
|
|
};
|
|
|
|
|
2022-04-19 10:31:55 -07:00
|
|
|
CHECK_BODY("reallocarray-null-sizezero") {
|
|
|
|
void* p = mi_reallocarray(NULL,0,16); // issue #574
|
|
|
|
result = (p != NULL && errno == 0);
|
|
|
|
mi_free(p);
|
|
|
|
};
|
|
|
|
|
2019-06-27 13:36:19 -07:00
|
|
|
// ---------------------------------------------------
|
|
|
|
// Heaps
|
|
|
|
// ---------------------------------------------------
|
|
|
|
CHECK("heap_destroy", test_heap1());
|
|
|
|
CHECK("heap_delete", test_heap2());
|
|
|
|
|
2019-07-02 07:23:24 -07:00
|
|
|
//mi_stats_print(NULL);
|
|
|
|
|
2019-07-08 17:43:10 -07:00
|
|
|
// ---------------------------------------------------
|
|
|
|
// various
|
|
|
|
// ---------------------------------------------------
|
2022-04-19 10:21:41 -07:00
|
|
|
CHECK_BODY("realpath") {
|
2019-07-08 17:43:10 -07:00
|
|
|
char* s = mi_realpath( ".", NULL );
|
|
|
|
// printf("realpath: %s\n",s);
|
|
|
|
mi_free(s);
|
2022-04-19 10:21:41 -07:00
|
|
|
};
|
2019-07-08 17:43:10 -07:00
|
|
|
|
2020-01-06 16:18:22 -08:00
|
|
|
CHECK("stl_allocator1", test_stl_allocator1());
|
|
|
|
CHECK("stl_allocator2", test_stl_allocator2());
|
|
|
|
|
2019-06-27 13:36:19 -07:00
|
|
|
// ---------------------------------------------------
|
|
|
|
// Done
|
|
|
|
// ---------------------------------------------------[]
|
2021-12-21 12:39:17 +01:00
|
|
|
return print_test_summary();
|
2019-06-27 13:36:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------
|
|
|
|
// Larger test functions
|
|
|
|
// ---------------------------------------------------
|
|
|
|
|
2023-04-14 09:42:04 -07:00
|
|
|
bool test_heap1(void) {
|
2019-06-27 13:36:19 -07:00
|
|
|
mi_heap_t* heap = mi_heap_new();
|
|
|
|
int* p1 = mi_heap_malloc_tp(heap,int);
|
|
|
|
int* p2 = mi_heap_malloc_tp(heap,int);
|
|
|
|
*p1 = *p2 = 43;
|
|
|
|
mi_heap_destroy(heap);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-04-14 09:42:04 -07:00
|
|
|
bool test_heap2(void) {
|
2019-06-27 13:36:19 -07:00
|
|
|
mi_heap_t* heap = mi_heap_new();
|
|
|
|
int* p1 = mi_heap_malloc_tp(heap,int);
|
|
|
|
int* p2 = mi_heap_malloc_tp(heap,int);
|
|
|
|
mi_heap_delete(heap);
|
|
|
|
*p1 = 42;
|
|
|
|
mi_free(p1);
|
|
|
|
mi_free(p2);
|
|
|
|
return true;
|
|
|
|
}
|
2020-01-06 16:18:22 -08:00
|
|
|
|
2023-04-14 09:42:04 -07:00
|
|
|
bool test_stl_allocator1(void) {
|
2020-01-06 16:18:22 -08:00
|
|
|
#ifdef __cplusplus
|
2020-01-20 15:27:05 -08:00
|
|
|
std::vector<int, mi_stl_allocator<int> > vec;
|
2020-01-06 16:18:22 -08:00
|
|
|
vec.push_back(1);
|
|
|
|
vec.pop_back();
|
|
|
|
return vec.size() == 0;
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-01-20 15:27:05 -08:00
|
|
|
struct some_struct { int i; int j; double z; };
|
|
|
|
|
2023-04-14 09:42:04 -07:00
|
|
|
bool test_stl_allocator2(void) {
|
2020-01-06 16:18:22 -08:00
|
|
|
#ifdef __cplusplus
|
2020-01-20 15:27:05 -08:00
|
|
|
std::vector<some_struct, mi_stl_allocator<some_struct> > vec;
|
2020-01-06 16:18:22 -08:00
|
|
|
vec.push_back(some_struct());
|
|
|
|
vec.pop_back();
|
|
|
|
return vec.size() == 0;
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|