merge from dev

This commit is contained in:
Daan 2021-11-14 15:39:05 -08:00
commit 18fc788201
6 changed files with 21 additions and 13 deletions

View File

@ -25,6 +25,7 @@ option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode
option(MI_INSTALL_TOPLEVEL "Install directly into $CMAKE_INSTALL_PREFIX instead of PREFIX/lib/mimalloc-version" OFF)
option(MI_USE_LIBATOMIC "Explicitly link with -latomic (on older systems)" OFF)
include(GNUInstallDirs)
include("cmake/mimalloc-config-version.cmake")
set(mi_sources
@ -230,9 +231,9 @@ endif()
# -----------------------------------------------------------------------------
if (MI_INSTALL_TOPLEVEL)
set(mi_install_libdir "lib")
set(mi_install_incdir "include")
set(mi_install_cmakedir "cmake")
set(mi_install_libdir "${CMAKE_INSTALL_LIBDIR}")
set(mi_install_incdir "${CMAKE_INSTALL_INCLUDEDIR}")
set(mi_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/mimalloc")
else()
set(mi_install_libdir "lib/mimalloc-${mi_version}")
set(mi_install_incdir "include/mimalloc-${mi_version}")

View File

@ -4,8 +4,8 @@ if (MIMALLOC_SHARE_DIR MATCHES "/share/")
string(REPLACE "/share/" "/lib/" MIMALLOC_LIBRARY_DIR ${MIMALLOC_SHARE_DIR})
string(REPLACE "/share/" "/include/" MIMALLOC_INCLUDE_DIR ${MIMALLOC_SHARE_DIR})
else()
# if MI_INSTALL_TOPLEVEL==ON
set(MIMALLOC_LIBRARY_DIR "${MIMALLOC_SHARE_DIR}/lib")
set(MIMALLOC_INCLUDE_DIR "${MIMALLOC_SHARE_DIR}/include")
# installed with -DMI_INSTALL_TOPLEVEL=ON
string(REPLACE "/lib/cmake" "/lib" MIMALLOC_LIBRARY_DIR "${MIMALLOC_SHARE_DIR}")
string(REPLACE "/lib/cmake" "/include" MIMALLOC_INCLUDE_DIR "${MIMALLOC_SHARE_DIR}")
endif()
set(MIMALLOC_TARGET_DIR "${MIMALLOC_LIBRARY_DIR}") # legacy

View File

@ -276,11 +276,11 @@ static inline bool mi_malloc_satisfies_alignment(size_t alignment, size_t size)
#endif
static inline bool mi_mul_overflow(size_t count, size_t size, size_t* total) {
#if (SIZE_MAX == ULONG_MAX)
return __builtin_umull_overflow(count, size, total);
return __builtin_umull_overflow(count, size, (unsigned long *)total);
#elif (SIZE_MAX == UINT_MAX)
return __builtin_umul_overflow(count, size, total);
return __builtin_umul_overflow(count, size, (unsigned int *)total);
#else
return __builtin_umulll_overflow(count, size, total);
return __builtin_umulll_overflow(count, size, (unsigned long long *)total);
#endif
}
#else /* __builtin_umul_overflow is unavailable */

View File

@ -8,7 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file
#ifndef MIMALLOC_H
#define MIMALLOC_H
#define MI_MALLOC_VERSION 201 // major + 2 digits minor
#define MI_MALLOC_VERSION 203 // major + 2 digits minor
// ------------------------------------------------------
// Compiler specific attributes
@ -391,6 +391,7 @@ mi_decl_nodiscard mi_decl_export void* mi_new_reallocn(void* p, size_t newcount,
// ---------------------------------------------------------------------------------------------
#ifdef __cplusplus
#include <cstddef> // std::size_t
#include <cstdint> // PTRDIFF_MAX
#if (__cplusplus >= 201103L) || (_MSC_VER > 1900) // C++11
#include <type_traits> // std::true_type

View File

@ -802,7 +802,10 @@ static bool mi_try_new_handler(bool nothrow) {
std::set_new_handler(h);
#endif
if (h==NULL) {
if (!nothrow) throw std::bad_alloc();
_mi_error_message(ENOMEM, "out of memory in 'new'");
if (!nothrow) {
throw std::bad_alloc();
}
return false;
}
else {
@ -830,9 +833,9 @@ static std_new_handler_t mi_get_new_handler() {
static bool mi_try_new_handler(bool nothrow) {
std_new_handler_t h = mi_get_new_handler();
if (h==NULL) {
_mi_error_message(ENOMEM, "out of memory in 'new'");
if (!nothrow) {
_mi_error_message(EFAULT, "out of memory in 'new' call"); // cannot throw in plain C, use EFAULT to abort
abort();
abort(); // cannot throw in plain C, use abort
}
return false;
}

View File

@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 3.0)
project(mimalloc-test C CXX)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
# Set default build type
if (NOT CMAKE_BUILD_TYPE)
if ("${CMAKE_BINARY_DIR}" MATCHES ".*(D|d)ebug$")