mirror of
https://github.com/microsoft/mimalloc.git
synced 2024-12-28 22:05:40 +08:00
Merge branch 'dev' into dev-slice
This commit is contained in:
commit
3d35147aba
@ -51,19 +51,19 @@ static void* mi_heap_malloc_zero_aligned_at(mi_heap_t* const heap, const size_t
|
||||
mi_assert(alignment > 0);
|
||||
if (mi_unlikely(alignment==0 || !_mi_is_power_of_two(alignment))) { // require power-of-two (see <https://en.cppreference.com/w/c/memory/aligned_alloc>)
|
||||
#if MI_DEBUG > 0
|
||||
_mi_error_message(EOVERFLOW, "aligned allocation requires the alignment to be a power-of-two (size %zu, alignment %zu)", size, alignment);
|
||||
_mi_error_message(EOVERFLOW, "aligned allocation requires the alignment to be a power-of-two (size %zu, alignment %zu)\n", size, alignment);
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
if (mi_unlikely(alignment > MI_ALIGNED_MAX)) { // we cannot align at a boundary larger than this (or otherwise we cannot find segment headers)
|
||||
#if MI_DEBUG > 0
|
||||
_mi_error_message(EOVERFLOW, "aligned allocation has a maximum alignment of %zu (size %zu, alignment %zu)", MI_ALIGNED_MAX, size, alignment);
|
||||
_mi_error_message(EOVERFLOW, "aligned allocation has a maximum alignment of %zu (size %zu, alignment %zu)\n", MI_ALIGNED_MAX, size, alignment);
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
if (mi_unlikely(size > PTRDIFF_MAX)) { // we don't allocate more than PTRDIFF_MAX (see <https://sourceware.org/ml/libc-announce/2019/msg00001.html>)
|
||||
#if MI_DEBUG > 0
|
||||
_mi_error_message(EOVERFLOW, "aligned allocation request is too large (size %zu, alignment %zu)", size, alignment);
|
||||
_mi_error_message(EOVERFLOW, "aligned allocation request is too large (size %zu, alignment %zu)\n", size, alignment);
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ mi_decl_restrict void* mi_pvalloc(size_t size) mi_attr_noexcept {
|
||||
mi_decl_restrict void* mi_aligned_alloc(size_t alignment, size_t size) mi_attr_noexcept {
|
||||
if (mi_unlikely((size&(alignment-1)) != 0)) { // C11 requires alignment>0 && integral multiple, see <https://en.cppreference.com/w/c/memory/aligned_alloc>
|
||||
#if MI_DEBUG > 0
|
||||
_mi_error_message(EOVERFLOW, "(mi_)aligned_alloc requires the size to be an integral multiple of the alignment (size %zu, alignment %zu)", size, alignment);
|
||||
_mi_error_message(EOVERFLOW, "(mi_)aligned_alloc requires the size to be an integral multiple of the alignment (size %zu, alignment %zu)\n", size, alignment);
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
@ -162,12 +162,18 @@ int main(void) {
|
||||
void* p;
|
||||
bool ok = true;
|
||||
for (int i = 1; i < 8 && ok; i++) {
|
||||
size_t align = 1UL << i;
|
||||
size_t align = (size_t)1 << i;
|
||||
p = mi_malloc_aligned(2*align, align);
|
||||
ok = (p != NULL && (uintptr_t)(p) % align == 0); mi_free(p);
|
||||
}
|
||||
result = ok;
|
||||
});
|
||||
CHECK_BODY("malloc-aligned7", {
|
||||
void* p = mi_malloc_aligned(1024,MI_ALIGNED_MAX); mi_free(p);
|
||||
});
|
||||
CHECK_BODY("malloc-aligned8", {
|
||||
void* p = mi_malloc_aligned(1024,2*MI_ALIGNED_MAX); mi_free(p);
|
||||
});
|
||||
CHECK_BODY("malloc-aligned-at1", {
|
||||
void* p = mi_malloc_aligned_at(48,32,0); result = (p != NULL && ((uintptr_t)(p) + 0) % 32 == 0); mi_free(p);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user