[New-bugs-announce] [issue29753] Ctypes Packing Incorrectly - Linux

Charles Machalow report at bugs.python.org
Tue Mar 7 19:36:40 EST 2017


New submission from Charles Machalow:

There appears to be a bug related to sizing/packing of ctypes Structures on Linux. I'm not quite sure how, but this structure:

class MyStructure(Structure):
    _pack_      = 1
    _fields_    = [ 
                      ("P",       c_uint16),    # 2 Bytes
                      ("L",       c_uint16, 9),
                      ("Pro",     c_uint16, 1),
                      ("G",       c_uint16, 1),
                      ("IB",      c_uint16, 1),
                      ("IR",      c_uint16, 1),
                      ("R",       c_uint16, 3), # 4 Bytes
                      ("T",       c_uint32, 10),
                      ("C",       c_uint32, 20),
                      ("R2",      c_uint32, 2)  # 8 Bytes
                  ]

Gives back a sizeof of 8 on Windows and 10 on Linux. The inconsistency makes it difficult to have code work cross-platform.

Running the given test.py file will print out the size of the structure on your platform.

Tested with Python 2.7.6 and Python 3.4.3 (builtin to Ubuntu 14.04), Python 2.7.13, (built from source) both on Ubuntu 14.04. On Linux all Python builds were 32 bit.

On Windows I tried with 2.7.7 (both 32 and 64 bit).

I believe on both platforms it should return a sizeof 8.

----------
components: ctypes
files: test.py
messages: 289193
nosy: Charles Machalow, amaury.forgeotdarc, belopolsky, meador.inge
priority: normal
severity: normal
status: open
title: Ctypes Packing Incorrectly - Linux
type: behavior
versions: Python 2.7, Python 3.4
Added file: http://bugs.python.org/file46708/test.py

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


More information about the New-bugs-announce mailing list