memory: AlignedAlloc: fallback to aligned_alloc()

When compiling with clang++, __STDC_VERSION__ is not defined (obviously
as clang++ is not a C compiler). Because of this, check if compiling
with MSVC and fallback to the Linux implementation. If the latter is not
supported, compilation will fail, as it previously would have with the
This commit is contained in:
sephiroth99 2015-09-22 00:46:15 -04:00 committed by Ben Vanik
parent 83f3d520b2
commit ff7c755bc9
1 changed files with 6 additions and 10 deletions

View File

@ -67,25 +67,21 @@ bool Protect(void* base_address, size_t length, PageAccess access,
// The memory must be freed with AlignedFree. // The memory must be freed with AlignedFree.
template <typename T> template <typename T>
inline T* AlignedAlloc(size_t alignment) { inline T* AlignedAlloc(size_t alignment) {
#if __STDC_VERSION__ >= 201112L #if XE_COMPILER_MSVC
return reinterpret_cast<T*>(aligned_alloc(alignment, sizeof(T)));
#elif XE_COMPILER_MSVC
return reinterpret_cast<T*>(_aligned_malloc(sizeof(T), alignment)); return reinterpret_cast<T*>(_aligned_malloc(sizeof(T), alignment));
#else #else
#error No aligned alloc. return reinterpret_cast<T*>(aligned_alloc(alignment, sizeof(T)));
#endif // __STDC_VERSION__ >= 201112L #endif // XE_COMPILER_MSVC
} }
// Frees memory previously allocated with AlignedAlloc. // Frees memory previously allocated with AlignedAlloc.
template <typename T> template <typename T>
void AlignedFree(T* ptr) { void AlignedFree(T* ptr) {
#if __STDC_VERSION__ >= 201112L #if XE_COMPILER_MSVC
free(ptr);
#elif XE_COMPILER_MSVC
_aligned_free(ptr); _aligned_free(ptr);
#else #else
#error No aligned alloc. free(ptr);
#endif // __STDC_VERSION__ >= 201112L #endif // XE_COMPILER_MSVC
} }
typedef void* FileMappingHandle; typedef void* FileMappingHandle;