[issue32780] ctypes: memoryview gives incorrect PEP3118 format strings for both packed and unpacked structs

Carl Banks report at bugs.python.org
Mon Jul 16 06:30:42 EDT 2018


Carl Banks <pythondev1 at aerojockey.com> added the comment:

I guess I'll weigh in since I was pinged.

I agree with the approach in the patch.  All the memoryview does is to use the format field verbatim from the underlying buffer, so if the format field is inaccurate then the only thing to do is to fix the object providing the buffer.

Since the format field is only there for interpretation of the data, and is not used to calculate of itemsizes or strides anywhere as far as I know, it's a fairly low-risk change.

However, the patch still leaves ctypes inaccurate for the case of unions.  It should be fairly simple to modify the code to use a format of "B<size>" for unions, so that it at least matches the itemsize, even if the type information is lost.

(As an aside, let me point out that I did not actually write or advocate for the PEP; for some reason my name was added to it even though I all I did was to provide feedback.)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32780>
_______________________________________


More information about the Python-bugs-list mailing list