FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

BUG: Fix segfault in nditer.multi_index when __getitem__ raises (#31314) by charris · Pull Request #31336 · numpy/numpy · GitHub

/ numpy Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 3 additions & 0 deletions numpy/_core/src/multiarray/nditer_pywrap.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,9 @@ npyiter_multi_index_set(
}
for (idim = 0; idim < ndim; ++idim) {
PyObject *v = PySequence_GetItem(value, idim);
if (v == NULL) {
return -1;
}
multi_index[idim] = PyLong_AsLong(v);
Py_DECREF(v);
if (error_converting(multi_index[idim])) {
Expand Down
16 changes: 16 additions & 0 deletions numpy/_core/tests/test_nditer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3531,3 +3531,19 @@ def test_signature_methods(method):

assert "self" in sig.parameters
assert sig.parameters["self"].kind is inspect.Parameter.POSITIONAL_ONLY


def test_nditer_multi_index_no_segfault():
class BadSequence:
def __len__(self):
return 2

def __getitem__(self, i):
if i == 1:
raise RuntimeError("intentional error")
return 0

arr = np.zeros((3, 4))
it = np.nditer(arr, flags=["multi_index"])
with pytest.raises(RuntimeError, match="intentional error"):
it.multi_index = BadSequence()
Loading

Back | FazBrowse Home | New Git URL