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
memoview[0] creates an invalid view if ndim != 1 #52552
Comments
memory_item() function creates a new memoryview object if ndim is different than 1. Example with numpy: from numpy import array
y=array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
y.shape = 3,4
view=memoryview(y)
view2 = view[0]
print type(view2) Result: <type 'memoryview'>. (Without the shape, ndim equals 1, and view2 is a standard str object.) The problem is that view attribute of the view2 (PyMemoryViewObject) is not initialized. Extract of memory_item(): /* Return a new memory-view object */
Py_buffer newview;
memset(&newview, 0, sizeof(newview));
/* XXX: This needs to be fixed so it actually returns a sub-view */
return PyMemoryView_FromBuffer(&newview); "This needs to be fixed" :-/ -- view2 is not initialized and so view2.tolist() does crash. |
Full example (using numpy) crashing Python: memoryview_crash.py |
According to bpo-2394, the implementation of the new buffer API is not complete. |
I'll leave this to our numpy experts. I don't even know how to unit test this without installing numpy. |
The crash is fixed in the features/pep-3118 repo: >>> from numpy import array
>>> y=array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
>>> y.shape = 3,4
>>> view=memoryview(y)
>>> view2 = view[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NotImplementedError: multi-dimensional sub-views are not implemented
[182251 refs] |
Fixed in bpo-10181. |
New changeset 3f9b3b6f7ff0 by Stefan Krah in branch 'default':
|
Since this issue targeted 2.7 and 3.2: In a brief discussion on python-dev it was decided that the 3.3 fixes http://mail.python.org/pipermail/python-dev/2012-February/116872.html |
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: