diff --git a/ide/vs2017/mimalloc.vcxproj b/ide/vs2017/mimalloc.vcxproj index 98a3a230..4a831722 100644 --- a/ide/vs2017/mimalloc.vcxproj +++ b/ide/vs2017/mimalloc.vcxproj @@ -94,6 +94,7 @@ true ../../include MI_DEBUG=3;_MBCS;%(PreprocessorDefinitions); + Default @@ -110,6 +111,7 @@ true ../../include MI_DEBUG=3;_MBCS;%(PreprocessorDefinitions); + Default @@ -144,6 +146,7 @@ Neither false false + Default true @@ -174,6 +177,7 @@ Neither false false + Default true diff --git a/include/mimalloc-atomic.h b/include/mimalloc-atomic.h index fb97f59c..b295aae2 100644 --- a/include/mimalloc-atomic.h +++ b/include/mimalloc-atomic.h @@ -57,33 +57,35 @@ static inline void* mi_atomic_exchange_ptr(volatile void** p, void* exchange) { #include #include #if (MI_INTPTR_SIZE==8) +typedef LONG64 msc_intptr_t; #define RC64(f) f##64 #else +typedef LONG msc_intptr_t; #define RC64(f) f #endif static inline uintptr_t mi_atomic_increment(volatile uintptr_t* p) { - return (uintptr_t)RC64(_InterlockedIncrement)((volatile intptr_t*)p); + return (uintptr_t)RC64(_InterlockedIncrement)((volatile msc_intptr_t*)p); } static inline uint32_t mi_atomic_increment32(volatile uint32_t* p) { - return (uint32_t)_InterlockedIncrement((volatile int32_t*)p); + return (uint32_t)_InterlockedIncrement((volatile LONG*)p); } static inline uintptr_t mi_atomic_decrement(volatile uintptr_t* p) { - return (uintptr_t)RC64(_InterlockedDecrement)((volatile intptr_t*)p); + return (uintptr_t)RC64(_InterlockedDecrement)((volatile msc_intptr_t*)p); } static inline uintptr_t mi_atomic_subtract(volatile uintptr_t* p, uintptr_t sub) { - return (uintptr_t)RC64(_InterlockedExchangeAdd)((volatile intptr_t*)p, -((intptr_t)sub)) - sub; + return (uintptr_t)RC64(_InterlockedExchangeAdd)((volatile msc_intptr_t*)p, -((msc_intptr_t)sub)) - sub; } static inline uint32_t mi_atomic_subtract32(volatile uint32_t* p, uint32_t sub) { - return (uint32_t)_InterlockedExchangeAdd((volatile int32_t*)p, -((int32_t)sub)) - sub; + return (uint32_t)_InterlockedExchangeAdd((volatile LONG*)p, -((LONG)sub)) - sub; } static inline bool mi_atomic_compare_exchange32(volatile uint32_t* p, uint32_t exchange, uint32_t compare) { - return ((int32_t)compare == _InterlockedCompareExchange((volatile int32_t*)p, (int32_t)exchange, (int32_t)compare)); + return ((int32_t)compare == _InterlockedCompareExchange((volatile LONG*)p, (LONG)exchange, (LONG)compare)); } static inline bool mi_atomic_compare_exchange(volatile uintptr_t* p, uintptr_t exchange, uintptr_t compare) { - return (compare == RC64(_InterlockedCompareExchange)((volatile intptr_t*)p, (intptr_t)exchange, (intptr_t)compare)); + return (compare == RC64(_InterlockedCompareExchange)((volatile msc_intptr_t*)p, (msc_intptr_t)exchange, (msc_intptr_t)compare)); } static inline uintptr_t mi_atomic_exchange(volatile uintptr_t* p, uintptr_t exchange) { - return (uintptr_t)RC64(_InterlockedExchange)((volatile intptr_t*)p, (intptr_t)exchange); + return (uintptr_t)RC64(_InterlockedExchange)((volatile msc_intptr_t*)p, (msc_intptr_t)exchange); } static inline void mi_atomic_yield(void) { YieldProcessor(); diff --git a/include/mimalloc.h b/include/mimalloc.h index 51d903ad..ee4ff042 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -41,6 +41,7 @@ terms of the MIT license. A copy of the license can be found in the file #define mi_attr_malloc #define mi_attr_alloc_size(s) #define mi_attr_alloc_size2(s1,s2) + #define mi_cdecl __cdecl #elif defined(__GNUC__) || defined(__clang__) #define mi_decl_thread __thread #define mi_decl_export __attribute__((visibility("default"))) @@ -51,7 +52,8 @@ terms of the MIT license. A copy of the license can be found in the file #define mi_attr_alloc_size2(s1,s2) #else #define mi_attr_alloc_size(s) __attribute__((alloc_size(s))) - #define mi_attr_alloc_size2(s1,s2) __attribute__((alloc_size(s1,s2))) + #define mi_attr_alloc_size2(s1,s2) __attribute__((alloc_size(s1,s2))) + #define mi_cdecl // leads to warnings... __attribute__((cdecl)) #endif #else #define mi_decl_thread __thread @@ -60,6 +62,7 @@ terms of the MIT license. A copy of the license can be found in the file #define mi_attr_malloc #define mi_attr_alloc_size(s) #define mi_attr_alloc_size2(s1,s2) + #define mi_cdecl #endif // ------------------------------------------------------ @@ -186,7 +189,7 @@ typedef struct mi_heap_area_s { size_t block_size; // size in bytes of each block } mi_heap_area_t; -typedef bool (mi_block_visit_fun)(const mi_heap_t* heap, const mi_heap_area_t* area, void* block, size_t block_size, void* arg); +typedef bool (mi_cdecl mi_block_visit_fun)(const mi_heap_t* heap, const mi_heap_area_t* area, void* block, size_t block_size, void* arg); mi_decl_export bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_all_blocks, mi_block_visit_fun* visitor, void* arg); diff --git a/src/alloc.c b/src/alloc.c index 4f36544a..ac4d80c8 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -489,6 +489,7 @@ void* mi_new(std::size_t n) noexcept(false) { else return mi_new_try(n); } +#if (__cplusplus > 201402L || defined(__cpp_aligned_new)) // for aligned allocation its fine as it is not inlined anyways void* mi_new_aligned(std::size_t n, std::align_val_t alignment) noexcept(false) { void* p; @@ -500,5 +501,6 @@ void* mi_new_aligned(std::size_t n, std::align_val_t alignment) noexcept(false) }; return p; } +#endif #endif diff --git a/src/page-queue.c b/src/page-queue.c index ba5e9291..8817d992 100644 --- a/src/page-queue.c +++ b/src/page-queue.c @@ -56,7 +56,7 @@ static inline uint8_t mi_bsr32(uint32_t x); #include static inline uint8_t mi_bsr32(uint32_t x) { uint32_t idx; - _BitScanReverse(&idx, x); + _BitScanReverse((DWORD*)&idx, x); return idx; } #elif defined(__GNUC__) || defined(__clang__)