Skip to content

Commit 8cd3f65

Browse files
committed
core: make generic alignment of struct
1 parent e5a8217 commit 8cd3f65

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

include/eigenpy/memory.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ static inline void _Py_SET_SIZE(PyVarObject* ob, Py_ssize_t size) {
1515
#define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size)
1616
#endif
1717

18+
#if EIGEN_DEFAULT_ALIGN_BYTES > 16
19+
#define EIGENPY_DEFAULT_ALIGN_BYTES EIGEN_DEFAULT_ALIGN_BYTES
20+
#else
21+
#define EIGENPY_DEFAULT_ALIGN_BYTES 16
22+
#endif
23+
1824
/**
1925
* This section contains a convenience MACRO which allows an easy specialization
2026
* 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) {
4248
\
4349
union { \
4450
align_t align; \
45-
char bytes[sizeof(Data) + 16]; \
51+
char bytes[sizeof(Data) + EIGENPY_DEFAULT_ALIGN_BYTES]; \
4652
} storage; \
4753
}; \
4854
\
@@ -96,7 +102,9 @@ static inline void _Py_SET_SIZE(PyVarObject* ob, Py_ssize_t size) {
96102
void* storage, PyObject* instance, \
97103
reference_wrapper<__VA_ARGS__ const> x) { \
98104
void* aligned_storage = reinterpret_cast<void*>( \
99-
(reinterpret_cast<size_t>(storage) & ~(size_t(15))) + 16); \
105+
(reinterpret_cast<size_t>(storage) & \
106+
~(size_t(EIGENPY_DEFAULT_ALIGN_BYTES - 1))) + \
107+
EIGENPY_DEFAULT_ALIGN_BYTES); \
100108
value_holder<__VA_ARGS__>* new_holder = \
101109
new (aligned_storage) value_holder<__VA_ARGS__>(instance, x); \
102110
return new_holder; \

0 commit comments

Comments
 (0)