]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #9737: Fix a crash when trying to delete a slice or an item from
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 1 Sep 2010 21:14:16 +0000 (21:14 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 1 Sep 2010 21:14:16 +0000 (21:14 +0000)
a memoryview object.

Lib/test/test_memoryview.py
Misc/NEWS
Objects/memoryobject.c

index 6ca23fc1aec032101b4544984c20b0ad27a46fc5..8e56df993fa368f311f762e6e294ca376f0ac1ca 100644 (file)
@@ -111,6 +111,15 @@ class AbstractMemoryTests:
         m = None
         self.assertEquals(sys.getrefcount(b), oldrefcount)
 
+    def test_delitem(self):
+        for tp in self._types:
+            b = tp(self._source)
+            m = self._view(b)
+            with self.assertRaises(TypeError):
+                del m[1]
+            with self.assertRaises(TypeError):
+                del m[1:4]
+
     def test_tobytes(self):
         for tp in self._types:
             m = self._view(tp(self._source))
index 2a959a4478362aadded3f8ef112839caca2a3a60..92d858a92df3b6c87992fbff8ebe74e522362759 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 3.2 Alpha 2?
 Core and Builtins
 -----------------
 
+- Issue #9737: Fix a crash when trying to delete a slice or an item from
+  a memoryview object.
+
 - Issue #9549: sys.setdefaultencoding() and PyUnicode_SetDefaultEncoding()
   are now removed, since their effect was inexistent in 3.x (the default
   encoding is hardcoded to utf-8 and cannot be changed).
index 9a62dd84bd67c40e80957d89277b1066b24da327..3f203920c7cacbb3fcb1106bbb07575f254afb64 100644 (file)
@@ -631,6 +631,11 @@ memory_ass_sub(PyMemoryViewObject *self, PyObject *key, PyObject *value)
             "cannot modify read-only memory");
         return -1;
     }
+    if (value == NULL) {
+        PyErr_SetString(PyExc_TypeError,
+                        "cannot delete memory");
+        return -1;
+    }
     if (view->ndim != 1) {
         PyErr_SetNone(PyExc_NotImplementedError);
         return -1;