Fix compilation error with MSVC C++

This commit is contained in:
daan 2019-07-07 21:59:53 -07:00
parent 7e743dfb58
commit 7f0137a617
5 changed files with 22 additions and 11 deletions

View File

@ -94,6 +94,7 @@
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../../include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>MI_DEBUG=3;_MBCS;%(PreprocessorDefinitions);</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
</ClCompile>
<Lib>
<AdditionalLibraryDirectories>
@ -110,6 +111,7 @@
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../../include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>MI_DEBUG=3;_MBCS;%(PreprocessorDefinitions);</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
</ClCompile>
<PostBuildEvent>
<Command>
@ -144,6 +146,7 @@
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
<OmitFramePointers>false</OmitFramePointers>
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
<CompileAs>Default</CompileAs>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@ -174,6 +177,7 @@
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
<OmitFramePointers>false</OmitFramePointers>
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
<CompileAs>Default</CompileAs>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>

View File

@ -57,33 +57,35 @@ static inline void* mi_atomic_exchange_ptr(volatile void** p, void* exchange) {
#include <windows.h>
#include <intrin.h>
#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();

View File

@ -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);

View File

@ -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

View File

@ -56,7 +56,7 @@ static inline uint8_t mi_bsr32(uint32_t x);
#include <intrin.h>
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__)