From d316d4f3933d39cbca67c61c462d45212aa86e13 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 5 Jan 2009 13:15:27 +0000 Subject: [PATCH] fix compilation on apple: _mm_malloc was undefined. the fix is to just use malloc since on apple it already returns aligned ptrs --- Eigen/src/Core/Matrix.h | 2 +- Eigen/src/Core/util/Memory.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 4851036e4..bb2bc2e2a 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -119,7 +119,7 @@ struct ei_traits > template -struct ei_matrix_with_aligned_operator_new : WithAlignedOperatorNew {}; +struct ei_matrix_with_aligned_operator_new : public WithAlignedOperatorNew {}; template struct ei_matrix_with_aligned_operator_new {}; diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h index 0e49ffeae..e4b3bc39c 100644 --- a/Eigen/src/Core/util/Memory.h +++ b/Eigen/src/Core/util/Memory.h @@ -56,6 +56,8 @@ inline T* ei_aligned_malloc(size_t size) #else #ifdef _MSC_VER void_result = _aligned_malloc(size*sizeof(T), 16); + #elif defined(__APPLE__) + void_result = malloc(size*sizeof(T)); // Apple's malloc() already returns aligned ptrs #else void_result = _mm_malloc(size*sizeof(T), 16); #endif @@ -71,7 +73,7 @@ inline T* ei_aligned_malloc(size_t size) // and this type has a custom operator new, then we want to honor this operator new! // so when we use C functions to allocate memory, we must be careful to call manually the constructor using // the special placement-new syntax. - return new(void_result) T[size]; + return new(void_result) T[size]; } else return new T[size]; // here we really want a new, not a malloc. Justification: if the user uses Eigen on @@ -95,6 +97,8 @@ inline void ei_aligned_free(T* ptr, size_t size) while(size) ptr[--size].~T(); #if defined(__linux) free(ptr); + #elif defined(__APPLE__) + free(ptr); #elif defined(_MSC_VER) _aligned_free(ptr); #else