diff options
author | Christoph Hertzberg <chtz@informatik.uni-bremen.de> | 2014-07-22 13:16:44 +0200 |
---|---|---|
committer | Christoph Hertzberg <chtz@informatik.uni-bremen.de> | 2014-07-22 13:16:44 +0200 |
commit | a8283e0ed2d3e42ba8e1c42f51cb08eacc301047 (patch) | |
tree | c9c78db74cdb680132a8779db69cf53ee73390ba /Eigen | |
parent | 529e6cb5529f626b7c5cf781bdcd5a5720f904c1 (diff) |
Define EIGEN_TRY, EIGEN_CATCH, EIGEN_THROW as suggested by Moritz Klammer.
Make it possible to run unit-tests with exceptions disabled via EIGEN_TEST_NO_EXCEPTIONS flag.
Enhanced ctorleak unit-test
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/Core | 16 | ||||
-rw-r--r-- | Eigen/src/Core/util/Macros.h | 12 | ||||
-rw-r--r-- | Eigen/src/Core/util/Memory.h | 145 |
3 files changed, 76 insertions, 97 deletions
diff --git a/Eigen/Core b/Eigen/Core index 16e388fa4..9a73fe37b 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -42,6 +42,14 @@ #define EIGEN_USING_STD_MATH(FUNC) using std::FUNC; #endif +#if (defined(_CPPUNWIND) || defined(__EXCEPTIONS)) && !defined(__CUDA_ARCH__) + #define EIGEN_EXCEPTIONS +#endif + +#ifdef EIGEN_EXCEPTIONS + #include <new> +#endif + // then include this file where all our macros are defined. It's really important to do it first because // it's where we do all the alignment settings (platform detection and honoring the user's will if he // defined e.g. EIGEN_DONT_ALIGN) so it needs to be done before we do anything with vectorization. @@ -209,14 +217,6 @@ #include <intrin.h> #endif -#if (defined(_CPPUNWIND) || defined(__EXCEPTIONS)) && !defined(__CUDA_ARCH__) - #define EIGEN_EXCEPTIONS -#endif - -#ifdef EIGEN_EXCEPTIONS - #include <new> -#endif - /** \brief Namespace containing all symbols from the %Eigen library. */ namespace Eigen { diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 71e42b125..5e9b0a112 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -452,4 +452,16 @@ namespace Eigen { const RHS \ > +#ifdef EIGEN_EXCEPTIONS +# define EIGEN_THROW_X(X) throw X +# define EIGEN_THROW throw +# define EIGEN_TRY try +# define EIGEN_CATCH(X) catch (X) +#else +# define EIGEN_THROW_X(X) std::abort() +# define EIGEN_THROW std::abort() +# define EIGEN_TRY if (true) +# define EIGEN_CATCH(X) else +#endif + #endif // EIGEN_MACROS_H diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h index 9b3e84fb0..38990566d 100644 --- a/Eigen/src/Core/util/Memory.h +++ b/Eigen/src/Core/util/Memory.h @@ -354,20 +354,16 @@ template<typename T> inline void destruct_elements_of_array(T *ptr, size_t size) template<typename T> inline T* construct_elements_of_array(T *ptr, size_t size) { size_t i; -#ifdef EIGEN_EXCEPTIONS - try -#endif - { + EIGEN_TRY + { for (i = 0; i < size; ++i) ::new (ptr + i) T; return ptr; - } -#ifdef EIGEN_EXCEPTIONS - catch (...) - { - destruct_elements_of_array(ptr, i); - throw; - } -#endif + } + EIGEN_CATCH(...) + { + destruct_elements_of_array(ptr, i); + EIGEN_THROW; + } } /***************************************************************************** @@ -389,38 +385,30 @@ template<typename T> inline T* aligned_new(size_t size) { check_size_for_overflow<T>(size); T *result = reinterpret_cast<T*>(aligned_malloc(sizeof(T)*size)); -#ifdef EIGEN_EXCEPTIONS - try -#endif - { - return construct_elements_of_array(result, size); - } -#ifdef EIGEN_EXCEPTIONS - catch (...) - { - aligned_free(result); - throw; - } -#endif + EIGEN_TRY + { + return construct_elements_of_array(result, size); + } + EIGEN_CATCH(...) + { + aligned_free(result); + EIGEN_THROW; + } } template<typename T, bool Align> inline T* conditional_aligned_new(size_t size) { check_size_for_overflow<T>(size); T *result = reinterpret_cast<T*>(conditional_aligned_malloc<Align>(sizeof(T)*size)); -#ifdef EIGEN_EXCEPTIONS - try -#endif - { - return construct_elements_of_array(result, size); - } -#ifdef EIGEN_EXCEPTIONS - catch (...) - { - conditional_aligned_free<Align>(result); - throw; - } -#endif + EIGEN_TRY + { + return construct_elements_of_array(result, size); + } + EIGEN_CATCH(...) + { + conditional_aligned_free<Align>(result); + EIGEN_THROW; + } } /** \internal Deletes objects constructed with aligned_new @@ -449,21 +437,17 @@ template<typename T, bool Align> inline T* conditional_aligned_realloc_new(T* pt destruct_elements_of_array(pts+new_size, old_size-new_size); T *result = reinterpret_cast<T*>(conditional_aligned_realloc<Align>(reinterpret_cast<void*>(pts), sizeof(T)*new_size, sizeof(T)*old_size)); if(new_size > old_size) + { + EIGEN_TRY { -#ifdef EIGEN_EXCEPTIONS - try -#endif - { - construct_elements_of_array(result+old_size, new_size-old_size); - } -#ifdef EIGEN_EXCEPTIONS - catch (...) - { - conditional_aligned_free<Align>(result); - throw; - } -#endif + construct_elements_of_array(result+old_size, new_size-old_size); + } + EIGEN_CATCH(...) + { + conditional_aligned_free<Align>(result); + EIGEN_THROW; } + } return result; } @@ -473,21 +457,17 @@ template<typename T, bool Align> inline T* conditional_aligned_new_auto(size_t s check_size_for_overflow<T>(size); T *result = reinterpret_cast<T*>(conditional_aligned_malloc<Align>(sizeof(T)*size)); if(NumTraits<T>::RequireInitialization) + { + EIGEN_TRY { -#ifdef EIGEN_EXCEPTIONS - try -#endif - { - construct_elements_of_array(result, size); - } -#ifdef EIGEN_EXCEPTIONS - catch (...) - { - conditional_aligned_free<Align>(result); - throw; - } -#endif + construct_elements_of_array(result, size); } + EIGEN_CATCH(...) + { + conditional_aligned_free<Align>(result); + EIGEN_THROW; + } + } return result; } @@ -499,21 +479,17 @@ template<typename T, bool Align> inline T* conditional_aligned_realloc_new_auto( destruct_elements_of_array(pts+new_size, old_size-new_size); T *result = reinterpret_cast<T*>(conditional_aligned_realloc<Align>(reinterpret_cast<void*>(pts), sizeof(T)*new_size, sizeof(T)*old_size)); if(NumTraits<T>::RequireInitialization && (new_size > old_size)) + { + EIGEN_TRY { -#ifdef EIGEN_EXCEPTIONS - try -#endif - { - construct_elements_of_array(result+old_size, new_size-old_size); - } -#ifdef EIGEN_EXCEPTIONS - catch (...) - { - conditional_aligned_free<Align>(result); - throw; - } -#endif + construct_elements_of_array(result+old_size, new_size-old_size); + } + EIGEN_CATCH(...) + { + conditional_aligned_free<Align>(result); + EIGEN_THROW; } + } return result; } @@ -713,20 +689,11 @@ template<typename T> class aligned_stack_memory_handler *****************************************************************************/ #if EIGEN_ALIGN - #ifdef EIGEN_EXCEPTIONS - #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \ - void* operator new(size_t size, const std::nothrow_t&) throw() { \ - try { return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); } \ - catch (...) { return 0; } \ - return 0; \ - } - #else - #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \ + #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \ void* operator new(size_t size, const std::nothrow_t&) throw() { \ - return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \ + EIGEN_TRY { return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); } \ + EIGEN_CATCH (...) { return 0; } \ } - #endif - #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \ void *operator new(size_t size) { \ return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \ |