Message311705
Discovered [here](https://github.com/numpy/numpy/issues/10528)
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
8
But that padding doesn't show up in the format string:
>>> mf.format
'T{<B:one:<I:two:}'
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
5
But the format is garbage:
>>> mf.format
'B' # sizeof(byte) == 5!? |
|
Date |
User |
Action |
Args |
2018-02-06 05:27:59 | Eric.Wieser | set | recipients:
+ Eric.Wieser |
2018-02-06 05:27:59 | Eric.Wieser | set | messageid: <1517894879.39.0.467229070634.issue32780@psf.upfronthosting.co.za> |
2018-02-06 05:27:59 | Eric.Wieser | link | issue32780 messages |
2018-02-06 05:27:59 | Eric.Wieser | create | |
|