Logged In: YES
user_id=31435
You shouldn't pad the end "by hand". The last paragraph of
the struct module docs explains the intended method:
"""
Hint: to align the end of a structure to the alignment
requirement of a particular type, end the format with the
code for that type with a repeat count of zero. For example,
the format 'llh0l' specifies two pad bytes at the end, assuming
longs are aligned on 4-byte boundaries. This only works when
native size and alignment are in effect; standard size and
alignment does not enforce any alignment.
"""
Python can't guess how a platform compiler is going to pad
the *end* of a struct; indeed, it may well depend on C
compiler options. If the OP's compiler pads the end to int
alignment in the examle, then the OP can tell the struct
module that by using "iB0i".
I'm closing this now as WontFix, because Python is likely
doing the best it can already here; and, if it's not, it can't be
changed now without breaking working code (so if someone
thinks they know how to do better, it would have to go in as
a new function, or new option to calcsize (etc) -- then it's a
new feature, not a bugfix).
|