[Python-Dev] ctypes: alignment of (simple) types

Michael Walle michael at walle.cc
Mon Nov 7 23:37:46 CET 2011


Hi all,

gcc allows to set alignments for typedefs like:

typedef double MyDouble __attribute__((__aligned__(8)));

Now if i use this new type within a structure:

struct s {
	char c;
	MyDouble d;
};

The following holds: sizeof(struct s) == 16 and offsetof(struct s, d) == 8.

ctypes doesn't seem to support this, although i saw a 'padded' function on
the ctypes-users mailinglist which dynamically insert padding fields. I would 
consider this more or less a hack :)

What do you think about adding a special attribute '_align_' which, if set for
a data type overrides the hardcoded align property of that type?

-- 
Michael


More information about the Python-Dev mailing list