Passing a packed C structure to a c module

"Martin v. Löwis" martin at v.loewis.de
Fri Apr 14 15:09:23 EDT 2006


Philippe Martin wrote:
> The call actually is an IOCtl: depending on the control code, the structure
> has a different format.

Ah. In that case, I recommend to use the ioctl module; you won't need a
C wrapper, then.

> Although the number of control codes/structures is finite, it would make the
> wrapper function fairly large.

*Some* code to handle this will be very large, regardless of how you
write it.

> You seem to think that building the structure from python would be a
> mistake: why is that ?

It's very error-prone. You have to match the C structure layout of the
compiler precisely, and you even have to get the alignment right,
something that can't be done reliably in Python.

> PS: the wrapper also has to work under multiple OSs

That makes it worse: now you not only have to match the C compiler's
expectation on a single processor, but on different ones.

Perhaps you should be using ctypes.

Regards,
Martin



More information about the Python-list mailing list