mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-06 23:39:31 +03:00
merge from dev
This commit is contained in:
commit
18fc788201
6 changed files with 21 additions and 13 deletions
|
@ -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_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)
|
option(MI_USE_LIBATOMIC "Explicitly link with -latomic (on older systems)" OFF)
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
include("cmake/mimalloc-config-version.cmake")
|
include("cmake/mimalloc-config-version.cmake")
|
||||||
|
|
||||||
set(mi_sources
|
set(mi_sources
|
||||||
|
@ -230,9 +231,9 @@ endif()
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
if (MI_INSTALL_TOPLEVEL)
|
if (MI_INSTALL_TOPLEVEL)
|
||||||
set(mi_install_libdir "lib")
|
set(mi_install_libdir "${CMAKE_INSTALL_LIBDIR}")
|
||||||
set(mi_install_incdir "include")
|
set(mi_install_incdir "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||||
set(mi_install_cmakedir "cmake")
|
set(mi_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/mimalloc")
|
||||||
else()
|
else()
|
||||||
set(mi_install_libdir "lib/mimalloc-${mi_version}")
|
set(mi_install_libdir "lib/mimalloc-${mi_version}")
|
||||||
set(mi_install_incdir "include/mimalloc-${mi_version}")
|
set(mi_install_incdir "include/mimalloc-${mi_version}")
|
||||||
|
|
|
@ -4,8 +4,8 @@ if (MIMALLOC_SHARE_DIR MATCHES "/share/")
|
||||||
string(REPLACE "/share/" "/lib/" MIMALLOC_LIBRARY_DIR ${MIMALLOC_SHARE_DIR})
|
string(REPLACE "/share/" "/lib/" MIMALLOC_LIBRARY_DIR ${MIMALLOC_SHARE_DIR})
|
||||||
string(REPLACE "/share/" "/include/" MIMALLOC_INCLUDE_DIR ${MIMALLOC_SHARE_DIR})
|
string(REPLACE "/share/" "/include/" MIMALLOC_INCLUDE_DIR ${MIMALLOC_SHARE_DIR})
|
||||||
else()
|
else()
|
||||||
# if MI_INSTALL_TOPLEVEL==ON
|
# installed with -DMI_INSTALL_TOPLEVEL=ON
|
||||||
set(MIMALLOC_LIBRARY_DIR "${MIMALLOC_SHARE_DIR}/lib")
|
string(REPLACE "/lib/cmake" "/lib" MIMALLOC_LIBRARY_DIR "${MIMALLOC_SHARE_DIR}")
|
||||||
set(MIMALLOC_INCLUDE_DIR "${MIMALLOC_SHARE_DIR}/include")
|
string(REPLACE "/lib/cmake" "/include" MIMALLOC_INCLUDE_DIR "${MIMALLOC_SHARE_DIR}")
|
||||||
endif()
|
endif()
|
||||||
set(MIMALLOC_TARGET_DIR "${MIMALLOC_LIBRARY_DIR}") # legacy
|
set(MIMALLOC_TARGET_DIR "${MIMALLOC_LIBRARY_DIR}") # legacy
|
||||||
|
|
|
@ -276,11 +276,11 @@ static inline bool mi_malloc_satisfies_alignment(size_t alignment, size_t size)
|
||||||
#endif
|
#endif
|
||||||
static inline bool mi_mul_overflow(size_t count, size_t size, size_t* total) {
|
static inline bool mi_mul_overflow(size_t count, size_t size, size_t* total) {
|
||||||
#if (SIZE_MAX == ULONG_MAX)
|
#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)
|
#elif (SIZE_MAX == UINT_MAX)
|
||||||
return __builtin_umul_overflow(count, size, total);
|
return __builtin_umul_overflow(count, size, (unsigned int *)total);
|
||||||
#else
|
#else
|
||||||
return __builtin_umulll_overflow(count, size, total);
|
return __builtin_umulll_overflow(count, size, (unsigned long long *)total);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#else /* __builtin_umul_overflow is unavailable */
|
#else /* __builtin_umul_overflow is unavailable */
|
||||||
|
|
|
@ -8,7 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||||
#ifndef MIMALLOC_H
|
#ifndef MIMALLOC_H
|
||||||
#define 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
|
// Compiler specific attributes
|
||||||
|
@ -391,6 +391,7 @@ mi_decl_nodiscard mi_decl_export void* mi_new_reallocn(void* p, size_t newcount,
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
#include <cstddef> // std::size_t
|
||||||
#include <cstdint> // PTRDIFF_MAX
|
#include <cstdint> // PTRDIFF_MAX
|
||||||
#if (__cplusplus >= 201103L) || (_MSC_VER > 1900) // C++11
|
#if (__cplusplus >= 201103L) || (_MSC_VER > 1900) // C++11
|
||||||
#include <type_traits> // std::true_type
|
#include <type_traits> // std::true_type
|
||||||
|
|
|
@ -802,7 +802,10 @@ static bool mi_try_new_handler(bool nothrow) {
|
||||||
std::set_new_handler(h);
|
std::set_new_handler(h);
|
||||||
#endif
|
#endif
|
||||||
if (h==NULL) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -830,9 +833,9 @@ static std_new_handler_t mi_get_new_handler() {
|
||||||
static bool mi_try_new_handler(bool nothrow) {
|
static bool mi_try_new_handler(bool nothrow) {
|
||||||
std_new_handler_t h = mi_get_new_handler();
|
std_new_handler_t h = mi_get_new_handler();
|
||||||
if (h==NULL) {
|
if (h==NULL) {
|
||||||
|
_mi_error_message(ENOMEM, "out of memory in 'new'");
|
||||||
if (!nothrow) {
|
if (!nothrow) {
|
||||||
_mi_error_message(EFAULT, "out of memory in 'new' call"); // cannot throw in plain C, use EFAULT to abort
|
abort(); // cannot throw in plain C, use abort
|
||||||
abort();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.0)
|
||||||
project(mimalloc-test C CXX)
|
project(mimalloc-test C CXX)
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
# Set default build type
|
# Set default build type
|
||||||
if (NOT CMAKE_BUILD_TYPE)
|
if (NOT CMAKE_BUILD_TYPE)
|
||||||
if ("${CMAKE_BINARY_DIR}" MATCHES ".*(D|d)ebug$")
|
if ("${CMAKE_BINARY_DIR}" MATCHES ".*(D|d)ebug$")
|
||||||
|
|
Loading…
Add table
Reference in a new issue