mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-09 07:00:27 +08:00
eventually it turns out that our current
EIGEN_WORK_AROUND_QT_BUG_CALLING_WRONG_OPERATOR_NEW_FIXED_IN_QT_4_5 is the right way to go for allowing placement new on a class having overloaded operator new. Qt 4.5 won't add the :: prefix. (I still do not understand how you can distinghish a placement new from an overloaded operator new taking an allocator as argument...)
This commit is contained in:
parent
e7c48fac9b
commit
9849931500
@ -233,27 +233,7 @@ inline static int ei_alignmentOffset(const Scalar* ptr, int maxOffset)
|
||||
#define ei_aligned_stack_delete(TYPE,PTR,SIZE) do {ei_delete_elements_of_array<TYPE>(PTR, SIZE); \
|
||||
ei_aligned_stack_free(PTR,sizeof(TYPE)*SIZE);} while(0)
|
||||
|
||||
/** Qt <= 4.4 has a bug where it calls new(ptr) T instead of ::new(ptr) T.
|
||||
* This fails as we overload other operator new but not this one. What Qt really means is placement new.
|
||||
* Since this is getting used only with fixed-size Eigen matrices where the ctor does nothing, it is OK to
|
||||
* emulate placement new by just returning the ptr -- no need to call ctors. Good, because we don't know the
|
||||
* class in this macro. So this can safely be used for QVector<Eigen::Vector4f> but definitely not for
|
||||
* QVector<Eigen::VectorXf>.
|
||||
*
|
||||
* This macro will go away as soon as Qt >= 4.5 is prevalent -- most likely it should go away in Eigen 2.1.
|
||||
*/
|
||||
#ifdef EIGEN_WORK_AROUND_QT_BUG_CALLING_WRONG_OPERATOR_NEW_FIXED_IN_QT_4_5
|
||||
#define EIGEN_WORKAROUND_FOR_QT_BUG_CALLING_WRONG_OPERATOR_NEW \
|
||||
void *operator new(size_t, void *ptr) throw() { \
|
||||
return ptr; \
|
||||
} \
|
||||
void *operator new[](size_t, void *ptr) throw() { \
|
||||
return ptr; \
|
||||
}
|
||||
#else
|
||||
#define EIGEN_WORKAROUND_FOR_QT_BUG_CALLING_WRONG_OPERATOR_NEW
|
||||
#endif
|
||||
|
||||
|
||||
/** \brief Overloads the operator new and delete of the class Type with operators that are aligned if NeedsToAlign is true
|
||||
*
|
||||
* When Eigen's explicit vectorization is enabled, Eigen assumes that some fixed sizes types are aligned
|
||||
@ -301,7 +281,7 @@ inline static int ei_alignmentOffset(const Scalar* ptr, int maxOffset)
|
||||
} \
|
||||
void operator delete(void * ptr) { Eigen::ei_conditional_aligned_free<NeedsToAlign>(ptr); } \
|
||||
void operator delete[](void * ptr) { Eigen::ei_conditional_aligned_free<NeedsToAlign>(ptr); } \
|
||||
EIGEN_WORKAROUND_FOR_QT_BUG_CALLING_WRONG_OPERATOR_NEW
|
||||
void *operator new(size_t, void *ptr) throw() { return ptr; }
|
||||
|
||||
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(true)
|
||||
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar,Size) \
|
||||
|
@ -37,6 +37,10 @@ void check_qtvector_matrix(const MatrixType& m)
|
||||
int cols = m.cols();
|
||||
MatrixType x = MatrixType::Random(rows,cols), y = MatrixType::Random(rows,cols);
|
||||
QVector<MatrixType> v(10, MatrixType(rows,cols)), w(20, y);
|
||||
for(int i = 0; i < 20; i++)
|
||||
{
|
||||
VERIFY_IS_APPROX(w[i], y);
|
||||
}
|
||||
v[5] = x;
|
||||
w[6] = v[5];
|
||||
VERIFY_IS_APPROX(w[6], v[5]);
|
||||
@ -50,7 +54,6 @@ void check_qtvector_matrix(const MatrixType& m)
|
||||
v[20] = x;
|
||||
VERIFY_IS_APPROX(v[20], x);
|
||||
v.fill(y,22);
|
||||
//v.resize(22);
|
||||
VERIFY_IS_APPROX(v[21], y);
|
||||
v.push_back(x);
|
||||
VERIFY_IS_APPROX(v[22], x);
|
||||
@ -86,7 +89,6 @@ void check_qtvector_transform(const TransformType&)
|
||||
v[20] = x;
|
||||
VERIFY_IS_APPROX(v[20], x);
|
||||
v.fill(y,22);
|
||||
//v.resize(22);
|
||||
VERIFY_IS_APPROX(v[21], y);
|
||||
v.push_back(x);
|
||||
VERIFY_IS_APPROX(v[22], x);
|
||||
@ -122,7 +124,6 @@ void check_qtvector_quaternion(const QuaternionType&)
|
||||
v[20] = x;
|
||||
VERIFY_IS_APPROX(v[20], x);
|
||||
v.fill(y,22);
|
||||
//v.resize(22);
|
||||
VERIFY_IS_APPROX(v[21], y);
|
||||
v.push_back(x);
|
||||
VERIFY_IS_APPROX(v[22], x);
|
||||
|
Loading…
Reference in New Issue
Block a user