diff options
author | seberg <sebastian@sipsolutions.net> | 2013-10-21 02:36:37 -0700 |
---|---|---|
committer | seberg <sebastian@sipsolutions.net> | 2013-10-21 02:36:37 -0700 |
commit | 54d3559c325be26f8fee71e1c669cc502286dc77 (patch) | |
tree | fea97ec226799030d48a6be2ebf4b2a68fe7161b /numpy/core | |
parent | 0d3289fa1d1a4f54980b65ad3b3f169a2a1afa59 (diff) | |
parent | c71f36658459e87cc3c938308b62ce0e0b34a6f8 (diff) | |
download | numpy-54d3559c325be26f8fee71e1c669cc502286dc77.tar.gz |
Merge pull request #3952 from JStech/issue_2052
BUG: #2052 del scalar subscript causes segfault
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/multiarray/scalartypes.c.src | 6 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 4 |
2 files changed, 10 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src index 6f3637cc1..0bd367567 100644 --- a/numpy/core/src/multiarray/scalartypes.c.src +++ b/numpy/core/src/multiarray/scalartypes.c.src @@ -2185,6 +2185,12 @@ voidtype_ass_subscript(PyVoidScalarObject *self, PyObject *ind, PyObject *val) return -1; } + if (!val) { + PyErr_SetString(PyExc_ValueError, + "cannot delete scalar field"); + return -1; + } + #if defined(NPY_PY3K) if (PyUString_Check(ind)) { #else diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index cb02c3666..9f333a4a2 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -3732,6 +3732,10 @@ def test_flat_element_deletion(): except: raise AssertionError +def test_scalar_element_deletion(): + a = np.zeros(2, dtype=[('x', 'int'), ('y', 'int')]) + assert_raises(ValueError, a[0].__delitem__, 'x') + class TestMemEventHook(TestCase): def test_mem_seteventhook(self): # The actual tests are within the C code in |