Skip to content
Snippets Groups Projects
Verified Commit 8cd3f654 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

core: make generic alignment of struct

parent e5a82173
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,12 @@ static inline void _Py_SET_SIZE(PyVarObject* ob, Py_ssize_t size) {
#define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size)
#endif
#if EIGEN_DEFAULT_ALIGN_BYTES > 16
#define EIGENPY_DEFAULT_ALIGN_BYTES EIGEN_DEFAULT_ALIGN_BYTES
#else
#define EIGENPY_DEFAULT_ALIGN_BYTES 16
#endif
/**
* This section contains a convenience MACRO which allows an easy specialization
* of Boost Python Object allocator for struct data types containing Eigen
......@@ -42,7 +48,7 @@ static inline void _Py_SET_SIZE(PyVarObject* ob, Py_ssize_t size) {
\
union { \
align_t align; \
char bytes[sizeof(Data) + 16]; \
char bytes[sizeof(Data) + EIGENPY_DEFAULT_ALIGN_BYTES]; \
} storage; \
}; \
\
......@@ -96,7 +102,9 @@ static inline void _Py_SET_SIZE(PyVarObject* ob, Py_ssize_t size) {
void* storage, PyObject* instance, \
reference_wrapper<__VA_ARGS__ const> x) { \
void* aligned_storage = reinterpret_cast<void*>( \
(reinterpret_cast<size_t>(storage) & ~(size_t(15))) + 16); \
(reinterpret_cast<size_t>(storage) & \
~(size_t(EIGENPY_DEFAULT_ALIGN_BYTES - 1))) + \
EIGENPY_DEFAULT_ALIGN_BYTES); \
value_holder<__VA_ARGS__>* new_holder = \
new (aligned_storage) value_holder<__VA_ARGS__>(instance, x); \
return new_holder; \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment