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