From 0ead911b6b1e1b5a531a156587c5d011f52f47e8 Mon Sep 17 00:00:00 2001 From: Yaroslav Syrytsia Date: Tue, 28 Sep 2021 20:34:56 +0300 Subject: [PATCH 1/6] cmake: removed hardcoded names for top level configuration --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b56953c4..9ba14a38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ option(MI_DEBUG_UBSAN "Build with undefined-behavior sanitizer (needs clan option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode (deprecated, use MI_DEBUG_FULL instead)" OFF) option(MI_INSTALL_TOPLEVEL "Install directly into $CMAKE_INSTALL_PREFIX instead of PREFIX/lib/mimalloc-version" OFF) +include(GNUInstallDirs) include("cmake/mimalloc-config-version.cmake") set(mi_sources @@ -208,9 +209,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}") From 5b0e73281fd4d98b6f211cdd1b6b29453c3e420e Mon Sep 17 00:00:00 2001 From: dc Date: Thu, 28 Oct 2021 22:43:21 +0100 Subject: [PATCH 2/6] fix spurious build warning with overflow builtins --- include/mimalloc-internal.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h index 0563d3de..982928cb 100644 --- a/include/mimalloc-internal.h +++ b/include/mimalloc-internal.h @@ -247,11 +247,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 */ From 4ce6821c09506d29feabdb8cfc4ac1d94b6574b6 Mon Sep 17 00:00:00 2001 From: Daan Date: Sun, 14 Nov 2021 15:32:21 -0800 Subject: [PATCH 3/6] update cmake install for MI_INSTALL_TOPLEVEL --- cmake/mimalloc-config.cmake | 6 +++--- test/CMakeLists.txt | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmake/mimalloc-config.cmake b/cmake/mimalloc-config.cmake index 024c97d9..9b0a56d7 100644 --- a/cmake/mimalloc-config.cmake +++ b/cmake/mimalloc-config.cmake @@ -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 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7986d2da..13bf32de 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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$") From d67ff1ca9fbffee067f5bbfa8b0c6e6e90437ec2 Mon Sep 17 00:00:00 2001 From: Daan Date: Sun, 14 Nov 2021 15:32:43 -0800 Subject: [PATCH 4/6] add include cstdef for std::size_t in C++ --- include/mimalloc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/mimalloc.h b/include/mimalloc.h index a77f1dc5..0a4ae689 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -388,6 +388,7 @@ mi_decl_nodiscard mi_decl_export void* mi_new_reallocn(void* p, size_t newcount, // --------------------------------------------------------------------------------------------- #ifdef __cplusplus +#include // std::size_t #include // PTRDIFF_MAX #if (__cplusplus >= 201103L) || (_MSC_VER > 1900) // C++11 #include // std::true_type From 07253fb44c3c220c93dbb64c6dd12c5d7608fb4a Mon Sep 17 00:00:00 2001 From: Daan Date: Sun, 14 Nov 2021 15:33:04 -0800 Subject: [PATCH 5/6] emit error message if out-of-memory in C++ --- src/alloc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 1dbd31a7..d9b6dd60 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -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; } From 4a590b1447e9d27e00dcd5bc9ac62eab6d7e51bb Mon Sep 17 00:00:00 2001 From: Daan Date: Sun, 14 Nov 2021 15:33:56 -0800 Subject: [PATCH 6/6] bump version number to 1.7.3 --- include/mimalloc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mimalloc.h b/include/mimalloc.h index 0a4ae689..4467173e 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -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 171 // major + 2 digits minor +#define MI_MALLOC_VERSION 173 // major + 2 digits minor // ------------------------------------------------------ // Compiler specific attributes