[issue20629] Python ctypes BigEndianStructure bitfield assignment misbehavior in Linux

Michael Rolle report at bugs.python.org
Tue Nov 8 22:43:19 EST 2016


Michael Rolle added the comment:

As a separate issue, I'd like to find an appropriate package,
other than ctypes, for interpreting data bytes in a consistently
defined manner, independent of the platform I'm running on.
The struct package is perfect where there are no bitfields
involved, i.e., where each item occupies whole bytes.  But
it doesn't support packing/unpacking bitfields.

Actually, ctypes could fit the bill if you specified that bitfields
be allocated from MSB to LSB for BigEndianStructure, and from LSB
to MSB for LittleEndianStructure.  This way, for instance, it wouldn't matter if a sequence of 4-bit fields were based on c_ubyte
or c_ushort, etc.  Each pair of fields would be allocated to the
next consecutive byte.  And if the platform native compiler for some strange reason doesn't follow either of these rules, then Structure
would follow the platform compiler.

differs from both Big and Little

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20629>
_______________________________________


More information about the Python-bugs-list mailing list