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.18:53:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1517943201.04.0.467229070634.issue32782@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-02-06 18:53:21Eric.Wiesersetrecipients: + Eric.Wieser
2018-02-06 18:53:21Eric.Wiesersetmessageid: <1517943201.04.0.467229070634.issue32782@psf.upfronthosting.co.za>
2018-02-06 18:53:21Eric.Wieserlinkissue32782 messages
2018-02-06 18:53:20Eric.Wiesercreate