Merge branch 'dev' into dev-slice

This commit is contained in:
daan 2022-10-31 16:17:17 -07:00
commit 43ce102425
2 changed files with 15 additions and 9 deletions

View file

@ -262,8 +262,11 @@ else()
set(pc_libraries "${pc_libraries} -lrt") set(pc_libraries "${pc_libraries} -lrt")
endif() endif()
find_library(MI_LIBATOMIC atomic) find_library(MI_LIBATOMIC atomic)
if (MI_LIBATOMIC OR MI_USE_LIBATOMIC) if (NOT MI_LIBATOMIC AND MI_USE_LIBATOMIC)
list(APPEND mi_libraries atomic) set(MI_LIBATOMIC atomic)
endif()
if (MI_LIBATOMIC)
list(APPEND mi_libraries ${MI_LIBATOMIC})
set(pc_libraries "${pc_libraries} -latomic") set(pc_libraries "${pc_libraries} -latomic")
endif() endif()
endif() endif()

View file

@ -83,13 +83,16 @@ mi_decl_nodiscard mi_decl_restrict void* mi_pvalloc(size_t size) mi_attr_noexcep
} }
mi_decl_nodiscard mi_decl_restrict void* mi_aligned_alloc(size_t alignment, size_t size) mi_attr_noexcept { mi_decl_nodiscard 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> // C11 requires the size to be an integral multiple of the alignment, see <https://en.cppreference.com/w/c/memory/aligned_alloc>.
#if MI_DEBUG > 0 // unfortunately, it turns out quite some programs pass a size that is not an integral multiple so skip this check..
_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); /* if mi_unlikely((size & (alignment - 1)) != 0) { // C11 requires alignment>0 && integral multiple, see <https://en.cppreference.com/w/c/memory/aligned_alloc>
#endif #if MI_DEBUG > 0
return NULL; _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
// C11 also requires alignment to be a power-of-two which is checked in mi_malloc_aligned return NULL;
}
*/
// C11 also requires alignment to be a power-of-two (and > 0) which is checked in mi_malloc_aligned
void* p = mi_malloc_aligned(size, alignment); void* p = mi_malloc_aligned(size, alignment);
mi_assert_internal(((uintptr_t)p % alignment) == 0); mi_assert_internal(((uintptr_t)p % alignment) == 0);
return p; return p;