ctypes and misaligned doubles

Jan Roelens Jan.Roelens at gmail.com
Thu Dec 11 08:04:32 EST 2008


Dear python experts,

How can I change the alignment of types in the ctypes package? I have
a library that was built with gcc using the -malign-double option. I
also have python code that can create ctypes wrapper code from the
include files for that library. The problem is that structs that
contain fields of type double are not correctly wrapped half of the
time. This is because ctypes assumes an alignment of 4 (on a 32-bit
platform) for the double type, while the library I'm wrapping uses an
alignment of 8 for these doubles.

Is there a way to change the alignment of a ctypes type without
recompiling the whole ctypes package? If I can't change it, is there a
way to define my own type based on c_double but with a different
alignment?

Regards,
Jan



More information about the Python-list mailing list