Meador Inge <mead...@gmail.com> added the comment:

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?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12945>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to