Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions Objects/memoryobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2334,8 +2334,7 @@ ptr_from_tuple(Py_buffer *view, PyObject *tup)
with the type specified by view->format. Otherwise, the item is a sub-view.
The function is used by memory_subscript(), memoryiter_next() and
memory_as_sequence.
Note: Iteration of multi-dimensional arrays is not yet implemented
(as of Python 3.10.0a0) */
Note: Iteration of multi-dimensional arrays is not yet implemented */
static PyObject *
memory_item(PyMemoryViewObject *self, Py_ssize_t index)
{
Expand Down Expand Up @@ -3216,10 +3215,7 @@ memoryiter_next(memoryiterobject *it)
if (seq == NULL) {
return NULL;
}
if (seq->view.ndim != 1) {
PyErr_SetString(PyExc_NotImplementedError,
"multi-dimensional sub-views are not implemented");
}

if (it->it_index < memory_length(seq)) {
return memory_item(seq, it->it_index++);
}
Expand All @@ -3244,8 +3240,19 @@ memory_iter(PyObject *seq)
}

it->it_index = 0;
Py_INCREF(seq);
it->it_seq = (PyMemoryViewObject *)seq;
Py_INCREF(seq);

int ndims = it->it_seq->view.ndim;
if (ndims == 0) {
PyErr_SetString(PyExc_TypeError, "invalid indexing of 0-dim memory");
return NULL;
}
if (ndims != 1) {
PyErr_SetString(PyExc_NotImplementedError,
"multi-dimensional sub-views are not implemented");
return NULL;
}
_PyObject_GC_TRACK(it);
return (PyObject *)it;
}
Expand Down Expand Up @@ -3289,4 +3296,4 @@ PyTypeObject PyMemoryView_Type = {
0, /* tp_init */
0, /* tp_alloc */
memoryview, /* tp_new */
};
};