[New-bugs-announce] [issue32782] ctypes: memoryview gives incorrect PEP3118 itemsize for array of length zero
Eric Wieser
report at bugs.python.org
Tue Feb 6 13:53:21 EST 2018
New submission from Eric Wieser <wieser.eric+pybug at gmail.com>:
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.
----------
components: ctypes
messages: 311740
nosy: Eric.Wieser
priority: normal
severity: normal
status: open
title: ctypes: memoryview gives incorrect PEP3118 itemsize for array of length zero
type: behavior
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32782>
_______________________________________
More information about the New-bugs-announce
mailing list