This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author meador.inge
Recipients Pavel.Boldin, meador.inge
Date 2011-09-11.01:41:08
SpamBayes Score 3.5618864e-06
Marked as misclassified No
Message-id <1315705270.28.0.473539835897.issue12945@psf.upfronthosting.co.za>
In-reply-to
Content
Pavel, I looked into to this a little more and have some ideas.  First off, '_swappedbytes_' is an undocumented implementation detail that is used to implement the LittleEndianStructure and BigEndianStructure types.  So using it directly like that is not expected to work.  If you want to change the endianity of the layout, then use LittleEndianStructure or BigEndianStructure instead.

Next, consider your test case when removing '_swappedbytes_' and using a LittleEndianStructure.  I am using a Linux hosted Python which lays out the structures in a manner similar to GCC.  This gives a layout like:

 ---------------------------------------
 | unsigned short   | unsigned short   |
 ---------------------------------------
 | bbbbaaaa cccccccc dddddddd ........ |
 ---------------------------------------
 | 00010010 00110100 01010110 01111000 |
 ---------------------------------------

'a', 'b', and 'c' all get "expanded" into one 'unsigned short'.  Then 'd' has to go in an 'unsigned short' as well leaving one byte left over with don't cares.

Similarly, the big endian layout looks like:

 ---------------------------------------
 | unsigned short   | unsigned short   |
 ---------------------------------------
 | aaaabbbb cccccccc dddddddd ........ |
 ---------------------------------------
 | 00010010 00110100 01010110 01111000 |
 ---------------------------------------

All of this is really a roundabout way of saying that the documentation for ctypes structure layout stinks.  issue12880 has been opened to fix it.

Does this seem reasonable to you?
History
Date User Action Args
2011-09-11 01:41:10meador.ingesetrecipients: + meador.inge, Pavel.Boldin
2011-09-11 01:41:10meador.ingesetmessageid: <1315705270.28.0.473539835897.issue12945@psf.upfronthosting.co.za>
2011-09-11 01:41:09meador.ingelinkissue12945 messages
2011-09-11 01:41:09meador.ingecreate