-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
ctypes arrays have incorrect buffer information (PEP-3118) #54953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Ctypes arrays have invalid buffer interface information (on Python 3.1.2): >>> import ctypes
>>> x = (ctypes.c_double*2)()
>>> y = memoryview(x)
>>> y.shape
(2,)
>>> y.format
'(2)<d' This implies that the array contains 2 items, each consisting of 2 floats, which is incorrect -- the shape information is duplicated. A suggested fix is attached. |
Thanks for the patch. I agree with the interpretation of the format string. The PEP isn't so clear on that, would you agree? I'm not done reviewing the patch, just a couple of nitpicks:
|
The array notation is useful for arrays inside structs, such as "T{(4)i(2,3)f}". |
@skrah: What is the status of this issue? |
Basically someone has to review the patch and commit it. I'm not really |
The correct format string for Py_ssize_t with sprintf is |
Here are updated patches for 2.7 and HEAD. I've updated the patches for both python 2 and python 3 and addressed some of the issues here:
I really hope this patch makes it to 2.7.7 and python 3 versions, as currently the situation is broken and code that once worked with older numpy versions does not work today (and we have legacy code that stopped working). |
Here is the patch for HEAD |
The shape for the StructWithArrays test should be () in 3.x; it's None in 2.x. |
Updated patch for default for empty shape, thanks eryksun |
New changeset 44dac2e7fcb8 by Benjamin Peterson in branch '2.7': New changeset 22938bf57161 by Benjamin Peterson in branch '3.4': New changeset ea9193340d6c by Benjamin Peterson in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: