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 Eric.Wieser
Recipients Eric.Wieser
Date 2018-02-06.05:27:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Discovered [here](

Consider the following structure, and a memoryview created from it:

    class foo(ctypes.Structure):
        _fields_ = [('one', ctypes.c_uint8),
                    ('two', ctypes.c_uint32)]
    f = foo()
    mf = memoryview(f)

We'd expect this to insert padding, and it does:

>>> mf.itemsize

But that padding doesn't show up in the format string:

>>> mf.format

That format string describes the _packed_ version of the struct, with the `two` field starting at offset 1, based on the `struct` documentation on how `<` should be interpreted:

> No padding is added when using non-native size and alignment, e.g. with ‘<’, ‘>’

But ctypes doesn't even get it right for packed structs:

    class foop(ctypes.Structure):
        _fields_ = [('one', ctypes.c_uint8),
                    ('two', ctypes.c_uint32)]
        _pack_ = 1
    f = foo()
    mf = memoryview(f)

The size is what we'd expect:

>>> mf.itemsize

But the format is garbage:

>>> mf.format
'B'  # sizeof(byte) == 5!?
Date User Action Args
2018-02-06 05:27:59Eric.Wiesersetrecipients: + Eric.Wieser
2018-02-06 05:27:59Eric.Wiesersetmessageid: <>
2018-02-06 05:27:59Eric.Wieserlinkissue32780 messages
2018-02-06 05:27:59Eric.Wiesercreate