Issue 8305: memoview[0] creates an invalid view if ndim != 1 (original) (raw)
Created on 2010-04-03 15:24 by vstinner, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (8)
Author: STINNER Victor (vstinner) *
Date: 2010-04-03 15:24
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.
Author: STINNER Victor (vstinner) *
Date: 2010-04-03 15:25
Full example (using numpy) crashing Python: memoryview_crash.py
Author: STINNER Victor (vstinner) *
Date: 2010-04-03 15:44
According to #2394, the implementation of the new buffer API is not complete.
Author: Antoine Pitrou (pitrou) *
Date: 2010-04-22 11:39
I'll leave this to our numpy experts. I don't even know how to unit test this without installing numpy.
Author: Stefan Krah (skrah) *
Date: 2011-08-10 12:39
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 "", line 1, in NotImplementedError: multi-dimensional sub-views are not implemented [182251 refs]
Author: Stefan Krah (skrah) *
Date: 2012-02-09 22:33
Fixed in #10181.
Author: Roundup Robot (python-dev)
Date: 2012-02-25 11:25
New changeset 3f9b3b6f7ff0 by Stefan Krah in branch 'default':
- Issue #10181: New memoryview implementation fixes multiple ownership http://hg.python.org/cpython/rev/3f9b3b6f7ff0
Author: Stefan Krah (skrah) *
Date: 2012-03-02 07:49
Since this issue targeted 2.7 and 3.2:
In a brief discussion on python-dev it was decided that the 3.3 fixes from #10181 won't be backported for a number of reasons, see:
http://mail.python.org/pipermail/python-dev/2012-February/116872.html
History
Date
User
Action
Args
2022-04-11 14:56:59
admin
set
github: 52552
2012-03-02 07:49:15
skrah
set
messages: +
2012-02-25 11:25:31
python-dev
set
nosy: + python-dev
messages: +
2012-02-09 22:33:54
skrah
set
status: open -> closed
superseder: Problems with Py_buffer management in memoryobject.c (and elsewhere?)
messages: +
dependencies: - Problems with Py_buffer management in memoryobject.c (and elsewhere?)
resolution: duplicate
stage: needs patch -> resolved
2011-08-10 12:39:21
skrah
set
nosy: + skrah
dependencies: + Problems with Py_buffer management in memoryobject.c (and elsewhere?)
messages: +
2011-05-09 15:29:40
pitrou
set
nosy: + mark.dickinson
versions: + Python 3.3
2010-04-22 11:39:08
pitrou
set
priority: normal
assignee: teoliphant
messages: +
stage: needs patch
2010-04-22 11:31:59
vstinner
set
nosy: + gvanrossum, georg.brandl, pitrou, scoder, benjamin.peterson
2010-04-03 15:44:56
vstinner
set
nosy: + teoliphant
messages: +
2010-04-03 15:26:35
vstinner
set
type: crash
components: + Interpreter Core
2010-04-03 15:25:56
vstinner
set
files: + memoryview_crash.py
messages: +
2010-04-03 15:24:41
vstinner
create