Python ctypes align data structure

Viewed 824

I have a C library that is compiled to a shared object and want to build a ctypes interface around it to call the C functions from Python.

In general it works fine but there is this definition of a double array in the C library:

typedef double __attribute__ ((aligned (32))) double_array[512];

I found no way to access this type directly, so I defined in Python:

DoubleArray = ctypes.c_double * 512

While this works out in most cases, sometimes the C library segfaults and I guess this happens because DoubleArray is not aligned to 32 bytes (maybe the library expects this because the data is passed to AVX).

How can I solve this problem?

1 Answers
Related