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 Brian Trotter
Recipients Alan.Ning, Brian Trotter, amaury.forgeotdarc, belopolsky, rgaddi
Date 2015-09-11.19:18:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1441999123.77.0.693168566926.issue20629@psf.upfronthosting.co.za>
In-reply-to
Content
I am experiencing the same bug with c_uint32 bitfields inside BigEndianStructure in Python 3.4.0 on Ubuntu 14.04.3 x64. No problem in Windows 7 x64. As shown in the example below, the fourth byte is the only one that is written correctly. This is a rather significant error.


Source:

import ctypes

class BitFieldsBE(ctypes.BigEndianStructure):
    _pack_ = 1
    _fields_ = [
        ('a', ctypes.c_uint32, 8),
        ('b', ctypes.c_uint32, 8),
        ('c', ctypes.c_uint32, 8),
        ('d', ctypes.c_uint32, 8)]

class BitFieldsLE(ctypes.LittleEndianStructure):
    _pack_ = 1
    _fields_ = [
        ('a', ctypes.c_uint32, 8),
        ('b', ctypes.c_uint32, 8),
        ('c', ctypes.c_uint32, 8),
        ('d', ctypes.c_uint32, 8)]

be = BitFieldsBE()
le = BitFieldsLE()

def prints(arg):
    print(arg)
    print('be',bytes(be))
    print('le',bytes(le))

prints('00000000')
be.a = 0xba; be.b = 0xbe; be.c = 0xfa; be.d = 0xce
le.a = 0xba; le.b = 0xbe; le.c = 0xfa; le.d = 0xce
prints('babeface')
be.a = 0xde; be.b = 0xad; be.c = 0xbe; be.d = 0xef
le.a = 0xde; le.b = 0xad; le.c = 0xbe; le.d = 0xef
prints('deadbeef')


Output:

00000000
be b'\x00\x00\x00\x00'
le b'\x00\x00\x00\x00'
babeface
be b'\x00\xfa\x00\xce'
le b'\xba\xbe\xfa\xce'
deadbeef
be b'\x00\xbe\x00\xef'
le b'\xde\xad\xbe\xef'
History
Date User Action Args
2015-09-11 19:18:43Brian Trottersetrecipients: + Brian Trotter, amaury.forgeotdarc, belopolsky, Alan.Ning, rgaddi
2015-09-11 19:18:43Brian Trottersetmessageid: <1441999123.77.0.693168566926.issue20629@psf.upfronthosting.co.za>
2015-09-11 19:18:43Brian Trotterlinkissue20629 messages
2015-09-11 19:18:43Brian Trottercreate