[issue8305] memoview[0] creates an invalid view if ndim != 1
STINNER Victor
report at bugs.python.org
Sat Apr 3 17:24:42 CEST 2010
New submission from STINNER Victor <victor.stinner at haypocalc.com>:
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.
----------
messages: 102270
nosy: haypo
severity: normal
status: open
title: memoview[0] creates an invalid view if ndim != 1
versions: Python 2.7, Python 3.1, Python 3.2
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8305>
_______________________________________
More information about the Python-bugs-list
mailing list