Message311740
Take the following simple structure:
class Foo(ctypes.Structure):
_fields_ = [('f', ctypes.uint32_t)]
And construct some arrays with it:
def get_array_view(N):
return memoryview((Foo * N)())
In most cases, this works as expected, returning the size of one item:
>>> get_array_view(10).itemsize
4
>>> get_array_view(1).itemsize
4
But when N=0, it returns the wrong result
>>> get_array_view(0).itemsize
0
Which contradicts its `.format`, which still describes a 4-byte struct
>>> get_array_view(0).format
'T{>I:one:}'
This causes a downstream problem in numpy:
>>> np.array(get_array_view(0))
RuntimeWarning: Item size computed from the PEP 3118 buffer format string does not match the actual item size. |
|
Date |
User |
Action |
Args |
2018-02-06 18:53:21 | Eric.Wieser | set | recipients:
+ Eric.Wieser |
2018-02-06 18:53:21 | Eric.Wieser | set | messageid: <1517943201.04.0.467229070634.issue32782@psf.upfronthosting.co.za> |
2018-02-06 18:53:21 | Eric.Wieser | link | issue32782 messages |
2018-02-06 18:53:20 | Eric.Wieser | create | |
|